我一直遇到以下代码的问题; “weights = weight”显示为未使用的参数。我该如何解决这个问题?
x_0 <- rbinom(1,100, 0.01)
x_1 <- rbinom(1,100, 0.1)
x <- c(0,0,1,1)
y <- c(0,1,0,1)
weight <- c(100-x_0, x_0, 100-x_1, x_1)
result <- logistf(y ~ x, weights=weight)$coef[2]
此外,有没有办法执行上面显示的30,60或100次整个过程并生成时间(或计数), x_0 ,每次都有x_1 和结果?任何建议都会很棒。感谢。
答案 0 :(得分:0)
我设法运行以下代码没有问题(R v 3.0.0 logistf v 1.10):
arr <- t(sapply(1:30, function(i){
x_0 <- rbinom(1,100, 0.01)
x_1 <- rbinom(1,100, 0.1)
x <- c(0,0,1,1)
y <- c(0,1,0,1)
weight <- c(100-x_0, x_0, 100-x_1, x_1)
list(count=i,x_0=x_0,x_1=x_1, res= logistf(y ~ x, weights=weight)$coef[2])
}))
答案 1 :(得分:0)
我的工作区中没有logistf
,但这可以使用glm(..., family="binomial")
rtest <- replicate(10,
{x_0 <- rbinom(1,100, 0.01)
x_1 <- rbinom(1,100, 0.1)
x <- c(0,0,1,1)
y <- c(0,1,0,1)
weight <- c(100-x_0, x_0, 100-x_1, x_1)
result <- glm(y ~ x, weights=weight, family="binomial")$coef[2]} )
rtest
#------------
x x x x x x x x
1.694596 2.281485 1.843585 18.220418 18.410200 18.113934 18.724469 1.162464
x x
1.650681 2.504379