Learn R Programming

maxLik (version 0.8-0)

nObs.maxLik: 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, \dots)

Arguments

x
a statistical model estimated by Maximum Likelihood using maxLik.
...
further arguments (currently ignored).

Value

  • numeric, number of observations

Details

The nObs method for objects of class "maxLik" can return the number of observations only if maxLik was called with argument grad equal to a gradient function or (if no gradient function is specified) argument logLik equal to a log-likelihood function that return the gradients or log-likelihood values, respectively, for each observation.

See Also

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