0

I kept getting a problem for the following code; "weights=weight" was shown as an unused argument. How should I solve the problem?

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]

Also, is there a way to perform the whole process shown above 30, 60, or 100 times and generate time (or count), x_0, x_1, and result for each time? Any suggestion would be great. Thanks.

4

2 回答 2

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])
}))
于 2013-05-04T17:30:03.933 回答
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 
于 2013-05-04T17:35:02.977 回答