2. zapoctova pisomka
Created: 2012-05-14 - 14:51
#Zdrojovy kod v R
#1. uloha - urcte hornu a dolnu hranicu intervalu spolahlivosti s gamma = 0.95 (v R aj v Exceli)
x = c(5.03,5.06,5.2,5.04,5.02)
n = length(x)
S2n_1 = var(x) / (n-1);
mD2 = mean(x) - qt((1+0.95)/2,n-1) * sqrt(S2n_1 / n);
mD2
# vystup = [1] 5.023958
mH2 = mean(x) + qt((1+0.95)/2,n-1) * sqrt(S2n_1 / n);
mH2
#vystup = [1] 5.116042
#2. uloha - otestujte, ci je "povodna" v priemere horsia ako "nova" (rychlost nacitavania webovych stranok)
povodna = c(2.5,2.8,2.3,2.2,2.7,2.1,2.2,2.4)
nova = c(2.6,2.8,2.6,2.6,2.7,2.5,2.3)
n1 = length(povodna)
n2 = length(nova)
n1
#vystup [1] 8
n2
#vystup [1] 7
#nerovnaka dlzka
#alternativna hypoteza -> priemerna rychlost noveho portalu je mensia ako povodna
var.test(povodna,nova)$p.value < 0.05
#vystup [1] FALSE
#A teda H0 nezamietame, disperzie su rovnake
t.test(povodna,nova,alternative="less",var.equal=TRUE)$p.value < 0.05
#vystup [1] FALSE
#vysledkom je - p hodnota > alpha a teda H0 nezamietame -> rychlost nacitania stranky je v priemere rovnaka
#3. uloha - spravte funkciu na test z 2. ulohy a otestujte to na tych istych udajoch
DvojVybAna <- function(x1,x2,alpha) {
varEquals = !var.test(x1,x2)$p.value < 0.05;
if(t.test(x1,x2,alternative="less",var.equal=varEquals,conf.level=alpha)$p.value < alpha) "H0 zamietame"
else "H0 nezamietame"
}
DvojVybAna(povodna, nova, 0.05)
#vystup: [1] "H0 nezamietame"
DvojVybAna(nova,povodna, 0.05)
#vystup : [1] "H0 nezamietame"
#4. uloha - urcte ktora funkcia lepsie aproximuje data: (exp(x) alebo log(x))
x = c(0.5,1.2,1.3,1.4,1.8,1.9);
y = c(4.297443,7.640234,8.338593,9.110400,13.099295,14.371789)
plot(x,y);
z1 = exp(x);
z2 = log(x);
y_z1 = lm(y~z1)$coefficients[1] + lm(y~z1)$coefficients[2] * exp(x)
lines(x,y_z1,col='red')
y_z2 = lm(y~z2)$coefficients[1] + lm(y~z2)$coefficients[2] * log(x)
lines(x,y_z2,col='blue')
#exp(x) lepsie popisuje data
#vidno to aj na datach:
y
#vystup [1] 4.297443 7.640234 8.338593 9.110400 13.099295 14.371789
y_z1
#vystup [1] 4.297443 7.640234 8.338593 9.110400 13.099295 14.371789
y_z2
#vystup [1] 3.119799 9.216623 9.774046 10.290139 12.040310 12.416837
#y a y_z1 su rovnake
#5. uloha na papieri - Dokazte ze ak S^2(n-1) je nestranny odhad disperzie, tak S^2(n) je uz vychyleny (teda nie je nestranny)