我们在标记为release的列中有数据,其中有两个选项,release和non release。我们正在尝试进行置换测试,但是结果返回为Na。
dat$frelease <- factor(recode(dat$release, `nonrelease`="nonrelease", `release`="release"))
dat$release <- as.factor (dat$release)
dat$isrelease<- as.numeric (dat$release)
dat
dat$frelease <- factor(recode(dat$release, `1`="nonrelease", `2`="release"))
(obsdiff <- mean(dat[dat$frelease == "Nonrelease", "damage"]) - mean(dat[dat$frelease == "Nonrelease", "damage"]))
nreps <- 50
rdiffs <- numeric(nreps)
for(i in 1:nreps){
rand.damage <- sample(dat$damage, size = length(dat$damage), replace = FALSE)
rdiffs[i] <- mean(rand.damage[dat$frelease == "release"]) - mean(rand.damage[dat$frelease == "nonrelease"])
} 均值(rdiffs> = obsdiff
This is the result when being but into R
> mean(rdiffs >= obsdiff)
[1] NA
> nreps <- 50
> rdiffs <- numeric(nreps)
> (obsdiff <- mean(dat[dat$frelease == "Nonrelease", "damage"]) - mean(dat[dat$frelease == "Nonrelease", "damage"]))
[1] NaN
> nreps <- 50
> rdiffs <- numeric(nreps)
> for(i in 1:nreps){
+ rand.damage <- sample(dat$damage, size = length(dat$damage), replace = FALSE)
+ rdiffs[i] <- mean(rand.damage[dat$frelease == "release"]) - mean(rand.damage[dat$frelease == "nonrelease"])
+ }
> mean(rdiffs >= obsdiff)
[1] NA