I'm trying to run a 2-way repeated measures ANOVA to look at condition and time effect on systolic BP. I'm using the anova_test()
function but I'm getting the error:
Error in `spread()`:
! Each row of output must be identified by a unique combination of keys.
ℹ Keys are shared for 6 rows
• 14, 36
• 182, 204
• 98, 120
I'm unsure of why these are reading as non-unique?
> df_lbp[c(14,36),]
# A tibble: 2 × 10
subject_id condition visit time syst timef conditionf
<dbl> <dbl> <dbl> <int> <dbl> <fct> <fct>
1 129 0 1 1 106. anticipate Control
2 165 1 1 1 119 anticipate Stress
> df_lbp[c(182, 204),]
# A tibble: 2 × 10
subject_id condition visit time syst timef conditionf
<dbl> <dbl> <dbl> <int> <dbl> <fct> <fct>
1 129 0 1 3 103. recovery Control
2 165 1 1 3 121. recovery Stress
> df_lbp[c(98, 120),]
# A tibble: 2 × 10
subject_id condition visit time syst timef conditionf
<dbl> <dbl> <dbl> <int> <dbl> <fct> <fct>
1 129 0 1 2 102. task Control
2 165 1 1 2 128 task Stress
I'm curious what r is pulling from to use as keys, and I'd appreciate any help in getting this to work. My code and data are below.
a1 <- anova_test( data = df_lbp, dv = syst,
wid = subject_id,
within = c(timef, conditionf) )
get_anova_table(a1)
dput(df_lbp))
You observation with
subject_id
161 has several entries (varyingtimef
values):output:
... without these duplicates,
anova_test
runs OK:output:
edit as r2evans pointed out, you can keep
distinct
combinations of variables (instead of checking first and singling them out) like so (note that the first/topmost observation of any duplicate is kept):