r - 数据有 101 个值 为什么结果有 303 个值?
问题描述
这里的数据是“销售”数据,包含两列价格和销售额以及 16 行,例如,
price sales
49 81996
46 91735
50 70830
45 101192
51 78319
47 105369
47 68564
46 95523
49 88834
46 89511
45 107836
52 81410
50 67817
54 59207
50 83310
46 71431
在下面的代码中,使用“dim(my.boot.price)”可以显示输入数据中有 101 个值,但结果显示我们有 303 行。为什么?请更正随附的脚本。
#=== bootstrapping prediction price range
library(boot)
# bootstrap function
my.boot <- function(formula, data, indices, price) {
d <- data[indices,]
fit <- lm(formula, data=d)
my.new.data<-data.frame(price)
pred_interval <- predict(fit, newdata=my.new.data, interval="prediction",
level = 0.95)
colnames(pred_interval)[2:3]<-c("pred.lwr","pred.upr")
# return the prediction
return(pred_interval)
}
###############################################
# run the bootstrap
# determine the single value to bootstrap
my.boot.price=data.frame(price=seq(45,55,.1))
dim(my.boot.price)
results <- boot(data=sales, statistic=my.boot,
R=2000, formula=sales~price, price=my.boot.price)
# view results
results
解决方案
推荐阅读
- python - 如何使用 python (google colab) 将人员分配到房间?
- bash - Oozie Shell Action 无法运行 Docker 容器
- java - Jolokia - Origin null 不允许调用此代理
- selenium - 使用 sendkeys,Selenium JAVA 刷新不起作用
- excel - VBA .shapes.pastespecial 间歇性失败
- amazon-web-services - 如何从工作和家庭连接相同的 AWS EC2 实例?
- python - 在 Python 中使用 Pivot_Table 的问题:有什么方法可以保持数据的原始顺序并且没有多重索引?
- android - READ_EXTERNAL_STORAGE 无法解析或不是字段
- python - AttributeError:类型对象“x”没有属性“y”
- flask - 不同破折号会话的唯一会话 ID