Debian Codegraph @

R/nobs.R

raw
1 # `stats::nobs` is a standard function to retrieve the number of
2 # observations used to fit a model. Unfortunately, Some packages do
3 # not define a `stats::nobs.MODEL` method. This file fills-in those missing
4 # methods. Ideally, we should offload these methods by submitting them for
5 # adoption in the upstream packages.
6
7 # These packages still need to be checked:
8
9 # caret
10 # joineRML
11 # ergm
12 # nlme
13 # rstanarm
14 # lavaan: conflict between stats::nobs and lavaan::nobs
15 # mass-ridgelm
16 # survival-*
17 # quantreg-rq
18 # quantreg-rqs
19
20 # nnet-multinom
21 #' @export
22 nobs.multinom <- function(object, ...) {
23 nrow(object$residuals)
24 }
25
26 # mass-fitdistr
27 #' @export
28 nobs.fitdistr <- function(object, ...) {
29 object$n
30 }
31
32 # biglm
33 #' @export
34 nobs.biglm <- function(object, ...) {
35 object$n
36 }
37
38 # glmnet-cv-glmnet
39 #' @export
40 nobs.cv.glmnet <- function(object, ...) {
41 stats::nobs(object$glmnet.fit)
42 }
43
44 # gmm
45 #' @export
46 nobs.gmm <- function(object, ...) {
47 object$n
48 }
49
50 # lfe - felm
51 #' @export
52 nobs.felm <- function(object, ...) {
53 object$N
54 }
55
56 # lmodel2
57 #' @export
58 nobs.lmodel2 <- function(object, ...) {
59 object$n
60 }
61
62 # mclust
63 #' @export
64 nobs.Mclust <- function(object, ...) {
65 object$n
66 }
67
68 # muhaz
69 #' @export
70 nobs.muhaz <- function(object, ...) {
71 length(object$pin$times)
72 }
73
74 # polca
75 #' @export
76 nobs.poLCA <- function(object, ...) {
77 object$N
78 }
79
80 # robust-glmrob
81 #' @export
82 nobs.lmRob <- function(object, ...) {
83 length(object$residuals)
84 }
85 #' @export
86 nobs.glmRob <- function(object, ...) {
87 length(object$residuals)
88 }
89
90 # stats-loess
91 #' @export
92 nobs.loess <- function(object, ...) {
93 object$n
94 }
95
96 # stats-prcomp
97 #' @export
98 nobs.prcomp <- function(object, ...) {
99 NROW(object$x)
100 }
101
102 # stats-smooth.spline
103 #' @export
104 nobs.smooth.spline <- function(object, ...) {
105 length(object$x)
106 }
107
108 # bbmle
109 #' @export
110 nobs.bbmle <- function(object, ...) {
111 length(object@data[[1]])
112 }
113
114 # survival-aareg
115 #' @export
116 nobs.aareg <- function(object, ...) {
117 object$n[1] # obs / event times / event times in computation
118 }
119
120 # survival-survfit
121 #' @export
122 nobs.survfit <- function(object, ...) {
123 object$n
124 }
125
126 # survival-survfit.cox
127 #' @export
128 nobs.survfit.cox <- function(object, ...) {
129 object$n
130 }
131
132 # survival-pyears
133 #' @export
134 nobs.pyears <- function(object, ...) {
135 object$observations
136 }
137
138 # survival-survdiff
139 #' @export
140 nobs.survdiff <- function(object, ...) {
141 s <- summary(object)
142 s$nobs
143 }
144
145 # tseries
146 #' @export
147 nobs.garch <- function(object, ...) {
148 object$n.used
149 }