This commit is contained in:
Jakub Adamski 2021-05-30 12:48:38 +02:00
parent 6e10bcea52
commit 45390c180b
7 changed files with 234 additions and 0 deletions

View File

@ -34,6 +34,8 @@ Hipotezy:
- H1 : Próba nie pochodzi z populacji o rozkładzie normalnym.
Hipoteza zerowa tego testu mówi nam o tym, że nasza próba badawcza pochodzi z populacji o normalnym rozkładzie. Jeśli test Shapiro-Wilka osiąga istotność statystyczną (p < 0,05), świadczy to o rozkładzie oddalonym od krzywej Gaussa. W przypadku tego testu najczęściej chcemy otrzymać wartości nieistotne statystyczne (p > 0,05), ponieważ świadczą one o zgodności rozkładu zmiennej z rozkładem normalnym.
# Var.test

BIN
zajecia7/.RData Normal file

Binary file not shown.

84
zajecia7/.Rhistory Normal file
View File

@ -0,0 +1,84 @@
dane <- read.table("http://ls.home.amu.edu.pl/data_sets/kontekst.txt")
View(dane)
colnames(dane) <- c("number", "context")
dane$context <- as.factor(dane$context)
aggregate(dane$number, list(CONTEXT = dane$context), FUN = mean)
boxplot(number ~ context, data = dane, xlab = "Kontekst", ylab = "Words number")
summary(aov(number ~ context, data = dane))
rests <- lm(number ~ context, data = dane)$residuals
shapiro.test(rests)$p.value
qqnorm(rests)
qqline(rests)
bartlett.test(number ~ context, data = dane)$p.value
fligner.test(number ~ context, data = dane)$p.value
library(car)
leveneTest(number ~ context, data = dane)[[3]][1]
leveneTest(number ~ context, data = dane, center = "mean")[[3]][1]
attach(dane)
pairwise.t.test(number, context, data = dane)
boxplot(number ~ context, data = dane, xlab = "Kontekst", ylab = "Words number")
model_aov <- aov(number ~ context, data = dane)
TukeyHSD(model_aov)$context
plot(TukeyHSD(model_aov))
library(agricolae)
install.packages("agricolae")
library(agricolae)
HSD.test(model_aov, "context", console = TRUE)
SNK.test(model_aov, "context", console = TRUE)
LSD.test(model_aov, "context", p.adj = "holm", console = TRUE)
scheffe.test(model_aov, "context", console = TRUE)
C1 <- c(-3, 2, 2, -3, 2)
C2 <- c(0, -1, -1, 0, 2)
C3 <- c(0, 1, -1, 0, 0)
C4 <- c(1, 0, 0, -1, 0)
con <- cbind(C1, C2, C3, C4)
contrasts(dane$context) <- con
model_aov_2 <- aov(number ~ context, data = dane)
summary(model_aov_2, split = list(context = list('C1' = 1, 'C2' = 2, 'C3' = 3, 'C4' = 4)))
dane <- read.table("http://ls.home.amu.edu.pl/data_sets/eysenck.txt")
dane <- read.table("http://ls.home.amu.edu.pl/data_sets/eysenck.txt")
View(dane)
colnames(dane) <- c("result", "instruction")
dane <- read.table("http://ls.home.amu.edu.pl/data_sets/Eysenck.txt", header = TRUE)
dane$Nr <- NULL
dane$context <- as.factor(dane$context)
dane$Instrukcja <- as.factor(dane$Instrukcja)
aggregate(dane$Wynik, list(CONTEXT = dane$Instrukcja), FUN = mean)
boxplot(number ~ context, data = dane, xlab = "Instrukcja", ylab = "Wynik")
boxplot(Wynik ~ Instrukcja, data = dane, xlab = "Instrukcja", ylab = "Wynik")
summary(aov(Wynik ~ Instrukcja, data = dane))
rests <- lm(Wynik ~ Instrukcja, data = dane)$residuals
shapiro.test(rests)$p.value
qqnorm(rests)
qqline(rests)
bartlett.test(Wynik ~ Instrukcja, data = dane)$p.value
fligner.test(Wynik ~ Instrukcja, data = dane)$p.value
leveneTest(Wynik ~ Instrukcja, data = dane)[[3]][1]
leveneTest(Wynik ~ Instrukcja, data = dane, center = "mean")[[3]][1]
attach(dane)
pairwise.t.test(Wynik, Instrukcja, data = dane)
model_aov <- aov(Wynik ~ Instrukcja, data = dane)
TukeyHSD(model_aov)$Instrukcja
plot(TukeyHSD(model_aov))
HSD.test(model_aov, "Instrukcja", console = TRUE)
SNK.test(model_aov, "Instrukcja", console = TRUE)
LSD.test(model_aov, "Instrukcja", p.adj = "holm", console = TRUE)
scheffe.test(model_aov, "Instrukcja", console = TRUE)
C1 <- c(0, 1, -1, 1, -1)
C2 <- c(4, -1, -1, -1, -1)
C3 <- c(0, 1, 0, -1, 0)
C4 <- c(0, 0, -1, 0, 1)
con <- cbind(C1, C2, C3, C4)
contrasts(dane$Instrukcja) <- con
View(con)
model_aov_2 <- aov(Wynik ~ Instrukcja, data = dane)
View(model_aov_2)
summary(model_aov_2, split = list(Instrukcja = list('C1' = 1, 'C2' = 2, 'C3' = 3, 'C4' = 4)))
boxplot(Wynik ~ Instrukcja, data = dane, xlab = "Instrukcja", ylab = "Wynik")
contrasts(dane$Instrukcja) <- con
c <- contrasts(dane$Instrukcja) <- con
View(c)
View(dane)
contrasts(dane$Instrukcja) <- con
contrasts(dane$Instrukcja)
View(dane)

