Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nObs

Number of Observations


Description

Returns the number of observations for statistical models, estimated by Maximum Likelihood using maxLik.

Usage

## S3 method for class 'maxLik'
nObs(x, ...)

Arguments

x

a statistical model estimated by Maximum Likelihood using maxLik.

...

further arguments (currently ignored).

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.

Value

numeric, number of observations

Author(s)

Arne Henningsen, Ott Toomet

See Also

Examples

## 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 )

maxLik

Maximum Likelihood Estimation and Related Tools

v1.4-8
GPL (>= 2)
Authors
Ott Toomet <otoomet@gmail.com>, Arne Henningsen <arne.henningsen@gmail.com>, with contributions from Spencer Graves and Yves Croissant
Initial release
2021-03-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.