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.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140

2 Answers2

0

I managed to run the following code without problems (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])
}))
dratewka
  • 2,104
  • 14
  • 15
  • My R version is 2.9.2; I think I should re-install it. Thanks. – David Smith May 04 '13 at 17:34
  • If I would like to add another logistf model into the code for comparison purpose, what should I do? (I would then have two different "res" arguments in the list function.) – David Smith May 04 '13 at 18:05
  • You can add as many as you need in the list: `list(count=i,x_0=x_0,x_1=x_1, res= logistf(y ~ x, weights=weight)$coef[2], res_2= logistf(y ~ x, weights=weight)$coef[2], res_3= logistf(y ~ x, weights=weight)$coef[2])` each one will correspond to a column in the resulting array. – dratewka May 04 '13 at 19:28
  • Thanks again. I thought each added "res" had something to do with "res<-t(sapp...". – David Smith May 04 '13 at 20:15
0

I don't have a logistf in my workspace but this works using 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 
IRTFM
  • 258,963
  • 21
  • 364
  • 487