48
zajecia7/README.md Normal file
View File

@ -0,0 +1,48 @@
# Zajęcia 7
## Notatki
- Dużo jest tych funkcji gotowych/wbudowanych - mogą być ważne na egzamin?
- Ortogonalny - prostopadły
## Analiza wariancji
Została użyta aby sprawdzić czy wartość danej zmeinnej zależy w stopniu znaczącym od innej zmiennej.
- fligner.test oraz bartlett.test leveneTest użyte do sprawdzenia czy wariancje dwóch grup są takie same
## Porównanie wyników
- pairwise.t.test - daje wynik w postaci tabeli jak różnią się od siebie wyniki poszczególnych grup
- TukeyHSD - Create a set of confidence intervals on the differences between the means of the levels of a factor (współczynnik) with the specified family-wise probability of coverage. The intervals are based on the Studentized range statistic, Tukey's Honest Significant Difference method.
- HSD.test - na podstawie testu Tukeya - wynik w postaci grup
- SNK - SNK is derived from Tukey, but it is less conservative (finds more differences). Tukey controls the error for all comparisons, where SNK only controls for comparisons under consideration. Wynik też w postaci grup
- LSD - Multiple comparisons, "Least significant difference" and Adjust P-values. Wynik też grupy.
- Scheffe - method is very general in that all possible contrasts can be tested for significance and confidence intervals can be constructed for the corresponding linear. The test is conservative. Wynik też grupy.
## Jednoczynnikowa analiza wariancji
W jednoczynnikowej analizie wariancji, jak sama nazwa wskazuje, mamy do czynienia tylko z jednym czynnikiem. Chcemy sprawdzić, czy jakiś pojedynczy czynnik ma wpływ na mierzoną zmienną zależną.
## Testy post hoc
Testy post-hoc (po fakcie) wykonuje się jako kolejny krok analizy wariancji. Znane są również pod nazwą porównań wielokrotnych lub porównań parami. Sama analiza wariancji mówi nam o tym czy różnice w porównywanych średnich występują czy nie. Nie wiemy jednak między którymi grupami zachodzą te różnice. Istotny współczynnik F wskazuje jedynie na słuszność (lub brak słuszności) odrzucenia hipotezy zerowej. Jeśli ją odrzucimy musimy dowiedzieć się czy wszystkie średnie różnią się między sobą czy tylko niektóre. Stąd też nazwa “po fakcie” wykonujemy je dopiero po sprawdzeniu czy wynik F jest istotny statystycznie. Jeśli nie jest, nie musimy wykonywać testów post-hoc.
## Kontrast
By można było zdefiniować wybrane hipotezy należy dla każdej średniej przypisać wartość kontrastu.
Wartości kontrastu są tak wybierane by ich sumy dla porównywanych stron były liczbami przeciwnymi, a ich wartość dla średnich nie biorących udziału w analizie wynosi 0!!
Wykonując później test ANOVA - analiza wariancji możemy zobaczyć czy porównywane grupy (wyszczególnione za pomocą kontrastów) różnią się od siebie.

