@@ -24,98 +24,99 @@ survival::Surv
2424# add some S3-convenience functions for q&d lmercens
2525
2626# ' @export
27- print.lmercens <- function (obj ){
27+ print.lmercens <- function (x , ... ){
2828 cat(" Linear Mixed Model with Censored Observations\n " )
2929
30- cat(" \n Call:\n " , paste(deparse(obj $ call ), sep = " \n " , collapse = " \n " ),
30+ cat(" \n Call:\n " , paste(deparse(x $ call ), sep = " \n " , collapse = " \n " ),
3131 " \n\n " , sep = " " )
32- cat(" \n Coefficients:\n Fixed coefs: " , fixef.lmercens(obj ))
33- cat(" \n Random effect coefs: log(S_betw) = " , log(sigma(obj , which = " between" )),
34- " \t log(S_within) = " , log(sigma(obj , which = " residual" )), " \n " )
32+ cat(" \n Coefficients:\n Fixed coefs: " , fixef.lmercens(x ))
33+ cat(" \n Random effect coefs: log(S_betw) = " , log(sigma(x , which = " between" )),
34+ " \t log(S_within) = " , log(sigma(x , which = " residual" )), " \n " )
3535}
3636
3737# ' Extract variance estimates on standard-deviation scale
3838# ' @param which which type of variance estimate
3939# ' @export
40- sigma.lmercens <- function (obj , which = c(" residual" , " between" ), ... ){
40+ sigma.lmercens <- function (object , which = c(" residual" , " between" ), ... ){
4141 which <- match.arg(which )
4242
4343 switch (which ,
44- between = exp(obj $ par [[1L ]]),
44+ between = exp(object $ par [[1L ]]),
4545 residual = ,
46- exp(obj $ par [[2L ]])
46+ exp(object $ par [[2L ]])
4747 )
4848}
4949
5050
51+ # ' Fixed effect coefficient estimates.
5152# ' @export
52- fixef.lmercens <- function (obj ){
53- setNames(obj $ fixef , nm = colnames(obj $ ingredients $ X ))
53+ fixef.lmercens <- function (object , ... ){
54+ stats :: setNames(object $ fixef , nm = colnames(object $ ingredients $ X ))
5455}
5556
5657# ' Random effect predictions for the random intercept.
5758# ' @export
58- ranef.lmercens <- function (obj ){
59- stopifnot( inherits(obj , what = " lmercens" ) )
59+ ranef.lmercens <- function (object , ... ){
60+ stopifnot( inherits(object , what = " lmercens" ) )
6061
6162 # use only observed cases
62- respMatrix <- as.matrix(obj $ ingredients $ fr [[1L ]])
63+ respMatrix <- as.matrix(object $ ingredients $ fr [[1L ]])
6364 stopifnot( " status" %in% colnames(respMatrix ) )
6465 obsInd <- respMatrix [," status" , drop = TRUE ] == 1L # # eventually could use also interval-censored (=> take mean of interval)
65- fixef_resids <- respMatrix [obsInd , 1L , drop = FALSE ] - obj $ ingredients $ X [obsInd ,, drop = FALSE ] %*% fixef( obj )
66+ fixef_resids <- respMatrix [obsInd , 1L , drop = FALSE ] - object $ ingredients $ X [obsInd ,, drop = FALSE ] %*% fixef.lmercens( object )
6667
6768 # cf. Demidenko, section 3.7
68- Zt <- obj $ ingredients $ reTrms $ Zt
69- D <- diag(exp(2 * (obj $ par [[1L ]] - obj $ par [[2L ]])), nrow = NROW(Zt ))
69+ Zt <- object $ ingredients $ reTrms $ Zt
70+ D <- diag(exp(2 * (object $ par [[1L ]] - object $ par [[2L ]])), nrow = NROW(Zt ))
7071
7172 # with random intercept only, it is enough to give out a vector (not a named list)
7273 setNames(as.numeric(D %*% Matrix :: solve(a = diag(1 , nrow = NROW(Zt )) + Matrix :: tcrossprod(Zt ) %*% D ,
7374 b = Zt [, obsInd ] %*% (fixef_resids ))),
74- nm = levels(obj $ ingredients $ reTrms $ flist [[1 ]]))
75+ nm = levels(object $ ingredients $ reTrms $ flist [[1 ]]))
7576}
7677
7778# ' Predict method for `lmercens` objects.
7879# '
79- # ' @param obj `lmercens` model object
80+ # ' @param object `lmercens` model object
8081# ' @param newdata dataframe with covariate values for prediction. Default is `NULL` which is to fall back to the training data.
8182# ' @param re.form right-side formula for random effects to condition on in case of prediction on training data. If `NULL`, include all random effects; if `~0` or `NA`, include no random effects.
8283# ' @export
83- predict.lmercens <- function (obj , newdata = NULL , re.form = NULL ){
84- stopifnot( inherits(obj , what = " lmercens" ) )
84+ predict.lmercens <- function (object , newdata = NULL , re.form = NULL , ... ){
85+ stopifnot( inherits(object , what = " lmercens" ) )
8586
8687 ret <- NULL
8788
8889 if ( is.null(newdata ) ){ # use training data itself for predictions
8990
90- ret <- obj $ ingredients $ X %*% fixef( obj )
91+ ret <- object $ ingredients $ X %*% fixef.lmercens( object )
9192
9293 if ( is.null(re.form ) || re.form == ~ 1 ){ # #!isTRUE(is.na(re.form)) && !re.form == ~0 ){
9394 # expect simple random effects model (only a single random intercept)
94- stopifnot( length(obj $ ingredients $ reTrms $ cnms ) == 1L && obj $ ingredients $ reTrms $ cnms [[1L ]] == ' (Intercept)' )
95+ stopifnot( length(object $ ingredients $ reTrms $ cnms ) == 1L && object $ ingredients $ reTrms $ cnms [[1L ]] == ' (Intercept)' )
9596
96- ret <- ret + Matrix :: crossprod(obj $ ingredients $ reTrms $ Zt , y = ranef(obj ))
97+ ret <- ret + Matrix :: crossprod(object $ ingredients $ reTrms $ Zt , y = ranef(object ))
9798 }
9899
99100 } else { # new data used without random effect BLUPs
100- X <- model.matrix(lme4 ::: getFixedFormula(obj $ call $ formula [- 2 ]), data = newdata [,- 1 ])
101- ret <- X %*% fixef( obj )
101+ X <- model.matrix(lme4 ::: getFixedFormula(object $ call $ formula [- 2 ]), data = newdata [,- 1 ])
102+ ret <- X %*% fixef.lmercens( object )
102103 }
103104
104105 as.vector(ret )
105106}
106107
107108
108109# ' @export
109- fitted.lmercens <- function (obj ){
110- predict.lmercens(obj )
110+ fitted.lmercens <- function (object , ... ){
111+ predict.lmercens(object , ... )
111112}
112113
113114# ' @export
114- residuals.lmercens <- function (obj ){
115- stopifnot( inherits(obj , what = " lmercens" ) )
115+ residuals.lmercens <- function (object , ... ){
116+ stopifnot( inherits(object , what = " lmercens" ) )
116117
117- y_pred <- predict(obj )
118- y_obs <- as.matrix(obj $ ingredients $ fr [[1L ]])
118+ y_pred <- predict(object )
119+ y_obs <- as.matrix(object $ ingredients $ fr [[1L ]])
119120 y_obs_status <- y_obs [, " status" ]
120121
121122 # NA as default (for all censored outcomes)
@@ -127,14 +128,14 @@ residuals.lmercens <- function(obj){
127128}
128129
129130# ' @export
130- summary.lmercens <- function (obj ){
131- if (! inherits(obj , " lmercens" )) warning(" calling summary.lmercens(<fake-lmercens-object>) ..." )
132- ans <- obj [c(" call" , " ingredients" , " fval" )]
133- ans $ sigmas <- c(between = as.numeric(sigma(obj , which = " between" )),
134- residual = as.numeric(sigma(obj , which = " residual" )))
135-
136- est <- fixef(obj )
137- stdError <- sqrt(diag(vcov(obj )))
131+ summary.lmercens <- function (object , ... ){
132+ if (! inherits(object , " lmercens" )) warning(" calling summary.lmercens(<fake-lmercens-object>) ..." )
133+ ans <- object [c(" call" , " ingredients" , " fval" )]
134+ ans $ sigmas <- c(between = as.numeric(sigma(object , which = " between" )),
135+ residual = as.numeric(sigma(object , which = " residual" )))
136+
137+ est <- fixef(object )
138+ stdError <- sqrt(diag(vcov(object )))
138139 tval <- est / stdError
139140 ans $ coefs <- cbind(Estimate = est , `Std. Error` = stdError ,
140141 `z value` = tval ,
@@ -146,46 +147,46 @@ summary.lmercens <- function(obj){
146147}
147148
148149# ' @export
149- print.summary.lmercens <- function (obj , ... ) {
150+ print.summary.lmercens <- function (x , ... ) {
150151 cat(" Linear Mixed Model with Censored Observations\n " )
151152
152- cat(" \n Call:\n " , paste(deparse(obj $ call ), sep = " \n " , collapse = " \n " ),
153+ cat(" \n Call:\n " , paste(deparse(x $ call ), sep = " \n " , collapse = " \n " ),
153154 " \n\n " , sep = " " )
154155 cat(" \n Coefficients:\n Fixed coefs:\n " )
155- coefs <- obj $ coefs
156+ coefs <- x $ coefs
156157 stats :: printCoefmat(coefs , ... )
157158 cat(" \n Random effects:\n " )
158- cat(" S_betw = " , obj $ sigmas [" between" ], " \t S_within = " , obj $ sigmas [" residual" ], " \n " )
159- cat(" Log-likelihood: " , round(- obj $ fval , 2 ), " \n " )
159+ cat(" S_betw = " , x $ sigmas [" between" ], " \t S_within = " , x $ sigmas [" residual" ], " \n " )
160+ cat(" Log-likelihood: " , round(- x $ fval , 2 ), " \n " )
160161}
161162
162163# ' Variance-covariance matrix for fixed effect coefficients.
163164# ' It uses the observed Fisher information matrix at the ML parameter estimate.
164165# ' Therefore, it is only useful asymptotically.
165- # ' @param obj a fitted `lmercens`-object
166+ # ' @param object a fitted `lmercens`-object
166167# ' @return estimated variance-covariance matrix for fixed effect coefficients
167168# ' @export
168- vcov.lmercens <- function (obj , ... ){
169- stopifnot( inherits(obj , what = " lmercens" ) )
169+ vcov.lmercens <- function (object , ... ){
170+ stopifnot( inherits(object , what = " lmercens" ) )
170171
171172 retMat <- NULL
172173
173- if (! is.null(obj $ hess ) && is.matrix(obj $ hess ) && isSymmetric(obj $ hess )){
174- retMat <- solve(obj $ hess )
175- dimnames(retMat ) <- list (colnames(obj $ ingredients $ X ), colnames(obj $ ingredients $ X ))
174+ if (! is.null(object $ hess ) && is.matrix(object $ hess ) && isSymmetric(object $ hess )){
175+ retMat <- solve(object $ hess )
176+ dimnames(retMat ) <- list (colnames(object $ ingredients $ X ), colnames(object $ ingredients $ X ))
176177 }
177178
178179 retMat
179180}
180181
181182
182183# ' @export
183- confint.lmercens <- function (obj , parm , level = 0.95 , ... ){
184- stopifnot( inherits(obj , " lmercens" ), is.numeric(level ), level > 0L , level < 1L )
184+ confint.lmercens <- function (object , parm , level = 0.95 , ... ){
185+ stopifnot( inherits(object , " lmercens" ), is.numeric(level ), level > 0L , level < 1L )
185186
186- cf <- fixef(obj )
187+ cf <- fixef(object )
187188 pnames <- names(cf )
188- ses <- sqrt(diag(vcov(obj )))
189+ ses <- sqrt(diag(vcov(object )))
189190
190191 if (missing(parm )) parm <- pnames else if (is.numeric(parm )) parm <- pnames [parm ]
191192
0 commit comments