true_classification_prob function

Compute Probability of Each True Mediator, for Every Subject

Compute Probability of Each True Mediator, for Every Subject

Compute the probability of the latent true mediator M{1,2}M \in \{1, 2 \} as P(Mi=jXi)=exp(Xiβ)1+exp(Xiβ)P(M_i = j | X_i) = \frac{\exp(X_i \beta)}{1 + \exp(X_i \beta)}

for each of the i=1,,i = 1, \dots, n subjects.

true_classification_prob(beta_matrix, x_matrix)

Arguments

  • beta_matrix: A numeric column matrix of estimated regression parameters for the true mediator mechanism, M (true mediator) ~ X (predictor matrix of interest), obtained from COMMA_EM, COMMA_PVW, or COMMA_OLS.
  • x_matrix: A numeric matrix of covariates in the true mediator mechanism. x_matrix should not contain an intercept.

Returns

true_classification_prob returns a dataframe containing three columns. The first column, Subject, represents the subject ID, from 11 to n, where n is the sample size, or equivalently, the number of rows in x_matrix. The second column, M, represents a true, latent mediator category M{1,2}M \in \{1, 2 \}. The last column, Probability, is the value of the equation P(Mi=jXi)=exp(Xiβ)1+exp(Xiβ)P(M_i = j | X_i) = \frac{\exp(X_i \beta)}{1 + \exp(X_i \beta)} computed for each subject and true, latent mediator category.

Examples

set.seed(123) sample_size <- 1000 cov1 <- rnorm(sample_size) cov2 <- rnorm(sample_size, 1, 2) x_matrix <- matrix(c(cov1, cov2), nrow = sample_size, byrow = FALSE) estimated_betas <- matrix(c(1, -1, .5), ncol = 1) P_M <- true_classification_prob(estimated_betas, x_matrix) head(P_M)
  • Maintainer: Kimberly Webb
  • License: MIT + file LICENSE
  • Last published: 2024-12-13

Useful links