model_search: Stepwise model search

Description Usage Arguments Details Value Examples

View source: R/functions.R

Description

model_search performs a step-wise log-linear model search, and provides an overview of the model selection criteria AIC, AICc and BIC and the estimated population size for the models in the search path.

Usage

1
2
3
4
5
6
7
8
9
model_search(
  x,
  lists = NULL,
  min_model = Freq ~ .,
  max_model = Freq ~ .^2,
  start_model = NULL,
  year = NULL,
  degree_year = NULL
)

Arguments

x

data frame with the lists and (optionally) covariates in the form of a contingency table with the variable Freq containing the observed frequencies, or in the form of a data frame with individual observations. See details for the specifications of the variables.

lists

numeric vector with the column numbers of x containing the lists.

min_model

formula specifying the minimal model considered in the model search. Defaults to the main effects models Freq ~ ..

max_model

formula specifying the maximal model considered in the model search. Defaults to the first-order interaction model Freq ~ .^2.

start_model

formula specifying the first model in the model search. The model should be inside the range of models specified by min_model and max_model. Defaults to the model specified by min_model.

year

character string with the name of the covariate in x containing the year of the observations. The default NULL applies when the covariate is absent.

degree_year

degree of the orthogonal polynomials (1 = linear, 2 = quadratic, 3 = cubic, etc.) to be created for year. The default NULL creates dummy variables.

Details

The lists in x should be coded 0 and 1, with 0 denoting absence and 1 presence on the list.

If the observations are made in subsequent, non-overlapping periods of time (e.g. years), the covariate year indicates the period the observation was made. The maximum value for degree_year is one minus the number of distinct periods.

Value

Displays the degrees of freedom, deviance, AIC, AICc, BIC and population size estimates of the models in the search path, and returns a list with the following objects:

models

the table with the fit statistics of the fitted models.

formulas

the formulas of the fitted models.

coefs

the parameter estimates of the fitted models.

fits

a list with the fitted frequencies of the models in the search path.

minima

a vector with the respective unscaled minima of the AIC, AICc and BIC.

d

the data frame x in the form of a contingency table.

d_year

the data frame d with year (if present) coded as polynomial.

obs

a vector distinguishing between observations and structural zeros in d.

lists

a vector with the column numbers of d with the lists.

year

a scalar indicating the column number of the variable year in d.

Examples

1
2
3
# Model search with 1st-order interactions term only, and quadratic contrasts for year

search <- model_search(x = simdat, lists = 1:4, year = "Y", degree_year = 2)

MaartenCruyff/mse documentation built on Dec. 26, 2021, 2:13 a.m.