试图通过AIC方法使用bestglm函数来提出逻辑回归模型。以下是我运行过的数据集的摘要:数据集摘要
以下是我运行的行:
best1 <- bestglm(trainset, IC="AIC", family=binomial)
以下是我收到的错误消息:
Error in levels(x)[x] : only 0's may be mixed with negative subscripts
In addition: Warning messages:
1: In model.response(mf, "numeric") :
using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
dput(testset)structure(list(EyeContact = structure(c(2L,1L,2L,1L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,1L,2L,2L, 2L,1L,2L,1L,1L,2L,1L,1L,2L,1L,2L,1L,2L,1L,2L,2L,2L,2L,2L,2L,2L,1L,2L,1L,1L, 2L,2L,2L,1L,1L,2L,1L,2L,2L,1L,1L,1L,2L,2L,2L,2L,2L,2L,2L,1L,1L,2L,1L,2L,2L, 2L,2L,2L,1L,2L,1L,1L,2L,2L,2L,2L,2L,2L,1L,2L,2L,1L,2L,1L,2L,1L,2L,2L,2L,1L, 2L,2L,2L,1L,2L,2L,2L,2L,1L,2L),.Label = c(“ N”,“ Y”),class =“ factor”),Post.Processing =结构(c( 2L,2L,2L,1L,1L,1L,2L,2L,2L,1L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,1L, 2L,2L,2L,1L,2L,2L,2L,2L,2L,2L,2L,2L,1L,1L,2L,2L,2L,1L,2L,2L,2L,2L,1L,2L,2L, 2L,2L,1L,1L,1L,2L,1L,2L,1L,2L,1L,2L,1L,1L,2L,1L,2L,1L,2L,2L,2L,1L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,1L,2L,2L,1L,2L,2L,2L,1L,2L,2L,2L,2L, 2L,2L,2L,2L,2L)、. Label = c(“ N”,“ Y”),class =“ factor”),HairColour =结构(c(3L,2L,2L,2L,2L,2L, 4L,2L,1L,3L,1L,2L,1L,2L,2L,1L,1L,2L,1L,2L,1L,1L,1L,1L,1L,1L,2L,1L,1L,1L,1L, 3L,1L,1L,2L,2L,2L,2L,1L,1L,4L,1L,1L,2L,2L,1L,1L,1L,1L,2L,1L,2L,1L,2L,4L,1L, 1L,1L,1L,2L,2L,1L,1L,2L,2L,1L,4L,1L,2L,1L,1L,2L,2L,3L,3L,1L,2L,1L,4L,2L,2L, 1L,1L,4L,1L,2L,3L,2L,1L,1L,1L,1L,1L,2L,1L,2L,2L,4L,1L,2L,1L,1L,4L),. Label = c( “ BL”,“ BR”,“ NULL”,“ O”),类=“ factor”),动物=结构(c(1L,1L,1L,1L,1L,1L,2L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,2L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L)、. Label = c(“ N”,“ Y”),class =“ factor”),Age =结构(c(1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,2L,2L,2L,2L,2L, 2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L, 2L,2L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L, 3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,.Label = c(“ 21”, “ 22”,“ 23”),类=“因子”),后视图=结构(c(1L,2L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,2L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,2L,2L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,2L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L),.Label = c(“ N”,“ Y”),class =“ factor”),SkinTone =结构( c(3L,2L,2L,2L,1L,1L,2L,2L,2L,2L,1L,2L,2L,2L,2L,2L,3L,2L,2L,2L,2L,2L,1L,1L, 2L,2L,2L,2L,2L,1L,2L,1L,2L,2L,2L,2L,1L,1L,1L,1L,2L,2L,2L,2L,2L,2L,2L,2L,2L, 1L,1L,1L,1L,2L,2L,2L,1L,2L,2L,2L,1L,1L,2L,1L,3L,3L,2L,2L,1L,2L,2L,2L,2L,3L,3L,2L,2L,2L,2L,2L,2L,2L,2L,1L,2L,2L,3L,1L,1L,2L,2L,2L,1L,1L,1L,2L, 1L,2L,2L,2L,1L,1L,2L),.Label = c(“ Dark”,“ Fair”,“ NULL”),class =“ factor”),Smile =结构(c(5L,3L, 1L,1L,5L,4L,1L,1L,5L,1L,4L,4L,1L,1L,4L,3L,1L,2L,2L,1L,4L,3L,5L,5L,1L,3L,1L, 5L,5L,2L,5L,1L,2L,5L,1L,2L,2L,1L,4L,5L,5L,4L,3L,5L,2L,4L,2L,3L,5L,3L,5L,4L, 1L,5L,5L,4L,5L,5L,5L,1L,5L,2L,2L,1L,5L,5L,3L,5L,4L,4L,5L,4L,1L,3L,2L,1L,1L, 5L,4L,5L,4L,5L,5L,1L,2L,4L,3L,5L,5L,1L,5L,1L,4L,1L,4L,5L,1L,5L,4L,4L,5L,5L, 1L),.Label = c(“ CS”,“ NS”,“ NULL”,“ O”,“ ST”),class =“ factor”),HairLength = structure(c(1L,3L,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“ LD”,“ NULL”,“ T”),class =“ factor”),Outfit = structure(c(2L,1L,2L,1L,3L,1L,1L,4L, 1L,4L,1L,1L,1L,1L,1L,1L,4L,1L,2L,3L,2L,1L,1L,1L,1L,1L,1L,1L,2L,1L,4L,4L,2L, 1L,1L,2L,3L,3L,4L,1L,1L,1L,1L,1L,3L,1L,1L,1L,1L,1L,3L,1L,1L,1L,4L,3L,4L,1L,1L,1L,2L,3L,1L,3L,1L,1L,1L,1L,3L,2L,2L,1L,2L, 1L,1L,3L,1L,1L,1L,3L,3L,1L,1L,1L,1L,1L,4L,1L,1L,1L,1L,2L,1L,1L,3L,1L,1L,1L, 1L,2L,4L,1L,4L),.Label = c(“ D”,“ I”,“ NULL”,“ O”),class =“ factor”),Background = structure(c(2L,4L, 1L,4L,3L,1L,1L,2L,1L,1L,1L,1L,1L,1L,4L,2L,1L,4L,1L,4L,1L,1L,4L,1L,3L,2L,1L, 1L,4L,2L,1L,1L,1L,4L,1L,1L,1L,1L,1L,4L,2L,1L,1L,1L,3L,3L,1L,1L,4L,1L,3L,1L, 1L,1L,2L,1L,1L,1L,2L,3L,2L,1L,2L,4L,4L,4L,1L,4L,1L,1L,1L,1L,1L,1L,1L,3L,1L, 1L,1L,1L,3L,2L,1L,1L,1L,3L,2L,4L,2L,4L,1L,1L,4L,3L,3L,1L,2L,4L,1L,3L,4L,4L, 3L),.Label = c(“ I”,“ N”,“ NULL”,“ P”),class =“因子“),TypeofShot =结构(c(1L,4L,1L,4L,2L,4L,1L,1L,4L,1L,1L,2L,1L,1L,4L,3L,4L,1L,1L,3L, 4L,3L,3L,3L,4L,4L,2L,1L,3L,1L,3L,4L,1L,4L,1L,1L,2L,1L,1L,4L,1L,1L,4L,4L,2L, 1L,3L,4L,1L,1L,2L,1L,4L,4L,3L,1L,4L,1L,3L,1L,4L,1L,1L,1L,1L,3L,1L,1L,2L,2L, 1L,4L,1L,4L,4L,1L,1L,1L,1L,1L,2L,3L,3L,3L,4L,2L,3L,3L,1L,3L,4L,1L,3L,2L,1L, 1L,1L,3L,2L,1L,4L,3L,4L)、. Label = c(“ CU”,“ ECU”,“ LS”,“ MS”),类别=“ factor”),障碍物=结构c(1L,2L,1L,1L,1L,3L,1L,1L,1L,1L,1L,1L,1L,1L,1L,3L,1L,1L,1L,3L,1L,2L,1L,1L, 3L,3L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,3L,1L,3L,1L,1L,3L,1L, 2L,1L,1L,3L,1L,3L,1L,1L,1L,1L,1L,1L,3L,3L,3L,1L,1L,3L,1L,1L,1L,1L,1L,1L,2L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,2L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,3L,1L,1L,1L,1L,1L,1L),.Label = c(“ N”,“ NULL”,“ Y”),class =“ factor”),Makeup = structure(c( 4L,4L,2L,2L,3L,2L,2L,3L,2L,2L,1L,1L,2L,2L,3L,4L,1L,2L,2L,4L,1L,4L,2L,3L,4L, 2L,1L,2L,2L,2L,2L,1L,1L,1L,1L,2L,1L,1L,1L,2L,2L,2L,3L,3L,2L,1L,2L,3L,3L,1L, 2L,1L,3L,2L,4L,2L,2L,2L,3L,2L,2L,3L,3L,3L,3L,3L,1L,2L,2L,3L,2L,3L,2L,4L,4L, 2L,3L,2L,1L,2L,3L,3L,1L,2L,1L,2L,4L,2L,2L,2L,2L,2L,1L,2L,2L,2L,4L,2L,2L,1L, 3L,1L,1L),.Label = c(“ H”,“ L”,“ N”,“ NULL”),class =“ factor”),结果=结构(c(1L,1L,1L,1L, 1L,1L,1L,1L,2L,1L,1L,1L,2L,1L,1L,2L,1L,1L,1L,1L,1L,1L,1L,1L,2L,1L,1L,1L,1L,1L,1L,1L,1L,1L,2L,2L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,2L,1L,1L,1L,1L,1L,2L,1L,1L,1L,1L,1L,1L,2L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,2L,2L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L),.Label = c(“ N”,“ Y”),class =“ factor”),预测= c(9.32475933917106e-09 ,0.0385259384817495、0.0678681154072461、0.234968717458685、0.0290199853775816、0.171162293958793793、0.00129264601900783、0.00675484440459677、0.128155946032347、0.133539709174044、0.118744423809008、0.060206929901843、0.128155946032347、0.146426608321689、0608、360360834563 0.8679。111383163512112,0.0402597164944323,0.0141022328039524,0.55471858422641,0.128155946032347,0.35526622136263,0.128155946032347,0.382743622548627,0.00485338573377989,0.128155946032347,0.0324058895421302,0.320728574893713,0.320728574893713,0.35526622136263,0.146426608321148,0.0179540767871002,0.398798221640772,0.362407391381727,0.00485338573377989,0.00129264601900783,0.128155946032347,0.0823507208338033,0.00675484440459677,0.0195543511193415,0.320728574893713, 0.128155946032347、0.174534177022049、0.0477307982973154、0.0625662879441275、0.0174929064796301、0.135882446473831、0.00696631574219797、0.419831884479578、0.0862150002573959、0.128155946032347、0.0698582713166507、0.128155946032347、0.174534177022049、0.0164634102803959841.14002192545012e-08,0.0345251778805331,0.208346726243955,0.0203551415502053,0.020830802150735,0.128155946032347,0.197915823620481,0.146426608321148,9.32475933917106e-09,9.32475933917106e-09,0.128155946032347,0.0552623520735392,0.016802787713206,0.0345251778805331,0.146426608321148,0.00675484440459677,0.00579370288906212,0.320728574893713,0.00316694181006374,0.320728574893713,0.146426608321148 ,1.66951123737628e-08、0.0466701670833381、0.0402597164944323、0.382743622548627、0.128155946032347、0.128155946032347、0.118744423809008、0.171162293958793、0.0402597164944323、0.146426608321148、0.0895467055067367、0.0110101302622226、0.05872534136263(360081608)284230842842 Post.Processing”,“ HairColour”,“ Animals”,“年龄”,“后视图”,“肤色”,“微笑”,“头发长度”,“头发纹理”,“头发样式”,“服装”,“背景”,“ TypeofShot”,“障碍物”,“化妆”,“结果”,“预测”),row.names = c(2L,3L,9L,17L,19L,22L,23L,28L,29L,41L,42L,45L,47L,53L,55L,67L,68L,69L, 72L,78L,80L,81L,82L,83L,84L,90L,94L,95L,101L,103L,106L,111L,113L,116L,118L,119L,120L,122L,123L,128L,130L,134L,136L, 138L,144L,146L,148L,150L,152L,161L,162L,163L,165L,168L,174L,175L,180L,181L,183L,194L,204L,207L,210L,213L,214L,215L,221L,224L, 230L,234L,235L,236L,237L,239L,240L,244L,249L,250L,255L,259L,262L,272L,277L,278L,280L,281L,284L,289L,296L,297L,304L,306L,308L 316L,321L,323L,327L,329L,332L,335L,337L,339L,340L),类=“ data.frame”)
该模型正在运行,它提供了一些输出,但是print方法不起作用。
> print(best1)
AIC
Best Model:
Error in levels(x)[x] : only 0's may be mixed with negative subscripts
In addition: Warning messages:
1: In model.response(mf, "numeric") :
using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : '-' not meaningful for factors
但是best1结构正确,并且提供了best1 $ BestModel
best1$BestModel
Call: glm(formula = y ~ ., family = family, data = Xi, weights = weights)
Coefficients:
(Intercept) Post.ProcessingY Age22 Age23
-40.416 -244.338 59.277 -41.652
SkinToneFair SkinToneNULL SmileNS SmileNULL
245.316 -5.102 -80.986 -142.908
SmileO SmileST HairLengthNULL HairLengthSM
-121.258 -80.482 -159.677 -20.045
OutfitI OutfitNULL OutfitO BackgroundN
41.652 -41.653 -410.492 19.895
BackgroundNULL BackgroundP TypeofShotECU TypeofShotLS
-82.640 -208.283 16.369 -101.467
TypeofShotMS MakeupL MakeupN MakeupNULL
101.819 39.438 -122.850 285.187
Degrees of Freedom: 102 Total (i.e. Null); 79 Residual
Null Deviance: 69.99
Residual Deviance: 5.545 AIC: 53.55
您可以将print.bestglm方法替换为
print.bestglm <- function (x, ...)
{
ti <- x$Title
cat(ti, fill = TRUE)
if ((x$ModelReport$Bestk > 0) || (x$ModelReport$IncludeInterceptQ)) {
cat("Best Model:", fill = TRUE)
if (any(x$ModelReport$NumDF > 1))
out <- summary(x$BestModel)
else out <- summary(x$BestModel)$coefficients
print(out)
}
else cat("Best Model is the null model with no parameters.",
fill = TRUE)
}
问题在于代码使用了不推荐使用的功能。它在glm对象上调用aov,这是错误的。我认为使用替换功能应该可以解决问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句