JuliaStats/GLM.jl — pull request #70 by timema (2014-05-16 02:53:39+00:00)
Title: add effects and anovatable function for lm

Instead of an ANOVA table that was previously discussed and there were issues about it's potential misuse and abuse. This is a specific, full vs reduced model test where the effects from the desired terms are grouped together in a hypothesis to form a ANOVA style F test.

The effects function extracts the effects from an LmMod either produced with a formula and dataframe or from LmMod produced using a y and X matrix. ANOVA test allows you to specify terms in an LmMod model to do an anova (full vs reduced) test. You can specify 1 or more terms if the model was produced with a formula and data frame. If the LmMod was produced with a y and X, you can specify the columns of X that you would like to group together. ANOVAtest is a type to hold DF,SS,MS,F, and either the pval or -log10pval. It has a show function that produces a table.

Note, that if the model is produced from a formula and dataframe the terms can be specified by their position in the formula where the intercept is 0. A single term can have multiple degrees of freedom if it involves factors. If the model is produced from specified y and X then the user will need to specify what columns of the X matrix would need to be tested (i.e. we do not know the terms from the model if factors are involved.

The names, the option for log10pval, and how I did the show function are just what I put together and have no attachment to. I was also not certain how to deal with the term number and column number difference between models derived with and without formula's and data frames.

Below are some simple examples.
a=randn(100,4);
b=convert(DataFrame,a);

c=fit(LmMod,x1~x2+x3+x4,b) #fit model with formula and dataframe
d=ANOVAtest(c,[2,3],log10pval=true) #test of multiple terms in the formula with LmMod made with formula and dataframe
e=ANOVAtest(c,3) #test of a single term of X with LmMod made with formula and dataframe
f=ANOVAtest(c,[3]) #shows that you can also do one term with a single cell array

g=fit(LmMod,c.model.pp.X,c.model.rr.y) #fit model with X and y without formula or dataframe
h=ANOVAtest(g,[3,4]) #test of multiple columns of X with LmMod made without formula and dataframe
i=ANOVAtest(g,4) #test of a single column of X with LmMod made without formula and dataframe
j=ANOVAtest(g,[4]) #shows that you can also do one term was a single cell array