R中的变量选择

时间:2019-04-09 01:37:16

标签: r variable-selection

我正在设置一个模型以使用变量选择来查找重要变量。

 str(tweets2)
'data.frame':   6429 obs. of  13 variables:
 $ created_at            : Factor w/ 5918 levels "1/10/2019 17:40",..: 56 
53 52 51 50 49 48 47 46 45 ...
 $ screen_name           : Factor w/ 2 levels "HillaryClinton",..: 1 1 1 
 1 1 1 1 1 1 1 ...
 $ text                  : chr  "On top of human suffering and lasting 
damage to our national parks  the Trump shutdown cost the economy     
bil"| __truncated__ "Hurricane Maria decimated trees and ecosystems in 
Puerto Rico  Para La Naturaleza s nurseries have made a CGI c"| 
__truncated__ "Time to make the churros at Kreamy Ice Cream Shop in 
Puerto Rico   ClintonGlobal and  Foundation PR are working"| 
__truncated__ " chefjoseandres You are an inspiration  my friend " ...
$ source                : Factor w/ 6 levels "TweetDeck","Twitter for 
iPad",..: 6 6 6 6 6 6 6 6 3 3 ...
$ display_text_width    : int  192 235 238 34 222 214 140 259 140 140 ...
$ is_retweet            : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
$ favorite_count        : int  14324 10684 11423 1293 6641 12192 0 17618 
0 0 ...
$ retweet_count         : int  4168 2526 2089 113 951 2108 2094 4999 691 
915 ...
 $ retweet_favorite_count: int  NA NA NA NA NA NA 4214 NA 3474 3360 ...
 $ retweet_retweet_count : int  NA NA NA NA NA NA 2094 NA 691 915 ...
 $ retweet_screen_name   : Factor w/ 434 levels "ABCPolitics",..: NA NA 
NA NA NA NA 152 NA 227 44 ...
 $ retweet_name          : Factor w/ 433 levels "ABC News Politics",..: 
NA NA NA NA NA NA 159 NA 236 47 ...
$ retweet_statuses_count: int  NA NA NA NA NA NA 10784 NA 50482 10242 ...

vs = lm(screen_name ~.,data = tweets2)  fitstart = lm(screen_name ~ 1,data = tweets2)  step(fitstart,direction = "forward")  fitstart = lm(screen_name ~ 1,data = tweets2)

步骤出错(fitstart,方向=“前进”):    对于此模型,AIC为-infinity,因此“步骤”无法继续进行    另外:警告消息:    在Ops.factor(weighted.residuals(object),2)中:    ‘^’对因素没有意义

1 个答案:

答案 0 :(得分:0)

您正在尝试预测具有2个水平的二分法因子。逐步选择是不合适的,您应该使用逻辑回归。即使在这种情况下,例如,如果使用bestglm,则需要将此变量转换为01