gpt4 book ai didi

r - 逻辑回归 NA 误差

转载 作者:行者123 更新时间:2023-12-01 19:11:42 28 4
gpt4 key购买 nike

我正在尝试运行逻辑回归并不断收到“NA”错误。问题是它说有 NA 的列没有 NA,全是 0 或 1。我的代码如下:

#V1=race, V2=momcounts of breast cancer, V3=prstatus, V4=erstatus, V5=her2status, V6=triplenegative,      V7=menopause, V8=agemenopause, V9=mentype, V10=mensurg, V11=bmi, V12=eversmok, V13=age, V14=breastfeed, V15=breastfeedmonths, V16=pregnum, V17=birthcount, V18=agefirstpreg, 

regressiondata <- as.data.frame(cbind((data[,'race']),(data[,'mom_countsofbreastcancer']),(data[,'prstatus']),(data[,'erstatus']),(data[,'her2status']),(data[,'triplenegative']),(data[,'menopause']),(data[,'agemenopause']),(data[,'mentype']),(data[,'mensurg']),(data[,'bmi']),(data[,'eversmok']),(data[,'age']),(data[,'breastfeed']),(data[,'breastfeedmonths']),(data[,'pregnum']),(data[,'birthcount']),(data[,'agefirstpreg'])), stringsAsFactors=F)

dataAA=regressiondata[regressiondata$V1==2,] #AA
glm(V6 ~ V2+V7+V8+V10+V11+V12+V13+V14+V15+V16+V17+V18, family=binomial, data=dataAA)

我也尝试过 lm() 但仍然出现错误:

lm(formula=V6~V2+V7+V8+V10, data=dataAA)

错误:

Coefficients:
(Intercept) V2 V7 V8 V10 V11
1326.433 -17.262 NA -31.174 -34.108 0.525
V12 V13 V14 V15 V16 V17
2.281 11.060 NA 1.154 -50.258 NA
V18
-12.277

Degrees of Freedom: 12 Total (i.e. Null); 3 Residual
(1474 observations deleted due to missingness)
Null Deviance: 16.05
Residual Deviance: 3.49e-10 AIC: 20
Warning message:
glm.fit: fitted probabilities numerically 0 or 1 occurred

最佳答案

看起来 V17 是模型中其他变量的线性组合,因此 R 自动排除它。您的逻辑回归输出看起来没有任何问题。

(顺便说一句:我非常关心逻辑回归中发生的列表删除,看起来在删除 1474 个缺失数据的观察结果后,您还剩下 15 个观察结果......还是我错了?)

关于r - 逻辑回归 NA 误差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16137211/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com