numeric factors

78 views
Skip to first unread message

Todd Horowitz

unread,
Apr 10, 2012, 5:34:30 PM4/10/12
to ez4r
I'm analyzing a dataset with three sessions. If I use as the "within"
variable a factor with session names (i.e. "X1", "X2", "X3"), I get
out an ANOVA result with Dfn = 2. However, if I use a numeric variable
(i.e., 1, 2, 3), I get the mssage "Warning: There is at least one
numeric within variable, therefore aov() will be used for computation
and no assumption checks will be obtained.", and the ANOVA result has
Dfn = 1. What is going on in the second case?

thanks
Todd

Mike Lawrence

unread,
Apr 10, 2012, 6:00:18 PM4/10/12
to ez...@googlegroups.com, t.s.ho...@gmail.com
Hi Todd,

Whenever you do an anova with a numeric predictor variable, the df for
that variable will be 1 because all it is doing is fitting a linear
slope across the levels of that variable. In contrast, when you
artificially turn a numeric variable into a factor, the df will be as
for any categorical variable, the number of levels minus 1.

Treating the numeric predictor variable as properly numeric will yield
greatest power to detect linear effects, but will have low power to
detect non-linear effects. Artificially turning the variable into a
factor will yield better power to detect non-linear effects, but this
will still be mediocre and your power to detect linear effects will
also be rather mediocre.

This annoying trade-off is why I have come to love generalized
additive modelling (GAM), which has excellent power to detect both
linear and non-linear effects. In ez, GAM is implemented in the dev
version (https://github.com/mike-lawrence/ez#readme) of the ezMixed
function, where it can compute a generalized additive mixed effects
model when you have a random effect (e.g. subjects) to account for.

Mike

Thom

unread,
Apr 13, 2012, 6:43:26 AM4/13/12
to ez4r

Off-topic slightly but "Treating the numeric predictor variable as
properly
numeric will yield greatest power to detect linear effects, but will
have
low power to detect non-linear effects" isn't strictly true. You can
set
up contrasts that have greater power to detect linear effects than
linear contrasts - and linear contrasts have good power to detect some
non-linear effects. The advantage of the linear contrast is that it
pulls
out the linear component from a complex trend cleanly (and is
generally
the best option to detect linear effects).

I've not used GAMs, but my advice would be to use a priori contrasts
where possible - the only drawback is that you need to have fairly
clear hypotheses to test or to compare (but I see that as mainly
a virtue in encouraging good research practice ...).

Thom
Reply all
Reply to author
Forward
0 new messages