formula2index: Convert Between Formula and Index

Description Usage Arguments Value Note Author(s) Examples

View source: R/formula2index.R

Description

These functions will convert a formula object to a binary index and vice versa.

Usage

1
2
3
formula2index(big.X, formula, data)

index2formula(index, maximal.mod)

Arguments

big.X

The design matrix under the maximal model.

formula

An object of class "formula": a symbolic description of the model to convert to a binary index.

data

An object of class "data.frame" containing the variables in the model.

maximal.mod

An object of class "glm" giving the fit of the maximal model.

index

A binary vector, of the same length as the number of log-linear parameters in the maximal model, indicating which parameters are present in the model to be converted to a formula.

Value

The function formula2index will produce a binary vector of the same length as the number of log-linear parameters in the maximal model, indicating which parameters are present in the model represented by the argument formula.

The function index2formula will produce an object of class "formula": a symbolic description of the model given by the argument index.

Note

This function will not typically be called by the user.

Author(s)

Antony M. Overstall A.M.Overstall@soton.ac.uk.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
data(ScotPWID)
## Load the ScotPWID data

maximal.mod<-glm(y~(S1+S2+S3+S4+Region+Gender+Age)^2,family=poisson,contrasts=list(
S1="contr.sum",S2="contr.sum",S3="contr.sum",S4="contr.sum",
Region="contr.sum",Gender="contr.sum",Age="contr.sum"),data=ScotPWID,x=TRUE)
## Fit the maximal model containing all two-way interactions.

big.X<-maximal.mod$x
## Set the design matrix under the maximal model

index<-formula2index(big.X=big.X,
formula=~S1+S2+S3+S4+Region+Gender+Age+S1:S2+S1:Age+S2:Gender+S3:S4+S4:Age,
data=ScotPWID)
## Find the index under the model with the following interactions:
## S1:S2
## S1:Age
## S2:Gender
## S3:S4
## S4:Age

index
## Print index
# [1] 1 1 1 1 1 1 1 1 1 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0

index2formula(index=index,maximal.mod=maximal.mod)
## Go back to formula
#y ~ S1 + S2 + S3 + S4 + Region + Gender + Age + S1:S2 + S1:Age + 
#    S2:Gender + S3:S4 + S4:Age

conting documentation built on May 1, 2019, 8:47 p.m.