Use data frame ‘uk’ from’seminar2 (2).RData’
The variables are:
polintr: how interested in politics;
from 1 - Not at all interested to 4 - Very interested
age: age of the respondent
sex: gender of the respondent
edu: age when completed education
income1: income group
Fulfill the following tasks:
knitr::opts_chunk$set(message=FALSE, warning=FALSE)
load('seminar2 (2).RData')
library(MASS)
m1 = polr(polintr ~ age + sex + edu + income1, data = uk, Hess=T)
summary(m1) # logit
## Call:
## polr(formula = polintr ~ age + sex + edu + income1, data = uk,
## Hess = T)
##
## Coefficients:
## Value Std. Error t value
## age 0.01928 0.002556 7.545
## sexFemale -0.48411 0.087338 -5.543
## edu 0.13976 0.013431 10.405
## income1 0.10993 0.016068 6.842
##
## Intercepts:
## Value Std. Error t value
## Not at all interested|Hardly interested 1.4941 0.2525 5.9174
## Hardly interested|Quite interested 2.8338 0.2571 11.0227
## Quite interested|Very interested 5.2831 0.2795 18.9040
##
## Residual Deviance: 4574.285
## AIC: 4588.285
## (530 observations deleted due to missingness)
Better to interpret only AME coefficients:
library(knitr)
#Marginal effects
library(erer)
#ocME(m1) # logit
kable(ocME(m1)$out$ME.all*100) # in percent
effect.Not at all interested | effect.Hardly interested | effect.Quite interested | effect.Very interested | |
---|---|---|---|---|
age | -0.3 | -0.2 | 0.3 | 0.2 |
sexFemale | 6.7 | 5.1 | -7.3 | -4.5 |
edu | -1.9 | -1.5 | 2.2 | 1.3 |
income1 | -1.5 | -1.2 | 1.7 | 1.0 |
age: each year the probability of being…
sex: for women the probability of being…
edu: each year the probability of being…
income1: per each increase in income group the probability of being…
🔽 ‘Not at all interested’ in politics in comparison with other options decreases by 1.5%
🔽 ‘Not at all interested’ or ‘Hardly interested’ in politics in comparison with other options decreases by 1.2%
🔼 ‘Not at all interested’, ‘Hardly interested’ or ‘Quite interested’ in politics in comparison with being ‘Very interested’ increases by 1.7%
🔼 ‘Very interested’ in politics in comparison with all previous options increases by 1.0%
library(pscl)
t(pR2(m1))
## fitting null model for pseudo-r2
## llh llhNull G2 McFadden r2ML r2CU
## [1,] -2287.143 -2419.829 265.3719 0.05483279 0.1308678 0.1418563
Model seems to be obsolete to predict anything - McFadden’s pseudo R^2 equals to 0.05 which is too low - what a shame.
hitmiss(m1)
## Table of Actual (y) Against Predicted (p)
## Classification rule: outcome with highest probability.
## p=Not at all interested p=Hardly interested
## y=Not at all interested 73 11
## y=Hardly interested 49 17
## y=Quite interested 52 13
## y=Very interested 14 1
## p=Quite interested p=Very interested Row PCP
## y=Not at all interested 271 0 20.563
## y=Hardly interested 411 0 3.564
## y=Quite interested 758 7 91.325
## y=Very interested 205 10 4.348
##
## Percent Correctly Predicted, Fitted Model: 45.35%
## Percent Correctly Predicted, Null Model : 43.87%
So model with predictors is just slightly better than null model and guess even worse than random guessing - that’s a pity.
library(sjPlot)
plot_model(m1, type = "emm", terms = "age", title = 'Logit')
#plot_model(m2, type = "emm", terms = "age", title = 'Probit')
Relationship of age and polintr looks like linear-ish and people with age tends to be more interested in politics.