vignettes_defining_model.Rmd
The easiest and recommended way to define a model is to pass a
formula. Formula formats accepted by stats:glm
and
lme4::lmer()
functions are accepted.
For instance, a regression with interaction is passed as:
mod1<-gamlj_lm(formula = y~x*z, data=data)
For mixed and generalized mixed models the lme4::lmer()
format is accepted:
mod2<-gamlj_lm(formula = y~x*z+(1+x|cluster), data=data)
For logistic models, a part from the standard format, one can pass the formula with two additional format: The first allows passing the counts of successes and the counts of failures as a combined array.
Alternatively, one can pass the probability of success (with
)
and the counts of cases
()
for each row in the data.frame. The format uses /
to
indicate p over T
.
mod4<-gamlj_glm(formula = p / tot ~x*z, model_type="logistic", data=data)
In all models, polynomial terms can be passed using the
I()
format:
Please notice that the I()
is not interpreted literally,
so the term is build after any manipulation of the variable takes
places, such as centering or standardizing.
Another way to define the model is to define the arguments
model_terms
and defining the dependent variable with the
argument dep
. model_terms
can be passed as a
right-hand formula or as a list.
gamlj_lm(dep=ycont,model_terms=~x*z , data=data)
When terms is passed as a list, each element is a term, and elements
with more than 1 term, such as c("x","z")
are
interactions.
For mixed and generalized mixed models, this method requires to
define the random effects of the model with argument
re
.
For mixed and generalized mixed models, there are also the terms of the comparison model that can be defined as formula:
gamlj_mixed(formula=ycont~x+(1+x|cluster),nested_terms=~1,nested_re=~1|cluster, data=data)
Several arguments if gamlj_* functions can be passed either as formula or as a list. They are:
For both argument, either a right-hand formula or a list can be passed.
data$cat2<-factor(data$cat2)
data$cat3<-factor(data$cat3)
gamlj_lm(formula=ycont~cat2*cat3,posthoc=~cat2+cat2:cat3 , data=data)
This produces the comparisons only across cat2 levels and the
comparison across the interaction
.
For these arguments, we do not use the formula cat2*cat3
because it is not expanded, so passing cat2*cat3
would
produce two tables of comparisons, one for the comparison across cat2
levels, and one across cat3 levels.
The equivalent argument as a list is: