全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2744 0
2015-04-23
如题,怎么把三组数据,格式是(x,y),x是正确率,y是反应时,bootstrap抽2000次,然后把结果画成散点图,得到如下的图。 bootstrap散点图
目前已有的语句如下,求问怎么改~~~

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



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群