Learn R Programming

spaMM (version 3.2.0)

extractors: Functions to extract various components of a fit

Description

formula extracts the model formula. family extracts the response family. terms extracts the fixed-effect terms. nobs returns the length of the response vector. logLik extracts the log-likelihood (exact or approximated). dev_resids returns a vector of squared (unscaled) deviance residuals (the summands in McCullagh and Nelder 1989, p. 34). deviance returns the sum of squares of these (unscaled) deviance residuals, that is (consistently with stats::deviance) the unscaled deviance. fitted extracts fitted values (see fitted.values). residuals extracts residuals of the fit. response extracts the response (as a vector). fixef extracts the fixed effects coefficients, \(\beta\). ranef extracts the predicted random effects, Lv (default since version 1.12.0), or u (see Details in HLfit for definitions), print.ranef controls their printing. getDistMat returns a distance matrix for a Mat<U+00E9>rn correlation model. get_RLRTSim_args returns a list of arguments suitable for calls to RLRsim::RLRTSim()

Usage

# S3 method for HLfit
formula(x, which="hyper", ...)
# S3 method for HLfit
family(object, ...)
# S3 method for HLfit
terms(x, ...)
# S3 method for HLfit
nobs(object, ...)
# S3 method for HLfit
logLik(object, which, ...)
# S3 method for HLfit
fitted(object, ...)
# S3 method for HLfit
fixef(object, ...)
# S3 method for HLfit
ranef(object, type = "correlated", ...)
# S3 method for ranef
print(x, max.print = 40L, ...)
# S3 method for HLfit
deviance(object, ...)
# S3 method for HLfit
residuals(object, type = c("deviance", "pearson", "response"), ...)
getDistMat(object, scaled=FALSE, which = 1L)
response(object,...)
dev_resids(object,...)
get_RLRTSim_args(object,...)

Arguments

object

An object of class HLfit, as returned by the fitting functions in spaMM.

type

For ranef, use type="correlated" (default) to display the correlated random effects (Lv), whether in a spatial model, or a random- coefficient model. Use type="uncorrelated" to pretty-print the elements of the <object>$ranef vector (u). For residuals, the type of residuals which should be returned. The alternatives are: "deviance" (default), "pearson", and "response".

which

For logLik, the name of the element of the APHLs list to return (see Details for any further possibility). The default depends on the fitting method. In particular, if it was REML or one of its variants, the function returns the log restricted likelihood (exact or approximated). For getDistMat, an integer, to select a random effect from several for which a distance matrix may be constructed. For formula, by default the model formula with non-expanded multIMRF random-effect terms is returned, while for which="" a formula with multIMRF terms expanded as IMRF terms is returned.

scaled

If FALSE, the function ignores the scale parameter \(rho\) and returns unscaled distance.

x

For print.ranef: the return value of ranef.HLfit.

max.print

Controls options("max.print") locally.

Other arguments that may be needed by some method.

Value

Return values are numeric (for logLik), vectors (most cases), matrices or dist objects (for getDistMat), or a family object (for family). ranef returns a list of vectors or matrices (the latter for random-coefficient terms). terms returns an object of class c("terms", "formula") which contains the terms representation of a symbolic model. See terms.object for its structure.

get_RLRTSim_args extracts a list of arguments suitable for a call to RLRsim::RLRTSim() for a small-sample test of the presence of a random effect by an efficient simulation procedure. The test can be run by do.call("RLRTSim",<get_RLRTSim_args return value>).

Details

See residuals.glm for more information about the types of residuals.

With which="LogL_Lap", logLik() returns a Laplace approximation of log-likelihood based on the observed Hessian, rather than the expected Hessian. This is implemented only for the case family=Gamma(log), for demonstration purposes.

References

McCullagh, P. and Nelder J. A. (1989) Generalized linear models. Second ed. Chapman & Hall: London.

Lee, Y., Nelder, J. A. (2001) Hierarchical generalised linear models: A synthesis of generalised linear models, random-effect models and structured dispersions. Biometrika 88, 987-1006.

Lee, Y., Nelder, J. A. and Pawitan, Y. (2006) Generalized linear models with random effects: unified analysis via h-likelihood. Chapman & Hall: London.

See Also

See get_matrix vcov.HLfit to extract covariances matrices from a fit.

Examples

Run this code
# NOT RUN {
data("wafers")
m1 <- HLfit(y ~X1+X2+(1|batch),
          resid.model = ~ 1 ,data=wafers,HLmethod="ML")
fixef(m1)
ranef(m1)
# }

Run the code above in your browser using DataLab