University Solutions Hub provides Visual Analytics Week 12 solution
(Visual Analytics).
Week 12: working with models4
- load the margins library
- create a new column called called polviews_m to use Moderate as a
reference category using relevel on the polviews column of the gss_sm
data.
- use glm() to create a model called out_bo using logistic regression
of polviews_m with sex and race showing an interaction glm(obama~
polviews_m + sex*race, family = “binomial”, data = gss_sm).
- use summary() on out_bo to see what the results look like
- calculate the marginal effects of each variable and store that in a
variable called bo_m.
- plot(bo_m) to see a graph of the results
- create a tibble called bo_gg of the summary() of bo_m, create a
vector of the prefixes ‘polviews_m’ and ‘sex’. And, remove the prefixes
from the factor column and replace ‘race’ with ‘Race:’ in the factor
column. Finally, limit the contents of the bo_gg attributes to ‘factor’,
‘AME’, ‘lower’, and ‘upper’.
- Plot the average marginal effects with a point and the upper and
lower bounds with whiskers
Note:
Only for knowledge gain and helping to the students(who are facing
difficulties when solving to the Assessments/ Home works) with their
course support.