R Under development (unstable) (2024-11-13 r87330 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > library("tram") Loading required package: mlt Loading required package: basefun Loading required package: variables Loading required package: mvtnorm > require("lme4") Loading required package: lme4 Loading required package: Matrix > options(digits = 2) > > ## ----mtram-sleep_lmer, cache = FALSE------------------------------------------ > sleep_lmer <- lmer(Reaction ~ Days + (Days | Subject), + data = sleepstudy, REML = FALSE) > > > ## ----mtram-sleep_mtram, cache = FALSE----------------------------------------- > sleep_LM <- Lm(Reaction ~ Days, data = sleepstudy) > sleep_LMmer <- mtram(sleep_LM, ~ (Days | Subject), data = sleepstudy) > > > ## ----mtram-sleep_cmp---------------------------------------------------------- > logLik(sleep_lmer) 'log Lik.' -876 (df=6) > logLik(sleep_LMmer) 'log Lik.' -876 (df=6) > > > ## ----mtram-sleep_sd----------------------------------------------------------- > (sdinv <- 1 / summary(sleep_lmer)$sigma) [1] 0.039 > coef(sleep_LMmer)["Reaction"] Reaction 0.039 > > > ## ----mtram-sleep_beta--------------------------------------------------------- > fixef(sleep_lmer) * c(-1, 1) * sdinv (Intercept) Days -9.82 0.41 > coef(sleep_LMmer)[c("(Intercept)", "Days")] (Intercept) Days -9.82 0.41 > > > ## ----mtram-sleep_varparm------------------------------------------------------ > sleep_lmer@theta [1] 0.929 0.018 0.223 > coef(sleep_LMmer)[-(1:3)] gamma1 gamma2 gamma3 0.929 0.018 0.223 > > > ## ----mtram-sleep_varcorr------------------------------------------------------ > sleep_LMmer$G * (1 / sdinv)^2 2 x 2 sparse Matrix of class "dsCMatrix" [1,] 565 11 [2,] 11 33 > cov2cor(sleep_LMmer$G * (1 / sdinv)^2) 2 x 2 sparse Matrix of class "dsCMatrix" [1,] 1.000 0.082 [2,] 0.082 1.000 > unclass(VarCorr(sleep_lmer))$Subject (Intercept) Days (Intercept) 565 11 Days 11 33 attr(,"stddev") (Intercept) Days 23.8 5.7 attr(,"correlation") (Intercept) Days (Intercept) 1.000 0.081 Days 0.081 1.000 > > > ## ----mtram-sleep-Surv--------------------------------------------------------- > library("survival") > sleepstudy$Reaction_I <- with(sleepstudy, Surv(Reaction - 20, Reaction + 20, + type = "interval2")) > sleepstudy$Reaction_I[1:5] [1] [230, 270] [239, 279] [231, 271] [301, 341] [337, 377] > > > ## ----mtram-sleep-interval, cache = FALSE-------------------------------------- > sleep_LM_I <- Lm(Reaction_I ~ Days, data = sleepstudy) > sleep_LMmer_I <- mtram(sleep_LM_I, ~ (Days | Subject), data = sleepstudy) > > > ## ----mtram-sleep-interval-results--------------------------------------------- > logLik(sleep_LMmer_I) 'log Lik.' -213 (df=6) > > proc.time() user system elapsed 13.2 1.4 14.6