File Exchange

image thumbnail


version 1.0 (456 KB) by

Statistical analysis (ANOVA,…) and plotting of fixed and mixed effects models using modern methods

4 Ratings



View License

LinStats is a collection of classes, functions and data that are useful for representing, solving and analyzing linear statistical models. LinStats has been updated to use a new object based approach to support incremental model-building and more sophisticated analysis.
Notably this is the first Matlab statistical package that can handle ANOVA and Variance Components models with fixed and random effects using Restricted Estimated Maximum Likelihood (REML) including the modern corrections for small sample size. This allows improved estimates for both fixed (Best linear unbiased estimates) and random terms (Best linear unbiased predictors).
Many statistical analysis including ANOVA involve random factors which poses challenging problems. Old solutions used approximations that were required before the advent of computers. Modern solutions use Restricted Estimated Maximum Likelihood. More recent enhancements and refinements include corrections for small sample size (Kenward and Roger) and take into account the uncertainty that parameter estimates have on variance estimates (Harville and Kackar).
This approach is becoming more common but the calculations are complex and this has slowed implementation. Matlab and R, for example, do not support this. I have only seen it in Professional statistics programs like SAS/JMP. Now, for the first time, Matlab Stats users don't need to take a backseat to users of those languages (at least in terms of mixed model analysis of linear models).
Fixed effects analysis outputs have been validated using National Institute of Standards and Technology Standards Technology Reference most difficult datasets (included with Linstats). Random effects outputs have been checked against results produced by SAS/JMP.
Please see zip file for the Word document containing the most complete documentation available.

Comments and Ratings (9)


Faith (view profile)

Hi, any time I try to run a model I get the following error. I have Matlab R2011a and I have both the Statistics and Optimization Toolboxes. Any help?

>> m.anova
??? Cell contents assignment to a non-cell array object.

Error in ==> Mstats>Mstats.solve at 92
            a.beta{ k,: } = b;

Error in ==> Lstats>Lstats.Lstats at 78
            a = solve( a );

Error in ==> Mstats>Mstats.Mstats at 31
            a = a@Lstats(varargin{:});

Error in ==> Model>Model.solve at 115
                    a.stats_ = Mstats(a);

Error in ==> Model>Model.anova at 452
            glm = solve(glm);


Steven (view profile)

Daren Howell

Looks like there was a pathdef error in my installation and I'd lost a link to optimset. Test_linstats output below.

Thanks for freeing me from SAS!!!

passed: ArgParser
passed: Pmat standard ops
Warning: Colon operands must be real scalars.
> In test_dmat at 4
  In test_linstats at 4
passed: Dmat
passed: BDmat
passed: lsestimates
passed: mixed models
passed: fixed effects model
passed: fixed effects model, no intercept
passed: 2-way anacova (separate lines)
Warning: The RandStream.getDefaultStream static method will be removed in a
future release. Use RandStream.getGlobalStream instead.
> In RandStream.RandStream>RandStream.getDefaultStream at 460
  In test_model at 121
  In test_linstats at 8
passed: 2-way anacova (separate lines), multiple response
passed: mixed effects, clinical example
passed: mixed effects, unbalanced clinical example

Daren Howell

Think it mayhave something to do with a different bug in this release.

You call, optimset('fminunc'), which should return the options structure but instead throws an error.

I'll see what the Mathworks make of this.

Daren. Due to a documented bug in Matlab 2011 series, LinStats does not work. The bug is fixed in Matlab 2012a, out today I think.

Daren Howell

Update on above - seems to be related to referencing elements of the Pmat class.

The code references elements using cell array notation e.g. A{2,2}, which throws an error, whereas array notation A(2,2) doesn't.

Daren Howell

I've just installed this with R2011a and have run test_linstats which has thrown up a number of "Cell contents reference from a non-cell array object" errors.

Has anyone else had similar troubles with R2011a?


Steven (view profile)

Thank you for building this!


MATLAB Release
MATLAB 7.11 (R2010b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video