library(dplyr)
library(tidyr)
library(multcomp)
library(dunn.test)
library(GGally)
install.packages("dunn.test")
... <- read.csv("Data/ .csv",
stringsAsFactors = TRUE)
#----------------------------------------------------------------------------------------------------------------
---------------------------------------
# PC 1: basisbegrippen
#----------------------------------------------------------------------------------------------------------------
---------------------------------------
#dichtheidshistogram (continu)
ggplot(dataset, aes( x = variabele)) +
geom_histogram(aes( y = after_stat(density)),
bins = n) # + labs(x = "", y = "", title = "...")
#staafdiagram (discreet)
ggplot(dataset, aes(x = variabele)) +
geom_bar(aes(y = afterstat(prop)))
#empirische verdelingsfunctie
ggplot(dataset, aes(x = variabele)) +
stat_ecdf()
#boxplot
ggplot(dataset, aes( x = groep, y = waarde, fill = groep)) +
geom_boxplot()
#afkortingen voor verdelingen
, ?distribution
d... = densiteit (dichtheidsfunctie/probabiliteitsfunctie)
q... = kwantiel
p... = cummulatieve probabiliteit (verdelingsfunctie)
r... = random steekproef uit distributie
#extra functies toevoegen aan grafiek
avg <- mean(dataset$variabele)
s <- sd(dataset$variabele)
ggplot(dataset, aes(x = variabele)) +
... +
stat_function(fun = dnorm, #kan ook q/p/r..., of ...pois
args = list(mean = avg, #lambda = avg bij pois
sd = s ),
color = "red")
#QQ-plot
ggplot(dataset, aes(sample = variabele)) + #sample!!!
geom_qq(distribution = stats::qnorm, dparams = list(...)) +
geom_qq_line(distribution = stats::qnorm, dparams = list(...),
line.p = c(0...,0...)) #kwantielen aanpassen
#afwijking in staarten:
#horizontaal = kwantielen van steekproef dichter bij centrum dan verwacht
#verticaal = kwantielen verder van centrum dan verwacht
#betrouwbaarheidsinterval (vb.90%)
mX <- mean(dataset$variabele)
S <- sd(dataset$variabele)
n <- length(dataset$variabele)
t <- qt(p = 0.95, df = n-1) #90% BI
onderg <- mX - t * (S / sqrt(n))
boveng <- mX + t * (S / sqrt(n))
c(onderg,boveng)
, # ONE SAMPLE T-TEST #
#H0: µ = µ0
#H1: µ =!/</> µ0
#voorwaarden:
#1) continue variabele
#2) aselecte steekproef: observaties onafhankelijk van elkaar
#3) Populatie normaal verdeeld (of n groot genoeg voor centrale limietstelling)
#QQ plot maken
#manueel
#n <- nrow(no2)
#Qt <- (mx- m0?) / (S/sqrt(n))
#1- pt(Qt, df = n- 1)
#automatisch
t.test(dataset$variabele, mu=mu0,
alternative = “two.sided“) # = tweezijdig, less = links, greater = rechts
#----------------------------------------------------------------------------------------------------------------
---------------------------------------
# PC 2: Statistische besluitvorming
#----------------------------------------------------------------------------------------------------------------
---------------------------------------
#meerdere variabelen
#------------------------------------
# GEPAARDE T-TEST #
#H0: µverschil = 0
#H1: µverschil =! 0
#voorwaarden: