我正在使用LASSO对包含102个预测变量的数据集进行回归。数据集被正确读取,名称(谋杀)给了我正确的标题。
>library(glmnet)
>murder=read.csv(file="CommViolPredUnnormalizedData.csv", header = TRUE)
从cv.glmnet获得最好的lambda之后,我想用最好的lambda来预测系数。但是,结果会在第26个系数之后更改标题名称,系数标题会复制第26个系数,并在结尾处添加5位数字。这样我在OtherPerCapxxxxx之后命名其余77个系数,如下所示。是因为默认情况下,预测(.. type =“coefficient”)最多可以保存26个系数的标题?非常感谢。
>lasso.out=glmnet(x,y,alpha=1,family="gaussian",lambda=grid)
>lasso.coef=predict(lasso.out,type="coefficients",s=bestlam2)[1:103,]
>lasso.coef
(Intercept) population householdsize racePctBlack racePctWhite
15.68589291 0.00000000 0.00000000 0.07242063 -0.12888132
racePctAsian racePctHisp agePct12t21 agePct12t29 agePct16t24
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
agePct65up numbUrban pctUrban medIncome pctWWage
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
pctWFarmSelf pctWInvInc pctWSocSec pctWPubAsst pctWRetire
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
medFamInc perCapInc whitePerCap blackPerCap indianPerCap
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
AsianPerCap **OtherPerCap0 OtherPerCap10000** OtherPerCap10004 OtherPerCap10005
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10011 OtherPerCap10012 OtherPerCap10028 OtherPerCap10031 OtherPerCap10040
0.23747627 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10043 OtherPerCap10044 OtherPerCap10045 OtherPerCap10046 OtherPerCap10048
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10050 OtherPerCap10051 OtherPerCap10063 OtherPerCap10082 OtherPerCap10088
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10095 OtherPerCap10102 OtherPerCap10113 OtherPerCap10114 OtherPerCap10115
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10118 OtherPerCap10133 OtherPerCap10146 OtherPerCap10152 OtherPerCap10156
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10159 OtherPerCap1016 OtherPerCap10162 OtherPerCap10164 OtherPerCap10166
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10173 OtherPerCap10174 OtherPerCap10176 OtherPerCap10182 OtherPerCap10195
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10205 OtherPerCap10217 OtherPerCap10218 OtherPerCap10219 OtherPerCap1022
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10221 OtherPerCap10244 OtherPerCap10249 OtherPerCap10250 OtherPerCap10254
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10257 OtherPerCap10262 OtherPerCap10272 OtherPerCap10276 OtherPerCap10277
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10280 OtherPerCap10290 OtherPerCap10295 OtherPerCap10300 OtherPerCap10301
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10315 OtherPerCap10317 OtherPerCap10321 OtherPerCap10329 OtherPerCap10333
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10337 OtherPerCap10348 OtherPerCap10351 OtherPerCap10359 OtherPerCap10362
0.00000000 0.00000000 -1.49402709 0.00000000 0.00000000
OtherPerCap10381 OtherPerCap10385 OtherPerCap10394 OtherPerCap10395 OtherPerCap1040
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
OtherPerCap10401 OtherPerCap10423 OtherPerCap10425
0.00000000 0.00000000 0.00000000