0

I'm setting a model to find the significant variables using 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)

Error in step(fitstart, direction = "forward") : AIC is -infinity for this model, so 'step' cannot proceed In addition: Warning message: In Ops.factor(weighted.residuals(object), 2) : ‘^’ not meaningful for factors

1 Answers1

0

You are trying to predict a dichotomous factor with 2 levels. Stepwise selection is inappropriate and you should use logistic regression. Even in that case, if you use bestglm for example you need to convert this variable into 0 and 1.

Dij
  • 1,318
  • 1
  • 7
  • 13
  • Thanks for the response! Can you provide the code for using the bestglm function? – Kasi Perumal Apr 09 '19 at 22:48
  • I can't really help you there because I am not familiar with logistic regression using categorical predictors. Perhaps a search for Categorical Principal Component Analysis could help. If you are interested in classifying your binary outcome using your numeric variables then `bestglm` could be used as follows `bestglm(Xy, family = binomial)` where Xy is your object of class `data.frame` formatted such that all of the predictor variables are on the left and your dichotomous outcome is coded `0` and `1`, named `y`, and is the last column on the right. – Dij Apr 09 '19 at 22:58