Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R是Boot中未使用的参数,尽管存在?_R_Statistics Bootstrap - Fatal编程技术网

R是Boot中未使用的参数,尽管存在?

R是Boot中未使用的参数,尽管存在?,r,statistics-bootstrap,R,Statistics Bootstrap,我试图用相同的数据比较不同的模型。我运行的是R版本3.6.1,它似乎有自己的问题——特别是在下载软件包方面。这就是我想做的: bs <- function(formula=model1, data=my_data, R=1000) { d <- my_data[R=1000,] fit <- lm(formula=model1, data=my_data) return(coef(fit)) } results <- boot(data=my_data

我试图用相同的数据比较不同的模型。我运行的是R版本3.6.1,它似乎有自己的问题——特别是在下载软件包方面。这就是我想做的:

bs <- function(formula=model1, data=my_data, R=1000) 
{
 d <- my_data[R=1000,] 
  fit <- lm(formula=model1, data=my_data)
  return(coef(fit)) 
} 

results <- boot(data=my_data, statistic=bs, R=1000, formula=model1)

plot(results, index=1) # intercept 
plot(results, index=2) # wt 
plot(results, index=3) # disp 


boot.ci(results, type="bca", index=1) # intercept 
boot.ci(results, type="bca", index=2) # wt 
boot.ci(results, type="bca", index=3) # disp
如果从最后一行中删除R变量,则会出现以下错误:

Error in `[.data.table`(my_data, R = 1000, ) : unused argument (R = 1000)
Error in index.array(n, R, sim, strata, m, L, weights) : argument "R" is missing, with no default
我既不是统计学家,也不是程序员,只是一个困惑的生物学家,希望了解我在看什么——如果没有默认值,这个论点怎么会被闲置和丢失?我做错了什么


谢谢你的帮助

R是引导数,仅在调用boot时使用。函数bs不需要知道它在哪个引导上。在原始函数中,不太清楚是使用函数变量还是从全局调用

我在下面展示了bs应该如何编写,它应该适合您:

bs <- function(my_data,inds,formula=model1) 
{
 d <- my_data[inds,] 
  fit <- lm(formula=formula, data=d)
  return(coef(fit)) 
} 

results <- boot(data=mtcars, statistic=bs, R=10, formula=as.formula(mpg~.))
> results

ORDINARY NONPARAMETRIC BOOTSTRAP


Call:
boot(data = mtcars, statistic = bs, R = 10, formula = as.formula(mpg ~ 
    .))


Bootstrap Statistics :
        original        bias    std. error
t1*  12.30337416 -19.268069883 37.18417307
t2*  -0.11144048   0.311423945  1.27584819
t3*   0.01333524   0.012433796  0.01697679
t4*  -0.02148212  -0.006148059  0.02917990
t5*   0.78711097   0.778926590  3.57621690
t6*  -3.71530393  -1.632978225  3.32856394
t7*   0.82104075   0.963507105  1.53123787
t8*   0.31776281  -1.230288420  3.27278936
t9*   2.52022689   0.157071809  3.31151260
t10*  0.65541302   0.084539332  1.83846998
t11* -0.19941925   0.131494452  1.10284335

错误似乎来自d我在模仿我发现的东西。。。即使我只是运行了行结果,但这是在调用bs函数,其中有一行错误的代码。那句话毫无意义。我不认为你可以调用bs函数而不出错。