SHARE
TWEET

Untitled

a guest Nov 19th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(mosaic)
  2.  
  3. # Einlesen in R
  4. tips <- read.csv2("tips.csv")
  5.  
  6. mean(tip ~ 1, data = tips)
  7.  
  8. lm(tip ~ 1, data = tips)
  9.  
  10. #ALtdaten alte VL
  11. erglm1 <- lm(tip~total_bill, data = tips )
  12. erglm2 <- lm(tip~smoker , data=tips)
  13.  
  14. summary(erglm1)
  15. summary(erglm2)
  16.  
  17. #Neues
  18. erglm3 <- lm(tip ~ # abbhängige Variable
  19.                total_bill + smoker, # unabhängige Variablen
  20.              data = tips) # Datensatz
  21. summary(erglm3)
  22.  
  23. plotModel(erglm3)
  24.  
  25. #Bootstrapping
  26. set.seed(1896) # Reproduzierbarkeit
  27. Bootvtlg <- do(10000) * lm(tip ~ total_bill + smoker,
  28.                            data = resample(tips))
  29. confint(Bootvtlg)
  30.  
  31. #Interatkionseffekt
  32. erglm4 <- lm(tip ~ total_bill + smoker + total_bill:smoker,
  33.              data = tips)
  34. plotModel(erglm4)
  35.  
  36. #Test alle Variablen
  37. lm(tip ~ .,
  38.    data = tips)
  39.  
  40. #Schrittweise Regression
  41. #Wertet Schrittweise alle Variablen aus und gibt aus, welche relevant sind
  42. #Noch ohne Interaktionen
  43. step(lm(tip ~ .,
  44.    data = tips))
  45.  
  46. step(lm(tip ~ .+total_bill:smoker,
  47.         data = tips))
  48.  
  49. #S. 311
  50. erglmtb <- lm(total_bill ~ size+time,
  51.         data = tips)
  52. plotModel(erglmtb)
  53.  
  54.  
  55. #Logistische Regression
  56. gf_point( (sex=="Male") ~ total_bill,
  57.           data = tips)
  58.  
  59. #S.322
  60. # Referenzklasse festlegen
  61. tips$sex<- relevel(tips$sex, ref = "Female")
  62. # Kontrolle
  63. levels(tips$sex)
  64.  
  65. # Speichere Ergebnis der Regression glm() in "ergglm1"
  66. ergglm1 <- glm(sex ~ # abhängige Variable
  67.                  total_bill, # unabghängige Variable(n)
  68.                data = tips, # Datensatz
  69.                # Abhängige Variable binomial,
  70.                # Verknüpfung Logit
  71.                family = binomial("logit"))
  72. summary(ergglm1)
  73.  
  74. #Modell auflösen x = 10
  75. exp(-0.12 +0.04 * 10) / (1+exp(-0.12 +0.04 * 10))
  76.  
  77. plotModel(ergglm1)
  78.  
  79. set.seed(1896) # Reproduzierbarkeit
  80. Bootvtlg <- do(10000) *
  81.   glm(sex ~ total_bill,
  82.       data = resample(tips),
  83.       family = binomial("logit"))
  84. gf_histogram( ~ total_bill, data = Bootvtlg)
  85. quantile( ~ total_bill, data = Bootvtlg,
  86.           probs = c(0.025, 0.975))
  87.  
  88. set.seed(1896) # Reproduzierbarkeit
  89. Nullvtlg <- do(10000) *
  90.   glm(sex ~ shuffle(total_bill),
  91.       data = tips,
  92.       family = binomial("logit"))
  93.  
  94. gf_histogram( ~ total_bill, data = Nullvtlg)
  95. prop( ~ abs(total_bill) >= coef(ergglm1)[2],
  96.       data=Nullvtlg )
  97.  
  98. # Ab hier VL 7 von 2019-11-19
  99. ergglm2 <- glm(sex ~ size,
  100.                data = tips,
  101.                family = binomial("logit"))
  102. summary(ergglm2)
  103.  
  104. # S.334
  105. #Modell auflösen x = 10
  106. # b0 = 0,08 b1 = 0,2
  107. # 0,08 + 0,2 * x
  108. # x entweder 1, 2 oder 4
  109.  
  110. 0.08+0.2
  111. # p = 0,28
  112. 0.08+0.2*2
  113. # p = 0,48
  114. 0.08+0.2*4
  115. # p 0,28
  116.  
  117. exp(0.08 +0.2 * 1) / (1+exp(0.08 +0.2 * 1))
  118. exp(0.08 +0.2 * 2) / (1+exp(0.08 +0.2 * 2))
  119. exp(0.08 +0.2 * 4) / (1+exp(0.08 +0.2 * 4))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top