代码在R中运行正常,但在R-Fiddle中失败,为什么?
我试图运行一段R代码,但没有成功。代码在R中运行非常平稳,但根本不运行 任何建议都将不胜感激代码在R中运行正常,但在R-Fiddle中失败,为什么?,r,R,我试图运行一段R代码,但没有成功。代码在R中运行非常平稳,但根本不运行 任何建议都将不胜感激 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*q
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))
看起来R小提琴上使用了较旧版本的R
无论如何,如果我用旧的方式重做你的脚本,它会工作的,请参阅。唯一的更改是将作业从
=
替换为除了格式之外,您还更改了什么?(我肯定你做了些什么,只是不容易看到)@BenBolker将“=”替换为“@BenBolker如果我删除了一些R可以直接解析的不可见符号,我不会感到惊讶,但不知何故,通过R-Fiddle上的这个web界面,它变成了一些不同的、不可解析的东西
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)