0

I have built a logistic regression model with the dependent variable WinParty, which outputs fine. Then when trying to do variable selection with stepAIC I keep getting this error

Data Structure

tibble [2,467 × 25] (S3: tbl_df/tbl/data.frame)
 $ PollingPlace                         : chr [1:2467] "Abbotsbury" "Abbotsford" "Abbotsford East" "Aberdare" ...
 $ CoalitionVotes                       : int [1:2467] 9438 15548 3960 3164 2370 4524 3186 10710 372 5993 ...
 $ VoteDifference                       : num [1:2467] 0.1397 -0.0579 0.0796 -0.2454 0.2623 ...
 $ Liberal.National.Coalition.Percentage: num [1:2467] 57 47.1 54 37.7 63.1 ...
 $ WinParty                             : num [1:2467] 1 0 1 0 1 0 0 0 1 0 ...
 $ Median_age_persons                   : num [1:2467] 43 46 41.5 37 41 31 37 36 57.5 41 ...
 $ Median_mortgage_repay_monthly        : num [1:2467] 2232 3000 2831 1452 1559 ...
 $ Median_tot_prsnl_inc_weekly          : num [1:2467] 818 1262 1380 627 719 ...
 $ Median_rent_weekly                   : num [1:2467] 550 595 576 310 290 ...
 $ Median_tot_fam_inc_weekly            : num [1:2467] 2541 3062 3126 1521 2021 ...
 $ Average_household_size               : num [1:2467] 3.27 2.35 2.28 2.46 2.38 ...
 $ Indig_Percent                        : num [1:2467] 0 0 1.09 10.94 10.61 ...
 $ BirthPlace_Aus                       : num [1:2467] 60.9 67.9 61.7 90.9 89 ...
 $ Other_lang_Percen                    : num [1:2467] 44.97 25.85 28.71 2.58 2.45 ...
 $ Aus_Cit_Percent                      : num [1:2467] 91.5 91.5 86.6 93.7 91.9 ...
 $ Yr12_Comp_Percent                    : num [1:2467] 49.7 57.1 62.7 25 23.1 ...
 $ Pop_Density_SQKM                     : num [1:2467] 2849 6112 7951 1686 334 ...
 $ Industrial_Percent                   : num [1:2467] 6.24 3.95 4.69 8.3 15.31 ...
 $ Population_Serving_Percent           : num [1:2467] 16 12.9 15.1 16.1 13.6 ...
 $ Health_Education_Percent             : num [1:2467] 9.26 11.43 10.28 9.07 7.79 ...
 $ Knowledge_Intensive_Percent          : num [1:2467] 11.31 19.64 17.06 7.44 6.56 ...
 $ Over60_Yr                            : num [1:2467] 25.1 31.6 24.9 20.6 25.3 ...
 $ GenZ                                 : num [1:2467] 24.5 20 25.9 26.2 23.6 ...
 $ GenX                                 : num [1:2467] 27 29.1 26.6 25.8 26.1 ...
 $ Millenials                           : num [1:2467] 23.3 20.3 19.7 27.3 27.1 ...
 - attr(*, "na.action")= 'omit' Named int [1:8] 264 647 843 1332 1774 2033 2077 2138
  ..- attr(*, "names")= chr [1:8] "264" "647" "843" "1332" ...

The glm function computes the logistic regression with no errors

mod1 <- glm(WinParty~Median_age_persons+Median_rent_weekly+
             Median_tot_fam_inc_weekly+Indig_Percent+BirthPlace_Aus+
             Other_lang_Percen+Aus_Cit_Percent+Yr12_Comp_Percent+
             Industrial_Percent+Population_Serving_Percent+Health_Education_Percent+
             Knowledge_Intensive_Percent+Over60_Yr+GenZ+GenX+Millenials,
            family = binomial(link = "logit"), data = GS_PP_Agg)
summary(mod1)

step1 <- stepAIC(mod1, scope = list(lower = "~1",upper = "~Median_age_persons+Median_rent_weekly+
             Median_tot_fam_inc_weekly+Indig_Percent+BirthPlace_Aus+
             Other_lang_Percen+Aus_Cit_Percent+Yr12_Comp_Percent+
             Industrial_Percent+Population_Serving_Percent+Health_Education_Percent+
             Knowledge_Intensive_Percent+Over60_Yr+GenZ+GenX+Millenials"), data = GS_PP_Agg)

Step AIC function returns the error: "Error in FUN(left, right) : non-numeric argument to binary operator"

Some help in solving this error would be greatly appreciated!

0 Answers0