-
Notifications
You must be signed in to change notification settings - Fork 2
Maths behind phia functions
In general, it is a combination of differences between expected values of the output of the model, for given contrasts of factor levels.
For instance, let's consider a linear model called mod
containing the factor treatment
with levels placebo
and medication
, and the factor gender
with levels male
and female
. You can test the contrasts of treatment
for both genders, through:
testInteractions(mod, pairwise=treatment, fixed=gender)
This will give a table with two rows, which may bear the labels medication-placebo : female
and medication-placebo : male
. The value reported in both rows will be the difference between the expected output of the model for cases of medication
minus the expected output for placebo
, for each gender.
However, the default behaviour of the function will be reporting the pairwise contrasts between both factors. I.e. if you call:
testInteractions(mod)
You will ge a table with only one row, labelled something like medication-placebo : female-male
. The value reported in this case is the "difference of differences", and (for a linear model at least) will coincide with the difference between the two rows of the previous example. In models with more factors or more levels within each factor there may be many more rows, and more levels of nested differences, but the rationale is the same in all cases.
The test reported in each row of the table is related to the "relevance" of those values. In the simplest case of linear models, it means to what extent they are significantly different from zero.
Please read chapters from 3 to 5 of the vignette to find many more examples with actual data.
testInteractions
is a wrapper of the function linearHypothesis
from package car. As told in the manual of that package, it carries out a Wald test, which in this case compares the expected value of the interaction reported in the column called Value
with the null hypothesis. When there are multiple rows in the table, the test is adjusted for multiple comparisons, using Holm's correction by default; this can be changed using the argument adjust
(see the help page of the function p.ajust
for further information).
testInteractions
provides whatever test is given by the function linearHypothesis
from package car for the given type of model. As explained in the manual of that package, that is an F-test for univariate tests if it is possible to determine the degrees of freedom of the residuals, or a Chi-squared test otherwise. It can even be other type of test (Pillai, etc.) in the case of multivariate models (with vector outputs).
The package "phia" is not restricted by design to a particular set of models, but it has only been tested with linear models (univariate and multivariate), generalised linear models, and mixed models fitted by the functions of package nlme and lme4.
Contributions are welcome from any user that may provide data and expected results to validate the outcomes. But please consider that other models should be supported by the function linearHypothesis
of package car, which is used by the functions coded in "phia" to make statistical tests.