ezPerm: replacement dimension error for p-value

85 views
Skip to first unread message

Peter

unread,
Jan 3, 2017, 10:08:15 AM1/3/17
to ez4r
Dear all,

I have what should be a rather easy task for ezPerm: a pure within-subjects design with a single independent variable, at least at this stage of the analysis. ezPerm fails towards the end, however, with the following error:

Error in `$<-.data.frame`(`*tmp*`, "p", value = c(0.42, 0.85)) : 
  replacement has 2 rows, data has 1

The specific numbers, of course, change. I created a reproducible script, below this email message. The line I use to execute the analysis is like this:

ezPerm(data=testdata,dv=rating,wid=subj,within=int,perms=100)

To get an idea of how the data are like:

head(testdata)
  subj int rating
1   S1  T4      8
2   S1  T2     17
3   S1  T1     65
4   S1  T4     22
5   S1  T1      7
6   S1  T1     22

I looked into the code for ezPerm, and I suspect the problem has something to do with the lines in 133-136 of ezPerm.R:
from_terms = terms(eval(parse(text=aov_formula)))
term_labels = attr(from_terms,'term.labels')
term_labels = term_labels[grep('(Intercept)',term_labels,fixed=T,invert=T)]
term_labels = term_labels[grep('Error(',term_labels,fixed=T,invert=T)]

where it seems that term_labels get substituted rather than extended. I don't get the logic of this code, actually. The code subsequently fails in the lines
perm_test = data.frame(Effect=term_labels)
perm_test$p = rowMeans(sim>=obs)
because the data frame only has a single line while rowMeans has a length of 2. I'm not sure how to fix it though. Is this a known issue - or maybe I did got something wrong?

Code to reproduce is below.

Kind regards,

Peter


