This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(survey) | |
library(ggplot2) | |
library(dplyr) | |
library(xtable) | |
library(tidyr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# jeżeli nie jest zainstalowany pakiet to instalujemy | |
# library(devtools) | |
# install_github('pbiecek/PISA2009lite') | |
library(PISA2009lite) | |
studenci <- student2009 | |
szkoly <- school2009 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tab <- as.data.frame(table(szkoly$CNT)) | |
names(tab) <- c('Kraje','N') | |
summary(tab$N) | |
tab$Kolor <- as.factor(ifelse(tab$Kraje=='Poland',1,2)) | |
ggplot(data = tab, | |
aes(x = reorder(Kraje,N), | |
y = N, | |
fill = Kolor)) + | |
geom_bar(stat='identity', | |
colour='black') + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tab <- as.data.frame(table(studenci$CNT)) | |
names(tab) <- c('Kraje','N') | |
summary(tab$N) | |
tab$Kolor <- as.factor(ifelse(tab$Kraje=='Poland',1,2)) | |
ggplot(data = tab, | |
aes(x = reorder(Kraje,N), | |
y = N, | |
fill = Kolor)) + | |
geom_bar(stat='identity', | |
colour='black') + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cnames <- names(studenci) | |
attr(studenci$PV1MATH,'value.labels') <- NULL | |
attr(studenci$PV2MATH,'value.labels') <- NULL | |
attr(studenci$PV3MATH,'value.labels') <- NULL | |
attr(studenci$PV4MATH,'value.labels') <- NULL | |
attr(studenci$PV5MATH,'value.labels') <- NULL | |
attr(studenci$W_FSTUWT,'value.labels') <- NULL | |
for (i in which(cnames=='W_FSTR1'):which(cnames=='W_FSTR80')) { | |
attr(studenci[,i],'value.labels') <- NULL | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
badanie <- studenci %>% | |
select(CNT, ## kraj | |
SCHOOLID, ## identyfikator szkoły | |
ST04Q01, ## płeć | |
PV1MATH:PV5MATH, ## wartości PV | |
W_FSTR1:W_FSTR80, ## wagi replikacyjne | |
W_FSTUWT ## wagi ostateczne | |
) %>% | |
group_by(CNT) %>% | |
do(schemat = svrepdesign(ids= ~SCHOOLID, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wynik <- badanie %>% | |
do(data.frame(svymean(~PV1MATH,design = .$schemat))) | |
wynik$CNT <- badanie$CNT | |
names(wynik)[1] <- 'PV1MATH' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### przedział ufności | |
alpha <- 0.05 | |
z_alpha <- qnorm(1-alpha/2) | |
wynik$Kolor <- ifelse(wynik$CNT=='Poland','red','black') | |
### wykresy | |
ggplot(data = wynik, | |
aes(x=reorder(CNT,PV1MATH), | |
y=PV1MATH)) + | |
geom_errorbar(aes(ymin=PV1MATH-z_alpha*SE, | |
ymax=PV1MATH+z_alpha*SE)) + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wynik_matematyka <- badanie %>% | |
do(data.frame(PV1 = svymean(~PV1MATH,design = .$schemat), | |
PV2 = svymean(~PV2MATH,design = .$schemat), | |
PV3 = svymean(~PV3MATH,design = .$schemat), | |
PV4 = svymean(~PV4MATH,design = .$schemat), | |
PV5 = svymean(~PV5MATH,design = .$schemat))) %>% | |
ungroup() %>% | |
mutate(CNT = badanie$CNT) %>% | |
gather(Stat,Value,-CNT) %>% | |
separate(Stat,c('PV','STAT'),sep='\\.') %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wynik_matematyka$Kolor <- ifelse(wynik_matematyka$CNT=='Poland','red','black') | |
OECD_mean <- mean(wynik_matematyka$PV) | |
### wykresy | |
ggplot(data = wynik_matematyka, | |
aes(x=reorder(CNT,PV), | |
y=PV)) + | |
geom_errorbar(aes(ymin=PV-z_alpha*SE, | |
ymax=PV+z_alpha*SE)) + | |
geom_point(colour='red') + | |
theme_bw() + |
OlderNewer