2017-09-10 41 views
2

我试图运行一段R代码HERE on R-Fiddle,但没有成功。代码在R中运行非常顺利,但完全不运行HERE on R-Fiddle代码在R中运行正常但在R-Fiddle中失败,为什么?

任何建议表示赞赏。

alt.hyp = function(N, d){ 

options(warn = -1) ; d = sort(d) 
df = N - 1 ; d.SE = 1/sqrt(N) ; ncp.min = min(d)*sqrt(N) ; ncp.max = max(d)*sqrt(N) 
min.d = d.SE*qt(1e-5, df, ncp.min) ; max.d = d.SE*qt(0.99999, df, ncp.max) 

for(i in 1:length(d)){  
    H = curve(dt(d[i]*sqrt(N), df, x*sqrt(N)), min.d, max.d, n = 1e3, xlab = "Effect Size", 
     ylab = NA, ty = "n", add = i!= 1, bty = "n", yaxt = "n", font.lab = 2) 

    polygon(H, col = adjustcolor(i, .7), border = NA) 
    text(d[i], max(H$y), bquote(bolditalic(H[.(i-1)])), pos = 3, xpd = NA) 
    axis(1, at = d[i], col = i, col.axis = i, font = 2) 
    segments(d[i], 0, d[i], max(H$y), lty = 3) 
    } 
} 
# Example of use: 
alt.hyp(N = 30, d = seq(0, 2, .5)) 

回答

1

看起来像旧版本[R是在R小提琴使用。

无论如何,如果我重做您的脚本在旧式,它的工作原理,请参阅here。唯一的变化是将作业从=更换为<-以及每行单条语句。

代码

alt.hyp <- function(N, d) { 
    options(warn = -1) 
    d <- sort(d) 
    df <- N - 1 
    d.SE <- 1/sqrt(N) 
    ncp.min <- min(d)*sqrt(N) 
    ncp.max <- max(d)*sqrt(N) 
    min.d <- d.SE*qt(1e-5, df, ncp.min) 
    max.d <- d.SE*qt(0.99999, df, ncp.max) 

    for(i in 1:length(d)){  
     H <- curve(dt(d[i]*sqrt(N), df, x*sqrt(N)), min.d, max.d, n = 1e3, xlab = "Effect Size", ylab = NA, ty = "n", add = i!= 1, bty = "n", yaxt = "n", font.lab = 2) 
     polygon(H, col = adjustcolor(i, .7), border = NA) 
     text(d[i], max(H$y), bquote(bolditalic(H[.(i-1)])), pos = 3, xpd = NA) 
     axis(1, at = d[i], col = i, col.axis = i, font = 2) 
     segments(d[i], 0, d[i], max(H$y), lty = 3) 
    }  

    N 
} 

q <- alt.hyp(N = 30, d = seq(0, 2, .5)) 
print(q) 

而且在R小提琴

enter image description here

+0

你是怎么改变比其他格式的输出? (我相信你做了一件事,这只是不容易看到) –

+0

@BenBolker用“< - ”替换“=”,每行单个语句(不再有“;”) - 就是这样 –

+0

@BenBolker我不会如果我删除了一些看不见的符号,** R **可以直接解析,但通过这个R-Fiddle网页界面变成了不同的东西并且不可解析 –

相关问题