fitted.lmm | R Documentation |
Predicted Mean Value For Linear Mixed Model
## S3 method for class 'lmm' fitted( object, newdata = NULL, format = "long", keep.newdata = FALSE, impute = FALSE, se.impute = FALSE, ... )
object |
a |
newdata |
[data.frame] the covariate values for each cluster. |
format |
[character] Should the predicted mean be output relative as a vector ( |
keep.newdata |
[logical] Should the argument |
impute |
[logical] Should the missing data in the outcome be imputed based on covariates and other outcome values from the same cluster. |
se.impute |
[character] If |
... |
Not used. For compatibility with the generic method. |
When format="wide"
, a data.frame with as many rows as clusters.
When format="long"
or keep.newdata==TRUE
, a data.frame with as many rows as observations.
Otherwise:
if impute=FALSE
a vector of length the number of row of newdata containing the fitted values (i.e. based on the covariates only).
if impute=TRUE
a vector of length the number of missing values in the outcome of newdata containing the cluster-specific conditional means
(i.e. based on the covariates and outcome measurements from the same cluster).
When keep.newdata==TRUE
, a dataframe with an additional column containing the fitted values (i.e. based on the covariates only).
If impute=TRUE
, the missing value in the outcome column are replaced by the cluster-specific conditional means
(i.e. based on the covariates and outcome measurements from the same cluster).
#### simulate data in the long format #### set.seed(10) dL <- sampleRem(100, n.times = 3, format = "long") #### fit Linear Mixed Model #### eCS.lmm <- lmm(Y ~ X1 + X2 + X5, repetition = ~visit|id, structure = "CS", data = dL, df = FALSE) ## prediction fitted(eCS.lmm) fitted(eCS.lmm, newdata = data.frame(X1 = 1, X2 = 2, X5 = 3)) fitted(eCS.lmm, newdata = data.frame(X1 = 1, X2 = 2, X5 = 3), keep.newdata = TRUE) #### fit Linear Mixed Model with missing data #### dL2 <- dL dL2[3,"Y"] <- NA eCS2.lmm <- lmm(Y ~ X1 + X2 + X5, repetition = ~visit|id, structure = "CS", data = dL2, df = FALSE) ## most likely value to impute fitted(eCS2.lmm, impute = TRUE) head(fitted(eCS2.lmm, impute = TRUE, keep.newdata = TRUE)) ## multiple imputation dL2.imp1 <- data.frame(imp = "1", fitted(eCS2.lmm, impute = TRUE, se.impute = "total", keep.newdata = TRUE)) dL2.imp2 <- data.frame(imp = "2", fitted(eCS2.lmm, impute = TRUE, se.impute = "total", keep.newdata = TRUE)) head(dL2.imp1) head(dL2.imp2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.