Skip to content

Commit

Permalink
register nobs() methods (closes #1219)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Sep 26, 2024
1 parent 0c6c941 commit 8a1fdc4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,31 @@ S3method(glance,svyglm)
S3method(glance,svyolr)
S3method(glance,tbl_df)
S3method(glance,varest)
S3method(nobs,Mclust)
S3method(nobs,aareg)
S3method(nobs,bbmle)
S3method(nobs,biglm)
S3method(nobs,coxph)
S3method(nobs,cv.glmnet)
S3method(nobs,felm)
S3method(nobs,fitdistr)
S3method(nobs,garch)
S3method(nobs,glmRob)
S3method(nobs,gmm)
S3method(nobs,lmRob)
S3method(nobs,lmodel2)
S3method(nobs,loess)
S3method(nobs,muhaz)
S3method(nobs,multinom)
S3method(nobs,orcutt)
S3method(nobs,poLCA)
S3method(nobs,prcomp)
S3method(nobs,pyears)
S3method(nobs,smooth.spline)
S3method(nobs,survdiff)
S3method(nobs,survfit)
S3method(nobs,survfit.cox)
S3method(nobs,survreg)
S3method(tidy,"NULL")
S3method(tidy,Arima)
S3method(tidy,Gam)
Expand Down
25 changes: 25 additions & 0 deletions R/nobs.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,125 +18,150 @@
# quantreg-rqs

# nnet-multinom
#' @export
nobs.multinom <- function(object, ...) {
nrow(object$residuals)
}

# orcutt
#' @export
nobs.orcutt <- function(object, ...) {
nrow(object$residuals)
}

# mass-fitdistr
#' @export
nobs.fitdistr <- function(object, ...) {
object$n
}

# biglm
#' @export
nobs.biglm <- function(object, ...) {
object$n
}

# glmnet-cv-glmnet
#' @export
nobs.cv.glmnet <- function(object, ...) {
stats::nobs(object$glmnet.fit)
}

# gmm
#' @export
nobs.gmm <- function(object, ...) {
object$n
}

# lfe - felm
#' @export
nobs.felm <- function(object, ...) {
object$N
}

# lmodel2
#' @export
nobs.lmodel2 <- function(object, ...) {
object$n
}

# mclust
#' @export
nobs.Mclust <- function(object, ...) {
object$n
}

# muhaz
#' @export
nobs.muhaz <- function(object, ...) {
length(object$pin$times)
}

# polca
#' @export
nobs.poLCA <- function(object, ...) {
object$N
}

# robust-glmrob
#' @export
nobs.lmRob <- function(object, ...) {
length(object$residuals)
}
#' @export
nobs.glmRob <- function(object, ...) {
length(object$residuals)
}

# stats-loess
#' @export
nobs.loess <- function(object, ...) {
object$n
}

# stats-prcomp
#' @export
nobs.prcomp <- function(object, ...) {
NROW(object$x)
}

# stats-smooth.spline
#' @export
nobs.smooth.spline <- function(object, ...) {
length(object$x)
}

# bbmle
#' @export
nobs.bbmle <- function(object, ...) {
length(object@data[[1]])
}

# survival-aareg
#' @export
nobs.aareg <- function(object, ...) {
object$n[1] # obs / event times / event times in computation
}

# survival-survreg
#' @export
nobs.survreg <- function(object, ...) {
length(object$linear.predictors)
}

# survival-survfit
#' @export
nobs.survfit <- function(object, ...) {
object$n
}

# survival-survfit.cox
#' @export
nobs.survfit.cox <- function(object, ...) {
object$n
}

# survival-coxph
#' @export
nobs.coxph <- function(object, ...) {
length(object$linear.predictors)
}

# survival-pyears
#' @export
nobs.pyears <- function(object, ...) {
object$observations
}

# survival-survdiff
#' @export
nobs.survdiff <- function(object, ...) {
s <- summary(object)
s$nobs
}

# tseries
#' @export
nobs.garch <- function(object, ...) {
object$n.used
}

0 comments on commit 8a1fdc4

Please sign in to comment.