create.XMAT: design matrix for a hmm model

Description Usage Arguments Details Value References See Also Examples

Description

Function to specify the matrix X of the linear predictor Cln(Mm)=Xbeta for a hmm model.

Usage

1
2
3
create.XMAT(model, Formula = NULL, 
strata = 1, fnames = NULL, cocacontr = NULL, 
ncocacontr = NULL, replace = TRUE)

Arguments

model

Object created by ‘hmmm.model’

Formula

List of model-formulas; one formula for every marginal interaction

strata

Number of categories of the factors that describe the strata

fnames

Names of the factors that describe the strata

cocacontr

A list of zero-one matrices to build "r" logits created by the function ‘recursive’

ncocacontr

Number of contrasts for every factor, if NULL the maximum number is used

replace

If TRUE a new model object with design matrix X is produced, if FALSE the list of design matrices associated to each element specified in Formula is returned

Details

When the marginal interactions of a hmm model are defined in terms of a linear predictor of covariates Cln(Mm)=Xbeta, the list of model formulas defines additive effects of covariates on the interactions. In a case with two response variables declared by names<-c("A","B") and two covariates, named C and D by fnames=c("C","D"), the additive effect of the covariates on marginal logits of A and B and log odds ratios (A.B) of the two responses is specified by the following Formula: Formula<-list(A=~A*(C+D), B=~B*(C+D), A.B=~A.B*(C+D)). Use "zero" to constrain to zero all the interactions of a given type.

Value

A list of matrices or a hmm model with X as design matrix according to the input argument replace. The parameters beta in the predictor Cln(Mm)=Xbeta are the effects specified in Formula and correspond to the columns of X.

References

Lang JB (2004) Multinomial Poisson homogeneous models for contingency tables. The Annals of Statistics, 32, 340-383.

Lang JB (2005) Homogeneous linear predictor models for contingency tables. Journal of the American Statistical Association, 100, 121-134.

See Also

hmmm.model, hmmm.mlfit, summary.hmmmfit

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
data(accident)
y<-getnames(accident,st=9,sep=";")
# responses: 1 = Type, 2 = Time; covariates: 3 = Age, 4 = Hour

marglist<-c("l-m","m-g","l-g")
marginals<-marg.list(marglist,mflag="m")
names<-c("Type","Time")

modelsat<-hmmm.model(marg=marginals,lev=c(3,4),
strata=6, names=names) 

# Create X to account for additive effect of Age and Hour on the logits of Type and Time
# and constant association between Type and Time
al<-list(Type=~Type*(Age+Hour),
Time=~Time*(Age+Hour),Type.Time=~Type.Time)
# list of matrices (replace=FALSE)
listmat<-create.XMAT(modelsat,Formula=al,strata=c(3,2),fnames=c("Age","Hour"),replace=FALSE)

# the model obtained by the modified X (replace=TRUE)
model<-create.XMAT(modelsat,Formula=al,strata=c(3,2),fnames=c("Age","Hour")) 
fitmodel<-hmmm.mlfit(y,model,y.eps=0.00001,maxit=2000)
print(fitmodel)

hmmm documentation built on May 2, 2019, 12:27 p.m.