【问题标题】:Having weights shown as an unused argument in logistf R function在logistf R函数中将权重显示为未使用的参数
【发布时间】:2013-05-04 17:12:18
【问题描述】:

我一直遇到以下代码的问题; "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,以及每次的结果?任何建议都会很棒。谢谢。

【问题讨论】:

    标签: r statistics linear-regression weighting logistf


    【解决方案1】:

    我成功地运行了以下代码(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])
    }))
    

    【讨论】:

    • 我的R版本是2.9.2;我想我应该重新安装它。谢谢。
    • 如果我想在代码中添加另一个logistf模型进行比较,我应该怎么做? (然后我将在列表函数中有两个不同的“res”参数。)
    • 您可以根据需要在列表中添加任意数量: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]) 每个将对应于结果数组中的一列。
    • 再次感谢。我认为每个添加的“res”都与“res
    【解决方案2】:

    我的工作区中没有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 
    

    【讨论】:

      猜你喜欢
      • 2015-06-22
      • 1970-01-01
      • 1970-01-01
      • 2020-03-14
      • 2015-10-01
      • 1970-01-01
      • 2020-07-08
      • 1970-01-01
      相关资源
      最近更新 更多