fitted.lmm | R Documentation |
Predicted Mean Value For Linear Mixed Model
## S3 method for class 'lmm'
fitted(
object,
newdata = NULL,
impute = FALSE,
se.impute = FALSE,
keep.newdata = FALSE,
format = "long",
simplify = TRUE,
seed = NULL,
...
)
object |
a |
newdata |
[data.frame] the covariate values for each cluster. |
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 |
keep.newdata |
[logical] Should the dataset relative to which the predictions are evaluated be output along side the predicted values? Only possible in the long format. |
format |
[character] Should the prediction be output
in a matrix format with clusters in row and timepoints in columns ( |
simplify |
[logical] Simplify the data format (vector instead of data.frame) and column names (no mention of the time variable) when possible. |
seed |
[integer, >0] Random number generator (RNG) state used when starting imputation.
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.