admin管理员组文章数量:1133929
I have to bootstrap a logistic regression model on the 'birthwt' dataset from MASS. However, when I run my code for the bootstrap, I get the following error
Error in eval(predvars, data, env) : object 'low' not found
I don't understand why I get this error, since 'low' is among the variable names in the model.
Why do I get this error? Any feedback is appreciated!
data(birthwt, package = "MASS")
data <- as.data.frame(birthwt)
# converting predictor variable into factor
data$low <- as.factor(data$low)
pmod <- glm(low ~ . - bwt - age - ftv, data = data, family = binomial)
boot_results <- car::Boot(pmod, R = 100)
I have to bootstrap a logistic regression model on the 'birthwt' dataset from MASS. However, when I run my code for the bootstrap, I get the following error
Error in eval(predvars, data, env) : object 'low' not found
I don't understand why I get this error, since 'low' is among the variable names in the model.
Why do I get this error? Any feedback is appreciated!
data(birthwt, package = "MASS")
data <- as.data.frame(birthwt)
# converting predictor variable into factor
data$low <- as.factor(data$low)
pmod <- glm(low ~ . - bwt - age - ftv, data = data, family = binomial)
boot_results <- car::Boot(pmod, R = 100)
Share
Improve this question
edited Jan 7 at 15:00
jpsmith
16.9k6 gold badges20 silver badges44 bronze badges
asked Jan 7 at 11:45
enfieldenfield
1213 bronze badges
1
|
1 Answer
Reset to default 0I've only ever used the boot::boot
function for bootstrapping, but looking at the help page for car::Boot
, it states:
"This function provides a simple front-end to the
boot
function in theboot
package that is tailored to bootstrapping based on regression models..."
So the long way around using boot::boot
would be to first define your logistic regression for bootstrapping and then bootstrap on that function:
boot_logreg <- function(my_data, indices) {
coef(glm(low ~ . - bwt - age - ftv, data = my_data[indices, ], family = binomial))
}
set.seed(123) # Seed for reproducibility, not required
boot_results <- boot::boot(data, boot_logreg, R = 1000)
# ORDINARY NONPARAMETRIC BOOTSTRAP
#
# Call:
# boot::boot(data = data, statistic = boot_logreg, R = 1000)
# Bootstrap Statistics :
# original bias std. error
# t1* -0.80364418 0.070440226 1.238398503
# t2* -0.01294747 -0.001190249 0.008038214
# t3* 0.46913122 0.012766086 0.228166001
# t4* 0.94817154 0.021266241 0.426519541
# t5* 0.49145146 0.050717609 0.450790533
# t6* 1.83315979 0.198129583 1.311930532
# t7* 0.74793544 0.027657403 0.559801377
本文标签: rPredictor variable not found for bootstrappingStack Overflow
版权声明:本文标题:r - Predictor variable not found for bootstrapping - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736789350a1953018.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
data
since that is a commonly used function name as isdf
. – IRTFM Commented Jan 7 at 11:53