nobs
Extract the Number of Observations from a Fit

Description

Extract the Number of Observations from a Fit

Usage

nobs(object, ...)
## Default S3 method:
nobs(object, use.fallback = FALSE, ...)
## S3 method for class 'glm':
nobs(object, ...)
## S3 method for class 'lm':
nobs(object, ...)
## S3 method for class 'nls':
nobs(object, ...)

Arguments

object object inheriting from fitted model or list with "nobs" components.
use.fallback logical value, if TRUE, use the length of the object's weights or residuals component if they exist and there is no nobs component
... additional arguments for future functions.

Details

The default method returns the nobs component of object if it exists. If use.fallback is TRUE the default method will return the length of the weights component (if it exists) or the length of the residuals component (if it exists and weights does not).
The "glm" method returns the length of object's weights component.
The "lm" returns the length of object's weights component excluding the zero-weights or the length of the residuals component if there is no weights component.
The "logLik" method returns the "nobs" attribute of object.
The "nls" method returns the number of non-zero weights if there are weights in the model, otherwise the number of rows in the data after rows with missing values are removed and the desired subset is extracted.
Value
a numeric value that indicates the number of observations.
See Also
weights, residuals.
Examples
z1 <- list(x=c(1, 2, 3), nobs=3)
nobs(z1)
## [1] 3
z2 <- list(x=c(1, 2, 3), nobs=c(3, 4))
nobs(z2)
## [1] 3 4

z3 <- list(x=c(1, 2, 3), residuals=1:13) nobs(z3, use.fallback=TRUE) ## [1] 13

g1 <- glm(ozone ~ radiation + poly(wind, temperature, degree = 2), data = Sdatasets::air) nobs(g1) ## [1] 111

Package stats version 6.1.4-13
Package Index