【问题标题】:Variable Selection in RR中的变量选择
【发布时间】:2019-08-30 05:20:36
【问题描述】:

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

 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, direction = "forward") : 此模型的 AIC 为 -infinity,因此“步骤”无法继续 另外:警告信息: 在 Ops.factor(weighted.residuals(object), 2) 中: ‘^’ 对因子没有意义

【问题讨论】:

    标签: r variable-selection


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回复!能否提供使用bestglm函数的代码?
    • 我无法真正帮助您,因为我不熟悉使用分类预测变量的逻辑回归。也许搜索分类主成分分析会有所帮助。如果您有兴趣使用数字变量对二进制结果进行分类,那么 bestglm 可以按如下方式使用 bestglm(Xy, family = binomial) 其中 Xy 是 data.frame 类的对象,其格式设置为所有预测变量都在左侧,而您的二分法结果编码为01,命名为y,是右侧的最后一列。
    猜你喜欢
    • 2015-06-06
    • 2013-06-19
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多