如题,怎么把三组数据,格式是(x,y),x是正确率,y是反应时,bootstrap抽2000次,然后把结果画成散点图,得到如下的图。
目前已有的语句如下,求问怎么改~~~
setwd("E:/EXP/example"); # set the working directory
load("students.RData"); # load the data
#############2. Test the hypothesis using the Barron and Kenney method with Bootsrapping.
#############Print out the histogram with normal distribution curve as well as the confidence intervals and mean indirect effect.
original = 1:nrow(students) # Original sample: All cases in our data
N = nrow(students) # sample size
output.boot = data.frame(ab = rep(NA, 2000)) # make a NA array to contain all output
for(i in 1:2000) { # repeat 2000 times
boot.sample = students[sample(original, N, replace = TRUE), ] # Draw a sample of size N with replacement
boot.a = lm(gb.1 ~ neuro, data = boot.sample) # Estimate models again
boot.b_cprime = lm(ls.1 ~ neuro + gb.1, data = boot.sample)
ab.boot = coef(boot.a)[2] * coef(boot.b_cprime)[3] # Calculate indirect effect
output.boot$ab
= ab.boot
}
plot(output.boot$a,output.boot$b, breaks = 50)
curve(dnorm(x, mean(output.boot$ab), sd(output.boot$ab)), add = T, lwd = 2) # add normal distribution curve
mean(output.boot$ab) # mean as the estimate for the indirect effect
quantile(output.boot$ab, probs = c(.025, .975)) #the confidence interval