Mixed anova design function (unbalanced design)

Hi, I am trying to run a mixed (between and within design) anova and it seems like matlab does not have the function for that. I used the code as provided here (https://www.mathworks.com/matlabcentral/fileexchange/27080-mixed-between-within-subjects-anova) but it is not able to run with an unbalanced design i.e the within subject factor in my dataset has varying levels, but the code only runs it when it has same levels.
Is there a function out there that anyone may direct me to, to solve this issue?
Would be very grateful, thank you!

3 Comments

Have you checked https://www.mathworks.com/help/stats/repeatedmeasuresmodel.ranova.html?
Cside
Cside on 31 Dec 2020
Edited: Cside on 31 Dec 2020
Hi Ive & Adam,
Repeated measures wouldnt work in my case as I have a different population undergoing each level of my independent variable (no overlaps in subjects though). Repeated measures requires the same population undergoing through the different levels of the IV.
Please correct me if I am wrong

Sign in to comment.

 Accepted Answer

Adam Danz
Adam Danz on 31 Dec 2020
Edited: Adam Danz on 31 Dec 2020
Disclaimer: I'm not an expert in statistical test selection and have met very few experts on this matter. Test selection should always consider the assumptions, the null hypothesis, and whether or not your experimental methods are appropriate for the test.
From what I undersand you have a categorical independent variable, More|Less light exposure, where each level was applied to different groups of people. You have a continuous independent variable, hours of sleep during pre-expt, that potentially differs between all subjects. And you have dependent variable you're measuring which you didn't mentioned, perhaps something like serotonin or melatonin levels. You want to make sure the hours of sleep hasn't significantly affected the outcome of the DV.
A ANCOVA analysis will answer this question. An ANCOVA evaluates whether the means of the DV are equal across levels of the categorical IV (More|Less light) while controlling for the effects of a continuous covariate sometimes called a nuisance variable [wiki].
Note that a general linear model (GLM) is the same mathematical model as an ANCOVA (see Karen Grace-Martin's concise comparison).
Recommended sources on ANCOVA & GLM
  • Bingham & Fry (2010). Regression: Linear models in statistics. Chapter 5.2
  • Freund, Wilson, & Sa (2006). Regression Analysis Statistical Modeling of a Response Variable. Chapter 9.6
  • Brandon Foltz's excellent tutorial on ANCOVA [youtube].
  • Quantitative methods in Neuroscience, Chapter 9 (on GLM) [available online]
Matlab tools & Community resources
----------------------------------------------------------------
Old answer:
There's not enough information about your design to understand if a rmANOVA, 2-way ANOVA, ANCOVA, or a general linear model would be suitable. More importantly, that choice relies on the question you're asking which is also unclear.
If you can briefly describe your design and the question you're asking, I could help further and will update this answer. In the meantime, here are some general resource provided by Matlab on linear mixed-effects models.

4 Comments

Cside
Cside on 31 Dec 2020
Edited: Cside on 31 Dec 2020
Sure, I have an IV - 2 conditions, more light exposure or less light exposure in the experiment. Each condition has 100 subjects (total n = 200). This would be the between subject factor.
All subjects are required to sleep 7 hrs, for 10 days prior to the experiment. These 10 days will be the within subject factor. Subjects were interviewed of the number of hrs they slept prior to the experiment, but one could expect variation eg sleeping 10 hrs, 8hrs, 6.5hrs instead of 7hrs etc. Additionally, some participants did not do so for 10 days, and adhered only to 9 days.
The goal of the analysis is to see if the two groups differed significantly in sleep in the pre-expt, adjusting for possible covariates perhaps eg subjects?
Thank you so much Adam, happy holidays
That's helpful. I've updated my answer.
Thank you for the exceptional answer, and for directing me to these resources. I will peruse them.
All best
Based on what you already explained, you have a repeatedly measured IV (and single DV). Just note that in this scenario (GLM) you miss the structure of sleeping hours (as you already mentioned, you are interested in day-to-day variation). So you're reducing your model to
fitlm(data, 'response ~ sleeping_hrs + light_exposure')
This essentially means you are collapsing the sleeping hours matrix into a single vector (you may consider the matrix as a covariate but I'm not sure if this doesn't violate the independence assumption among IVs):
sleeping_hrs = sum(sleeping_hrs_mat, 2); % assuming no NaN values
You may also want to take a look at the discussion over a similar question here. So, you could use a latent growth curve model first, and use the outcome as a new IV for your response. However, everything here depends on your research questions.

Sign in to comment.

More Answers (1)

If the goal of the analysis is to see if the two groups differ significantly in sleep pre-expt, then actually the simplest appropriate analysis is to (a) compute the average sleep for each subject over the preceding 9 or 10 days, and then (b) do a between-groups t-test on these 200 averages.
You could also analyze these averages as the DV in a 2-group ANCOVA with any possible covariates that you wanted to adjust for.
It may seem unintuitive that the day-to-day variation within each subject can be ignored using these across-day averages, but that is actually the case in an ANOVA with both between- and within-Ss factors.

1 Comment

That is true, I would like to capture their day-to-day variation as well, and was refraining from ttest for that reason. missed that out for anova. Thank you Jeff!

Sign in to comment.

Asked:

on 30 Dec 2020

Edited:

on 1 Jan 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!