MCEM | R Documentation |
Implements the Monte Carlo EM algorithm for handling missing response data in linear regression models.
MCEM(data, d = 5, tol = 0.01, nb = 50)
data |
A data frame with the response variable in the first column and predictors in the remaining columns. |
d |
Initial convergence threshold. Defaults to 5. |
tol |
Termination tolerance. Defaults to 0.01. |
nb |
Maximum number of iterations. Defaults to 50. |
This function implements the Monte Carlo Expectation-Maximization (MCEM) algorithm to handle missing response variables in linear regression models. The algorithm iteratively imputes missing responses and updates regression coefficients until convergence.
A list containing the following components:
Yhat |
Imputed response vector with missing values filled in. |
betahat |
Final regression coefficients. |
iterations |
Number of iterations performed. |
# Create dataset with 20% missing responses
set.seed(123)
data <- data.frame(
Y = c(rnorm(80), rep(NA, 20)),
X1 = rnorm(100),
X2 = runif(100)
)
result <- MCEM(data, d = 5, tol = 0.001, nb = 100)
print(result$Yhat) # Imputed response vector
print(result$betahat) # Final regression coefficients
print(result$iterations) # Number of iterations performed
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.