plyr - Shapiro.test in R giving "all x values are identical"? -
i've been working on getting table of shapiro-wilkes normality hypothesis test p-values on data frame of mine. here data frame (named "mdf1") comma-delimeted csv.
shapiro-wilkes testing in r requires sample size greater 3. in order subset data frame (which contains 2 pertinent factors, "variable", , "site"), used following code:
z <- as.data.frame(data.table(mdf1)[, list(freq=.n, value=value), by=list(site,variable)][freq > 3])
this resulted in data frame "z" contained values belonged "site"*"variable" combination of n greater 3. then, try pass z ddply
function obtain table of shapiro-wilkes p-values:
norm2 <- ddply(z, .(site, variable), summarize, n=length(value), sw=shapiro.test(value)[2])
the result of command is:
error in shapiro.test(val) : 'x' values identical
how can be? thoughts?
your value
variable string here. ??shapiro.test(x)
says x
numeric vector of data values...missing values allowed, number of non-missing values must between 3 , 5000. first 2 lines of code same answer earlier question.
so can use following code (tested):
mydata$inter<-with(mydata,interaction(site,variable)) mydata1<-mydata[mydata$inter %in% names(which(table(mydata$inter) > 3)), ] library(plyr) ddply(mydata1, .(inter), summarize, n=length(value),sw=shapiro.test(as.numeric(value))[2]) inter n sw 1 41332.effluent (n) 18 0.6294289 2 41369.effluent (n) 18 0.6294289 3 41385.effluent (n) 10 0.969692 4 41394.effluent (n) 12 0.5272433 5 41402.effluent (n) 12 0.4404443 6 41436.effluent (n) 14 0.6283259 7 41439.effluent (n) 6 0.484449 8 41450.effluent (n) 5 0.5012284 9 41452.effluent (n) 14 0.5331113 10 41457.effluent (n) 12 0.5272433 11 41458.effluent (n) 12 0.5272433 12 43635.effluent (n) 7 0.7437188 13 41332.effluent (s) 13 0.5331956 14 41369.effluent (s) 7 0.4869206 15 41379.effluent (s) 6 0.484449 16 41385.effluent (s) 7 0.4869206 17 41394.effluent (s) 12 0.5272433 18 41436.effluent (s) 14 0.6283259 19 41332.influent (n) 18 0.6294289 20 41369.influent (n) 18 0.6294289 21 41385.influent (n) 10 0.969692 22 41394.influent (n) 12 0.5272433 23 41402.influent (n) 12 0.4404443 24 41436.influent (n) 14 0.6283259 25 41439.influent (n) 6 0.484449 26 41450.influent (n) 5 0.5012284 27 41452.influent (n) 14 0.5331113 28 41457.influent (n) 12 0.5272433 29 41458.influent (n) 12 0.5272433 30 43635.influent (n) 7 0.7437188 31 41332.influent (s) 13 0.5331956 32 41369.influent (s) 7 0.4869206 33 41379.influent (s) 6 0.484449 34 41385.influent (s) 7 0.4869206 35 41394.influent (s) 12 0.5272433 36 41402.influent (s) 12 0.4404443 37 41436.influent (s) 14 0.6283259 38 41452.influent (s) 7 0.6578695 39 41457.influent (s) 7 0.6578695 40 41458.influent (s) 8 0.7159932 41 41332.plot 6 0.484449 42 41369.plot 6 0.484449 43 41379.plot 6 0.484449 44 41385.plot 7 0.4869206 45 41394.plot 12 0.5272433 46 41402.plot 12 0.4404443 47 41452.plot 7 0.6578695 48 41457.plot 7 0.6578695 49 41458.plot 8 0.7159932
Comments
Post a Comment