TU Wien:Statistik und Wahrscheinlichkeitstheorie UE (Bura)/Übungen 2020W/HW13.6

Aus VoWi
Zur Navigation springen Zur Suche springen

Cigarettes - yummy (part 2)[Bearbeiten | Quelltext bearbeiten]

In the survey of the previous exercise additionally the smokers were asked how many cigarettes they approximately smoke per day and also those that stopped smoking were asked for the number of cigarettes they smoked before they quit.

The data is given in the file cigarettes.Rdata. Visualize the data. Then test the null hypo- thesis that there is no difference in the mean cigarette consumption between the two groups. Use a 1%-significance level. Formulate a result.

Lösungsvorschlag von Friday[Bearbeiten | Quelltext bearbeiten]

--Friday Sa 30 Jan 2021 18:40:34 CET

# Statistics and Probability: HW #13
# Friday 
# Duedate: 25.01.2021

# 6) Cigarettes - yummy (part 2)
# In the survey of the previous exercise additionally the smokers were asked 
# how many ciga- rettes they approximately smoke per day and also those that 
# stopped smoking were asked for the number of cigarettes they smoked before 
# they quit.
# The data is given in the file cigarettes.Rdata. Visualize the data. Then 
# test the null hypo- thesis that there is no difference in the mean 
# cigarette consumption between the two groups. Use a 1%-significance level. 
# Formulate a result.

load("cigarettes.Rdata")
stripchart(cigarettes, 
           main = "Cigarettes",
           xlab= "smoked per day",
           jitter = 0.1, 
           method='jitter', 
           pch=1,
           col = rainbow(5, v=0.7)
)
x1 = cigarettes$smokers
md1 = mean(x1)
sem1 = sd(x1)/sqrt(length(x1))
rect(md1-sem1, 1-0.15, md1+sem1, 1+0.15, density=10, col='pink')
lines(c(md1,md1), c(1-0.2, 1+0.2), col='red', lwd=2)

x2 = cigarettes$stopped
md2 = mean(x2)
sem2 = sd(x2)/sqrt(length(x2))
rect(md2-sem2, 2-0.15, md2+sem2, 2+0.15, density=10, col='darkseagreen')
lines(c(md2,md2), c(2-0.2, 2+0.2), col='green', lwd=2)

# Test with anova
k <- length(cigarettes)
x <- c()
gr <- c()
for (i in 1:k) {
  for (n in cigarettes[[i]]) {
    x <- c(x, n)
    gr <- c(gr, length(cigarettes[[i]]))
  }
}
anova(aov(x~gr))

# RESULT:
# We reject the hypothesis as p > alpha