obs_exp: Observed versus expected diagnostic

View source: R/obs_exp.R

obs_expR Documentation

Observed versus expected diagnostic

Description

Given a covariate, calculate the observed and expected counts for each unique value of the covariate. This can be a useful goodness of fit check for GAMs when modelling count data. It might make sense in other cases.

Usage

obs_exp(model, covar, cut = NULL)

Arguments

model

a fitted GAM

covar

covariate to aggregate by (character)

cut

vector of cut points to aggregate at. If not supplied, the unique values of covar are used.

Details

One strategy for model checking is to calculate observed and expected counts at different aggregations of the variable. If these match well then the model fit is good.

Value

data.frame with values of observed and expected counts.

Author(s)

David L Miller, on the suggestion of Mark Bravington.

Examples

# simulate poisson data...
set.seed(6)
dat <- gamSim(1,n=200,dist="poisson",scale=.1)

b2<-gam(y~s(x0)+s(x1)+s(x2)+
        s(x3),family=poisson,data=dat,method="REML", control=gam.control(keepData=TRUE))
plot(b2,pages=1)

dill/mgcvUtils documentation built on Oct. 14, 2024, 7:30 p.m.