Learn R Programming

apsrtable (version 0.8-8)

modelInfo: Model fit and diagnostic functions for output

Description

Model diagnostic / summary information to be included in apsrtable output.

Usage

modelInfo(x) "modelInfo"(x) "modelInfo"(x) "modelInfo"(x) "modelInfo"(x) "modelInfo"(x) "modelInfo"(x) "modelInfo"(x) "modelInfo"(x) "modelInfo"(x)

Arguments

x
A summary object.

Value

lm reports the $N, R^2$, adjusted $R^2$, and residual $\sigma$. The default for glm includes the $N$, AIC, BIC, and log-likelihood. Common names across model classes in the same table -- e.g., the $N$ -- are matched by name, exactly like the model coefficients (indeed, the same functions aggregate terms and order across models.)

Details

Returns a list containing model diagnostic information, with an interface described here to allow the user to change the information returned and thus presented. The method is called by apsrtable within an lapply on a list of model summaries. The modelInfo methods for a given model summary object simply return a list of arbitrary name-value pairs and give themselves the S3 class modelInfo. The modelInfo method dispach uses formal S4 classes, however.

The example shows how one can change the summary for lm objects to include only the $N$ and residual $\sigma$.

If you register a modelInfo method and it appears not to work, try calling setOldClass in order to register new modelInfo methods for your model summary object. Method dispatch in R has some subtleties.

See Also

sys.frame

Examples

Run this code

setMethod("modelInfo", "summary.lm", function(x) {
  env <- sys.parent()
  digits <- evalq(digits, env)
  model.info <- list(
                     "$N$"=formatC(sum(x$df[1:2]),format="d"),
                     "Resid. sd" = formatC(x$sigma,format="f",digits=digits))
  class(model.info) <- "model.info"
  return(model.info)
} )

example(apsrtable)


### Switch back to the default
setMethod("modelInfo", "summary.lm", apsrtable:::modelInfo.summary.lm)
## Not run: 
# example(apsrtable)
# ## End(Not run)

Run the code above in your browser using DataLab