subj<-unlist(strsplit("S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S1 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S2 S3 S3 S3 S3 S3 S3 S3 S3 S3 S3 S3 S3 S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 S10 S10 S10 S10 S10 S10 S10 S10 S10 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S11 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S12 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S13 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S14 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S15 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S16 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S17 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S18 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S19 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20 S20"," "))
int<-unlist(strsplit("4 2 1 4 1 1 2 1 3 1 4 4 3 3 1 4 4 1 1 4 3 2 2 1 3 2 2 3 3 2 2 3 1 1 3 2 1 2 1 4 2 2 2 4 1 4 3 2 4 4 3 2 1 3 3 1 2 2 2 2 1 3 1 2 3 4 1 3 4 3 3 4 1 2 2 4 1 2 4 1 1 3 4 3 4 1 2 1 4 4 2 1 1 3 1 1 1 3 2 1 2 3 4 4 1 1 1 1 3 4 2 2 1 1 4 4 3 1 2 3 2 4 4 1 2 1 1 3 2 1 4 1 2 2 1 3 3 2 3 4 3 2 1 1 2 1 3 1 4 1 3 1 3 1 1 3 2 1 1 2 3 2 4 2 2 2 1 4 4 1 2 4 2 1 2 4 2 1 3 1 3 1 4 1 2 1 1 3 4 3 3 2 1 3 3 1 4 1 1 1 3 2 3 1 2 1 1 2 2 3 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3 2 1 3 2 2 4 1 2 3 1 1 4 3 1 2 1 4 3 1 2 4 3 2 2 1 3 3 1 2 3 2 1 4 4 1 4 2 1 1 4 4 3 4 4 1 4 3 2 3 2 2 2 1 4 2 1 2 3 3 3 3 4 1 2 2 1 2 1 2 1 3 1 3 2 1 2 1 3 3 1 4 3 4 4 2 1 2 1 1 1 3 1 2 1 2 3 2 3 3 2 4 2 3 3 3 2 3 2 4 1 1 3 4 1 3 1 1 1 4 2 1 1 1 4 3 3 2 4 2 1 3 4 3 2 1 2 1 2 1 3 2 1 2 1 3 3 2 4 4 2 1 3 2 2 2 2 2 4 1 2 4 4 3 3 2 1 2 3 3 2 3 4 2 2 3 1 1 3 2 2 4 3 1 1 3 1 1 3 1 2 4 2 1 2 4 2 2 1 1 3 1 1 2 2 4 2 1 2 3 3 2 1 2 2 4 3 4 2 1 2 2 4 4 1 2 1 2 1 2 3 2 2 2 2 3 2 3 4 3 3 3 2 1 2 3 1 1 3 2 1 3 3 3 2 2 1 1 1 2 2 1 4",split=" "))
rating<-as.numeric(unlist(strsplit("8 17 65 22 7 22 17 19 0 38 6 15 9 0 41 5 2 5 10 9 5 10 3 25 15 6 0 19 9 27 48 9 10 18 3 20 7 8 10 7 1 30 7 6 9 6 9 2 0 10 3 24 35 15 50 76 30 98 92 5 94 8 52 50 73 95 80 97 50 100 1 97 92 13 62 3 50 2 23 55 77 75 89 50 94 83 65 80 56 11 89 86 93 100 70 31 11 30 9 53 69 10 45 9 91 40 65 10 10 25 51 75 40 50 91 50 60 70 41 91 30 25 20 90 50 30 20 24 60 20 20 40 67 24 24 75 50 25 55 75 30 20 30 96 50 29 50 0 14 77 0 86 100 0 19 86 91 42 87 79 84 67 44 67 25 68 36 68 15 92 95 52 25 18 26 92 22 20 81 83 80 51 24 23 92 96 88 98 81 95 18 89 88 0 0 9 50 0 55 0 81 10 10 52 0 97 91 15 47 31 11 92 27 27 14 90 8 29 61 1 3 100 95 95 89 100 79 91 50 96 20 27 9 5 4 51 52 94 51 41 0 14 91 96 72 70 58 59 47 70 73 66 61 57 80 50 62 68 39 68 98 68 73 58 91 48 79 53 72 67 49 44 53 34 46 57 53 53 6 70 12 26 31 38 9 9 18 13 52 80 9 76 41 41 31 83 62 19 6 41 54 32 64 54 22 54 48 50 78 70 51 28 68 31 25 79 23 22 16 35 26 17 14 50 50 97 100 100 80 93 79 91 92 91 82 100 100 45 61 82 98 85 100 95 89 85 100 86 95 79 91 15 53 47 1 65 82 87 50 79 89 11 48 49 87 16 28 17 0 0 0 0 0 0 53 52 0 0 14 50 0 0 0 0 23 83 0 72 100 100 0 39 64 6 0 30 0 65 27 71 50 0 0 57 45 94 4 26 73 49 73 50 100 100 72 100 72 31 68 0 67 87 100 100 14 100 75 0 20 95 0 90 0 86 100 100 98 19 27 100 95 5 0 0 0 91 91 97 0 87 80 100 100 3 32 50 55 84 70 0 25 27 61 36 52 0 15 14 0 19 25 42 5 0 0 0 48 0 0 37 0 0 0 0 0 0 0 44 94 0 72 33 0 0 0 0 0 0 0 0 0 0 7 0 6 0 0 0 0 0 7 42 18 13 6 16 15 80 55 64 59 61 76 50 75 63 15 89 54 24 11 41 11 65 39 17 96 80 78 78 68 35 52 98 19 59 32 71 13 47 47 55 82 75 54 70 34 61 84 30 10 90 51 63 49 93 30 65 10 60 70 86 1 65 56 29 10 72 15 65 40 25 14 11 15 35 95 15 14 34 46 9 25 21 0 33 32 58 21 3 25 8 55 30 56 86 30 87 32 53 67 55 100 25 46 55 36 59 73 57 70 35 0 100 100 100 55 0 100 0 0 82 100 0 51 0 0 78 100 0 0 0 100 0 31 0 100 100 71 0 100 80 0 100 0 100 0 50 69 100 92 100 30 0 58 0 100 100 71 85 0 0 89 100 43 42 64 40 15 70 19 24 17 33 71 52 47 41 15 64 34 72 61 39 36 21 44 22 39 47 37 5 27 80 65 63 67 29 36 33 50 55 55 55 68 64 21 55 55 50 75 66 50 50 51 50 49 76 9 76 9 50 71 29 19 79 22 78 78 96 20 80 77 81 13 50 76 50 78 84 78 18 81 81 24 89 4 0 83 82 84 100 100 77 50 50 50 50 49 74 92 20 78 75 84 100 100 59 84 100 100 67 53 100 85 100 25 38 62 81 39 47 86 91 71 55 0 0 5 57 100 41 19 31 44 62 100 56 100 26 70 55 100 50 39 0 19 0 0 0 100 83 100 61 100 30 31 51 63 54 26 60 33 62 31 31 47 0 0 46 71 25 25 84 30 0 2 72 30 100 0 87 100 39 100 35 0 0 0 0 0 9 0 0 0 0 0 0 41 0 34 19 79 0 0 94 20 0 0 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 50 75 100 25 75 25 100 50 20 20 40 75 4 60 55 25 10 50 40 100 25 50 50 65 30 10 15 15 50 15 50 10 25 65 25 10 50 5 50 10 60 25 0 55 20 10 19 77 81 66 85 6 7 70 36 5 7 78 14 11 22 16 45 3 77 91 76 90 76 80 31 38 17 14 93 84 80 61 56 34 81 76 97 56 18",split=" ")))