BIN
zajecia7/Zajęcia7.pdf Normal file

Binary file not shown.

87
zajecia7/zadania.R Normal file
View File

@ -0,0 +1,87 @@
# ZAD1
dane <- read.table("http://ls.home.amu.edu.pl/data_sets/kontekst.txt")
colnames(dane) <- c("number", "context")
# Transform from text type to categorical type
dane$context <- as.factor(dane$context)
aggregate(dane$number, list(CONTEXT = dane$context), FUN = mean)
boxplot(number ~ context, data = dane, xlab = "Kontekst", ylab = "Words number")
summary(aov(number ~ context, data = dane))
rests <- lm(number ~ context, data = dane)$residuals
shapiro.test(rests)$p.value
qqnorm(rests)
qqline(rests)
bartlett.test(number ~ context, data = dane)$p.value
fligner.test(number ~ context, data = dane)$p.value
# library(car)
leveneTest(number ~ context, data = dane)[[3]][1]
leveneTest(number ~ context, data = dane, center = "mean")[[3]][1]
attach(dane)
pairwise.t.test(number, context, data = dane)
model_aov <- aov(number ~ context, data = dane)
TukeyHSD(model_aov)$context
plot(TukeyHSD(model_aov))
# install.packages("agricolae")
# library(agricolae)
HSD.test(model_aov, "context", console = TRUE)
SNK.test(model_aov, "context", console = TRUE)
LSD.test(model_aov, "context", p.adj = "holm", console = TRUE)
scheffe.test(model_aov, "context", console = TRUE)
C1 <- c(-3, 2, 2, -3, 2)
C2 <- c(0, -1, -1, 0, 2)
C3 <- c(0, 1, -1, 0, 0)
C4 <- c(1, 0, 0, -1, 0)
con <- cbind(C1, C2, C3, C4)
contrasts(dane$context) <- con
model_aov_2 <- aov(number ~ context, data = dane)
summary(model_aov_2, split = list(context = list('C1' = 1, 'C2' = 2, 'C3' = 3, 'C4' = 4)))
# ZAD2
dane <- read.table("http://ls.home.amu.edu.pl/data_sets/Eysenck.txt", header = TRUE)
dane$Nr <- NULL
dane$Instrukcja <- as.factor(dane$Instrukcja)
aggregate(dane$Wynik, list(CONTEXT = dane$Instrukcja), FUN = mean)
boxplot(Wynik ~ Instrukcja, data = dane, xlab = "Instrukcja", ylab = "Wynik")
summary(aov(Wynik ~ Instrukcja, data = dane))
rests <- lm(Wynik ~ Instrukcja, data = dane)$residuals
shapiro.test(rests)$p.value
qqnorm(rests)
qqline(rests)
bartlett.test(Wynik ~ Instrukcja, data = dane)$p.value
fligner.test(Wynik ~ Instrukcja, data = dane)$p.value
# library(car)
leveneTest(Wynik ~ Instrukcja, data = dane)[[3]][1]
leveneTest(Wynik ~ Instrukcja, data = dane, center = "mean")[[3]][1]
attach(dane)
pairwise.t.test(Wynik, Instrukcja, data = dane)
model_aov <- aov(Wynik ~ Instrukcja, data = dane)
TukeyHSD(model_aov)$Instrukcja
plot(TukeyHSD(model_aov))
# library(agricolae)
HSD.test(model_aov, "Instrukcja", console = TRUE)
SNK.test(model_aov, "Instrukcja", console = TRUE)
LSD.test(model_aov, "Instrukcja", p.adj = "holm", console = TRUE)
scheffe.test(model_aov, "Instrukcja", console = TRUE)
C1 <- c(0, 1, -1, 1, -1)
C2 <- c(4, -1, -1, -1, -1)
C3 <- c(0, 1, 0, -1, 0)
C4 <- c(0, 0, -1, 0, 1)
con <- cbind(C1, C2, C3, C4)
contrasts(dane$Instrukcja) <- con
contrasts(dane$Instrukcja)
model_aov_2 <- aov(Wynik ~ Instrukcja, data = dane)
summary(model_aov_2, split = list(Instrukcja = list('C1' = 1, 'C2' = 2, 'C3' = 3, 'C4' = 4)))

13
zajecia7/zajecia7.Rproj Normal file
View File

@ -0,0 +1,13 @@
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX