Learn R Programming

maxLik (version 1.6-10)

nObs.maxLik: Number of Observations

Description

Returns the number of observations for statistical models, estimated by Maximum Likelihood using maxLik. nobs users the standard generic from stats4, nObs (deprecated) uses the S3 generic from miscTools.

Usage

# S3 method for maxLik
nObs(x, ...)
# S4 method for maxLik
nobs(object, ...)

Value

numeric, number of observations

Arguments

object

a statistical model estimated by Maximum Likelihood using maxLik.

x

a statistical model estimated by Maximum Likelihood using maxLik.

...

further arguments (currently ignored).

Author

Arne Henningsen, Ott Toomet

Details

The nobs method for “maxLik” objects can return the number of observations only if log-likelihood function (or the gradient) returns values by individual observation.

See Also

nobs, nObs, maxLik, nParam.

Examples

Run this code
## fit a normal distribution by ML
# generate a variable from normally distributed random numbers
x <- rnorm( 100, 1, 2 )
# log likelihood function (for individual observations)
llf <- function( param ) {
   return( dnorm( x, mean = param[ 1 ], sd = param[ 2 ], log = TRUE ) )
}
## ML method
ml <- maxLik( llf, start = c( mu = 0, sigma = 1 ) )
# return number of onservations
nobs( ml )

Run the code above in your browser using DataLab