19  Übung 12 Lösung

pacman::p_load("sjPlot", "texreg", "haven", "readr", "readxl", "fixest", "MASS",
               "glm.predict", "scales", "tidyverse")

20 Aufgabe 1a

logist = read_dta("logist.dta")
lm1 = lm(grade ~ gpa + tuce + psi, logist)
print(lm1)
plot_model(lm1, type = "pred")

21 Aufgabe 1b

predict(lm1, newdata = data.frame(gpa = 4, tuce = 0, psi = 0))

1 = 0.357 Wahrscheinlichkeit mit GPA 4 Höchstnote zu schreiben

predict(lm1, newdata = data.frame(gpa = 2.06, tuce = 0, psi = 0))

1 = - 0.54

-> Wahrscheinlichkeit ist höher wenn man vorher schlechtere Note hatte?

lm2 = lm(grade ~ gpa, logist)

plot_model(lm2, type = "pred")

22 Aufgabe 2

Zeugt den Schnitt besser?? Im Tutorat Video schauen

23 Aufgabe 3a

vote = read_tsv("pr_vote.tab")
vote2 = vote %>% 
  mutate(
    PRvote = as.numeric(case_when(
      PRvote == "J" ~ "1",
      PRvote == "N" ~ "0", 
      PRvote == "Fehlt" ~ "NA",
      T ~ TRUE))
  )

# Dieser Code macht Daten gleichzeitig numerisch und rekodiert sie!

24 Aufgabe 3b

lm3 = glm(PRvote ~ rokkan2_svd + socialdem11912 + skill_ratio, family = binomial(link = "probit"), data = vote2)
lm3
summary(lm3)

25 Aufgabe 3c

Wir können legedlich beurteilen ob eine Variable einen effekt auf eine signifikante Variable hat.

26 Aufgabe 3d

plot_model(lm3, type = "pred")

Hypothese hält stand

27 Aufgabe 4a

print(lm3)
?predicts
set.seed(666)
prob = predicts(lm3, "median;0-80,5;median", type = "simulation")

28 Aufgabe 4b

prob %>% 
  arrange(mean) %>% 
  ggplot(aes(x = socialdem11912, y = mean)) +
  
  geom_ribbon(
    aes(ymin = upper, ymax = lower),
    fill = "red",
    alpha = 0.2
  ) +
  
  geom_point(aes(color = mean)) +
  
  theme_bw() +
  
  labs(
    x = "Stärke der linken Kandidaten",
    y = "Wahrscheinlichkeit JA"
  ) + scale_y_continuous(labels = scales::percent)
?

Lernuhr
Uhrzeit
Lerntimer