testdata<-data.frame(cbind(subj=subj,int=paste0('T',int),rating=rating),stringsAsFactors=FALSE)
testdata$rating<-as.numeric(testdata$rating)

ezPerm(data=testdata,dv=rating,wid=subj,within=int,perms=100)

Mike Lawrence

unread,
Jan 3, 2017, 11:39:55 AM1/3/17
to ez...@googlegroups.com
Darn, looks like aov() changed its output format and I didn't notice. Happily, it's an easy solution, just replace the line (in ezPerm):

perm_test$p = rowMeans(sim>=obs)

with:

perm_test$p = rowMeans(sim>=obs)[2:length(obs)]


I'll double check that this generalizes then push an update.



--
You received this message because you are subscribed to the Google Groups "ez4r" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ez4r+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mike Lawrence

unread,
Jan 3, 2017, 2:29:35 PM1/3/17
to ez...@googlegroups.com
Oops! Turns out nothing's broken after all. You need to collapse the observations to a mean per cell of the design before using ezPerm. The other ez functions do this automatically, and I can't remember why I didn't do the same for ezPerm. Here's what you do:

library(plyr)
testdata_means = ddply(
.data = testdata
, .variables = .( subj , int )
, .fun = function(x){
to_return = data.frame(
rating = mean(rating)
)
return(to_return)
}
)
ezPerm(
data=testdata_means
,dv=rating
,wid=subj
,within=int
,perms=100
)



--
Mike Lawrence
Graduate Student
Department of Psychology & Neuroscience
Dalhousie University

~ Certainty is (possibly) folly ~

Peter

unread,
Jan 6, 2017, 7:55:00 AM1/6/17
to ez4r
Dear Mike,

Thanks for the solution. There is probably one little error in it, though. I'm not used to plyr but I think the line 'rating = mean(rating)' should be 'rating = mean(x$rating)'. Otherwise all cell means in testdata_means equal the global average of rating, which has been declared in a vector as input to the testdata data frame.

With that correction, it seems to have worked! (Alás, with a disappointing p-value.)

Thanks for the ez package, by the way. It has saved lots of time and headache!

Kind regards,

Peter
To unsubscribe from this group and stop receiving emails from it, send an email to ez4r+uns...@googlegroups.com.

Mike Lawrence

unread,
Jan 6, 2017, 9:05:17 AM1/6/17
to ez...@googlegroups.com
Oops! Yes, your correction is correct.
Reply all
Reply to author
Forward
0 new messages