Unable to run Two-way repeated measures ANOVA; 0 (non-NA) cases
I am trying to follow the tutorial by Datanovia for Two-way repeated measures ANOVA.
A quick overview of my dataset:
I have measured the number of different bacterial species in 12 samplingsunits over time. I have 16 time points and 2 groups. I have organised my data as a tibble called "richness";
# A tibble: 190 x 4 id selection.group Day value <fct> <fct> <fct> <dbl> 1 KRH1 KR 2 111. 2 KRH2 KR 2 141. 3 KRH3 KR 2 110. 4 KRH1 KR 4 126 5 KRH2 KR 4 144 6 KRH3 KR 4 135. 7 KRH1 KR 6 115. 8 KRH2 KR 6 113. 9 KRH3 KR 6 107. 10 KRH1 KR 8 119.
The id refers to each sampling unit, and the selection group is of two factors (KR and RK).
richness <- tibble( id = factor(c("KRH1", "KRH3", "KRH2", "RKH2", "RKH1", "RKH3")), selection.group = factor(c("KR", "KR", "KR", "RK", "RK", "RK")), Day = factor(c(2,2,4,2,4,4)), value = c(111, 110, 144, 92, 85, 69)) # subset of original data
My tibble appears to be in an identical format as the one in the tutorial;
> str(selfesteem2) Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 72 obs. of 4 variables: $ id : Factor w/ 12 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ... $ treatment: Factor w/ 2 levels "ctr","Diet": 1 1 1 1 1 1 1 1 1 1 ... $ time : Factor w/ 3 levels "t1","t2","t3": 1 1 1 1 1 1 1 1 1 1 ... $ score : num 83 97 93 92 77 72 92 92 95 92 ..
Before I can run the repeated measures ANOVA I must check for normality in my data. I copied the framework proposed in the tutorial.
#my code richness %>% group_by(selection.group, Day) %>% shapiro_test(value) #tutorial code selfesteem2 %>% group_by(treatment, time) %>% shapiro_test(score)
But get the error message "Error: Column
variable is unknown" when I try to run the code. Does anyone know why this happens?
I tried to continue without insurance that my data is normally distributed and tried to run the ANOVA
res.aov <- rstatix::anova_test( data = richness, dv = value, wid = id, within = c(selection.group, Day) )
But get this error message; Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases
I have checked for NA values with
any(is.na(richness)) which returns FALSE. I have also checked
table(richness$selection.group, richness$Day) to be sure my setup is correct
2 4 6 8 12 16 20 24 28 29 30 32 36 40 44 50 KR 6 6 6 6 6 6 6 6 6 6 6 5 6 6 6 6 RK 6 6 6 6 6 5 6 6 6 6 6 6 6 6 6 6
And the setup appears correct. I would be very grateful for tips on solving this.
Best regards Madeleine
Below is a subset of my dataset in a reproducible format:
library(tidyverse) library(rstatix) library(tibble) richness_subset = data.frame( id = c("KRH1", "KRH3", "KRH2", "RKH2", "RKH1", "RKH3"), selection.group = c("KR", "KR", "KR", "RK", "RK", "RK"), Day = c(2,2,4,2,4,4), value = c(111, 110, 144, 92, 85, 69)) richness_subset$Day = factor(richness$Day) richness_subset$selection.group = factor(richness$selection.group) richness_subset$id = factor(richness$id) richness_subset = tibble::as_tibble(richness_subset) richness_subset %>% group_by(selection.group, Day) %>% shapiro_test(value) # gives Error: Column `variable` is unknown res.aov <- rstatix::anova_test( data = richness, dv = value, wid = id, within = c(selection.group, Day) ) # gives Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : # 0 (non-NA) cases
I create something like the design of your data:
set.seed(111) richness = data.frame(id=rep(c("KRH1","KRH2","KRH3"),6), selection.group=rep(c("KR","RK"),each=9), Day=rep(c(2,4,6),each=3,times=2),value=rpois(18,100)) richness$Day = factor(richness$Day) richness$id = factor(richness$id)
First, shapiro_test, there's a bug in the script and the value you wanna test cannot be named "value":
# gives error Error: Column `variable` is unknown richness %>% shapiro_test(value) #works richness %>% mutate(X = value) %>% shapiro_test(X) # A tibble: 1 x 3 variable statistic p <chr> <dbl> <dbl> 1 X 0.950 0.422 1 X 0.963 0.843
Second, for the anova, this works for me.
rstatix::anova_test( data = richness, dv = value, wid = id, within = c(selection.group, Day) )
In my example every term can be estimated.. What I suspect is that one of your terms is a linear combination of the other. Using my example,
set.seed(111) richness = data.frame(id=rep(c("KRH1","KRH2","KRH3","KRH4","KRH5","KRH6"),3), selection.group=rep(c("KR","RK"),each=9), Day=rep(c(2,4,6),each=3,times=2),value=rpois(18,100)) richness$Day = factor(richness$Day) richness$id = factor(richness$id) rstatix::anova_test( data = richness, dv = value, wid = id, within = c(selection.group, Day) ) Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases
Gives the exact same error. This can be checked using:
lm(value~id+Day:selection.group,data=richness) Call: lm(formula = value ~ id + Day:selection.group, data = richness) Coefficients: (Intercept) id1 id2 101.667 -3.000 -6.000 id3 id4 id5 -6.000 1.889 11.556 Day2:selection.groupKR Day4:selection.groupKR Day6:selection.groupKR 1.667 -12.000 9.333 Day2:selection.groupRK Day4:selection.groupRK Day6:selection.groupRK -1.667 NA NA
The Day4:selection.groupRK and Day6:selection.groupRK are not estimateable because they are covered by a linear combination of factors before.
Two-Way Repeated Measures ANOVA: Error in lm.fit()… 0 non-na , 0 non-na cases (rstatix) I am trying to run a Two-Way Repeated Measures ANOVA using the R Based on the first post above, I tried to run: If you are unsure whether a two-way repeated measures ANOVA is appropriate, you may also want to consider how it differs from a one-way repeated measures ANOVA and a mixed ANOVA. A two-way repeated measures ANOVA goes further than a one-way repeated measures ANOVA, which only has one factor (i.e., one independent variable). For example, a one-way repeated measures ANOVA could be used when you only wanted to know whether there was a difference in chronic back pain before and after a back
The solution for running the Shapiro_test proposed above worked.
And I figured out I have some linear combination by running
lm(value~id+Day:selection.group,data=richness). However, I don't understand why? I know I have data points for each group (see graph). Where does this linear combination come from?
Repeated measure ANOVA appears so appropriate for me as I am following sampling units over time.
Repeated Measures ANOVA in R: The Ultimate Guide, The main goal of two-way and three-way repeated measures ANOVA is, are not met, you could consider running the two-way/three-way repeated the case/ sample identifier. within : within-subjects factor or grouping variable  treatment time id score is.outlier is.extreme ## <0 rows> (or 0-length 0 (non-NA ) cases. A two-way repeated measures ANOVA showed no significant interaction between time and treatment. By curiosity, I ran some one-way repeated measures ANOVAs to see if there was a difference between
I had the same issue. Couldn't find out the solution. Finally the following works: install "ez" package
newModel<-ezANOVA(data = dataFrame, dv = .(outcome variable), wid = .(variable that identifies participants), within = .(repeated measures predictors), between = . (between-group predictors), detailed = FALSE, type = 2)
Example: bushModel<-ezANOVA(data = longBush, dv = .(Retch), wid = .(Participant), within = .(Animal), detailed = TRUE, type = 3)
Two-Way Repeated Measures ANOVA: Error in lm.fit() 0 non-na , 0 non-na cases (rstatix). 发布于 2020-05-05 08:05:43. I am trying to run a Two- Way Repeated Measures ANOVA using the R Statix package based on the� independent variable with two levels, a repeated measures ANOVA can be done when you have more than two conditions, and/or more than one independent variable. In this tutorial we will consider an example where we have two independent variables and
When Does Repeated Measures ANOVA not work for Repeated , Repeated measures ANOVA is the approach most of us learned in stats listwise deletion, if one measurement is missing, the entire case gets dropped. Because of that wide-data format, there's no way to specify that each measurement of the If the subjects themselves are not only measured multiple times, but also� How to conduct a two-way repeated-measures (related) ANOVA in SPSS (PASW). View in HD (720p) and in full screen for best resolution.
How does one do a two way repeated measures ANOVA with , Unfortunately I could not get a measure for every animal every day, which means I We can analyse data using a repeated measures ANOVA for two types of If it is in fact a repeated measures problem, then you may have to eliminate cases and/or The simplest way to solve this is to use a very small value like 0,01 to 0 � I demonstrate how to perform and interpret a two-way repeated measures ANOVA. Specifically, a 2 by 2 repeated measures ANOVA. I help explain interpreting the
R Tutorial Series: One-Way Repeated Measures ANOVA, This tutorial will demonstrate how to conduct one-way repeated measures ANOVA in R using the Anova(mod, idata, idesign) function from the car package. Repeated Measures ANOVA Issues with Repeated Measures Designs Repeated measures is a term used when the same entities take part in all conditions of an experiment. So, for example, you might want to test the effects of alcohol on enjoyment of a party. In t his type of experiment it is important to control
- Please share your data in a reproducible format. Viewing the
str()doesn't make it easy to copy/paste the data to test your code.
- Error: Column variable is unknown -> issue might occur due to variable name being mistyped is it possible that you forgot to put a letter in caps? in group_by(selection.group, Day) %>% I for instance see that Day has a capital D
- Looking at the source for
shapiro_test, my guess was that you had a group of observations that were all NA, or a single row. Looking at the tests you've done, that doesn't seem to be the case. Without your full data to test, it's hard to help. If you don't want to share it, you can always try to anonymize it with something like
richness$value <- richness$value + rnorm(190).
- @Brian, I don't think it is the issue here. I was assuming the same thing and also that has there is multiple groups maybe one group was too small to fit condition for the
shapiro.test. But after running a similar example and excluding group below 3, I get the same issue. The error code seems to be related to
dplyrmore than to the
shapiro_test. But I don't have yet pinpoint the error.
- I was looking at that hardcoded
shapiro_testfunction definition and knew that was somehow the culprit, but couldn't figure out renaming the variable was the solution!
- Changing the column name "value" to something else actually helped! Thank you so much!
- Cool! Glad it helped :)