/
standardMethods.R
259 lines (217 loc) · 5.83 KB
/
standardMethods.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#' Standard methods for estimated models
#'
#' coef and vcov for hlme, lcmm, mutlcmm, Jointlcmm, mpjlcmm, externSurv, and externX
#' models, fixef, ranef, fitted and residuals methods for estimated hlme,
#' lcmm, mutlcmm and Jointlcmm models.
#'
#'
#'
#'
#'
#'
#' @aliases coef.hlme coef.lcmm coef.Jointlcmm coef.multlcmm coef.mpjlcmm
#' coef.externSurv coef.externX vcov.hlme vcov.lcmm vcov.Jointlcmm vcov.multlcmm
#' vcov.mpjlcmm vcov.externSurv vcov.externX fixef.hlme fixef.lcmm
#' fixef.Jointlcmm fixef.multlcmm ranef.hlme ranef.lcmm ranef.Jointlcmm
#' ranef.multlcmm fitted.hlme fitted.lcmm fitted.Jointlcmm fitted.multlcmm
#' residuals.hlme residuals.lcmm residuals.Jointlcmm residuals.multlcmm
#' @param object an object of class \code{hlme}, \code{lcmm}, \code{multlcmm}
#' or \code{Jointlcmm}
#' @param ... other arguments. There are ignored in these functions.
#' @return For \code{coef}, the vector of the estimates.
#'
#' For \code{vcov}, the variance-covariance matrix of the estimates.
#'
#' For \code{fixef} : - for \code{hlme}, \code{lcmm} and \code{multlcmm}
#' objects, a list containing the fixed effects estimates in the
#' class-membership model and in the longitudinal model. - for
#' \code{Jointlcmm} objects, a list containing the fixed effects estimates in
#' the class-membership model, the survival model and in the longitudinal
#' model.
#'
#' For \code{ranef}, a matrix (nrow=number of subjects, ncol=number of
#' covariates with random effect) containing the individual random effects.
#'
#' For \code{fitted}, a vector containing the subject-specific predictions
#' extracted from \code{object}.
#'
#' For \code{residuals}, a vector containing the subject-specific residuals
#' extracted from \code{object}.
#' @author Cecile Proust-Lima, Viviane Philipps
#'
#' @name StandardMethods
#'
#'
# coef = estimates
#' @export
coef.hlme <- function(object,...)
{
estimates.hlme(object)
}
#' @export
coef.lcmm <- function(object,...)
{
estimates.lcmm(object)
}
#' @export
coef.multlcmm <- function(object,...)
{
estimates.multlcmm(object)
}
#' @export
coef.Jointlcmm <- function(object,...)
{
estimates.Jointlcmm(object)
}
#' @export
coef.mpjlcmm <- function(object,...)
{
estimates.mpjlcmm(object)
}
#' @export
coef.externX <- function(object,...)
{
estimates.externX(object)
}
#' @export
coef.externSurv <- function(object,...)
{
estimates.externSurv(object)
}
# variance-covariance matrix of the estimates
#' @export
vcov.hlme <- function(object,...)
{
VarCov(object)
}
#' @export
vcov.lcmm <- function(object,...)
{
VarCov(object)
}
#' @export
vcov.multlcmm <- function(object,...)
{
VarCov(object)
}
#' @export
vcov.Jointlcmm <- function(object,...)
{
VarCov(object)
}
#' @export
vcov.mpjlcmm <- function(object,...)
{
VarCov(object)
}
#' @export
vcov.externX <- function(object,...)
{
VarCov(object)
}
#' @export
vcov.externSurv <- function(object,...)
{
VarCov(object)
}
# fixed effects
#' @export
fixef.hlme <- function(object,...)
{
res <- list(NA,NA)
if(object$ng>1) res[[1]] <- as.vector(object$best[1:object$N[1]])
if(object$N[2]>1) res[[2]] <- as.vector(object$best[object$N[1]+1:object$N[2]])
return(res)
}
#' @export
fixef.lcmm <- function(object,...)
{
res <- list(NA,NA)
if(object$ng>1) res[[1]] <- as.vector(object$best[1:object$N[1]])
if(object$N[2]>1) res[[2]] <- as.vector(object$best[object$N[1]+1:object$N[2]])
return(res)
}
#' @export
fixef.multlcmm <- function(object,...)
{
res <- list(NA,NA)
if(object$ng>1) res[[1]] <- as.vector(object$best[1:object$N[1]])
if(object$N[3]>1) res[[2]] <- as.vector(object$best[(object$N[1]+1):object$N[3]])
return(res)
}
#' @export
fixef.Jointlcmm <- function(object,...)
{
res <- list(NA,NA,NA)
if(object$ng>1) res[[1]] <- as.vector(object$best[1:object$N[1]])
if(object$N[3]>1) res[[2]] <- as.vector(object$best[object$N[1]+object$N[2]+1:object$N[3]])
if(object$N[4]>1) res[[3]] <- as.vector(object$best[object$N[1]+object$N[2]+object$N[3]+1:object$N[4]])
return(res)
}
# random effects
#' @export
ranef.hlme <- function(object,...)
{
if(object$N[3]>0) return(object$predRE[,-1,drop=FALSE])
else return(NA)
}
#' @export
ranef.lcmm <- function(object,...)
{
if(object$N[3]>0) return(object$predRE[,-1,drop=FALSE])
else return(NA)
}
#' @export
ranef.multlcmm <- function(object,...)
{
if(object$N[4]>0) return(object$predRE[,-1,drop=FALSE])
else return(NA)
}
#' @export
ranef.Jointlcmm <- function(object,...)
{
if(object$N[5]>0) return(object$predRE[,-1,drop=FALSE])
else return(NA)
}
# subject-specific predictions
#' @export
fitted.hlme <- function(object,...)
{
return(object$pred[,"pred_ss"])
}
#' @export
fitted.lcmm <- function(object,...)
{
return(object$pred[,"pred_ss"])
}
#' @export
fitted.multlcmm <- function(object,...)
{
return(object$pred[,"pred_ss"])
}
#' @export
fitted.Jointlcmm <- function(object,...)
{
return(object$pred[,"pred_ss"])
}
# subject-specific residuals
#' @export
residuals.hlme <- function(object,...)
{
return(object$pred[,"obs"]-object$pred[,"pred_ss"])
}
#' @export
residuals.lcmm <- function(object,...)
{
return(object$pred[,"obs"]-object$pred[,"pred_ss"])
}
#' @export
residuals.multlcmm <- function(object,...)
{
return(object$pred[,"obs"]-object$pred[,"pred_ss"])
}
#' @export
residuals.Jointlcmm <- function(object,...)
{
return(object$pred[,"obs"]-object$pred[,"pred_ss"])
}