The PISA2003lite package is released. Let’s explore!

Today I’m going to show how to install PISA2003lite, what is inside and how to use this R package. Datasets from this package will be used to compare student performance in four math sub-areas across different countries.
At the end of the day we will find out in which areas top performers from different countries are stronger and in which they are weaker.

In the post ,,The PISA2009lite is released” an R package PISA2009lite with data from PISA 2009 was introduced. The same approach was applied to convert data from PISA 2003 into an R package. PISA (Programme for International Student Assessment) is a worldwide study focused on measuring scholastic performance on mathematics, science and reading of 15-year-old school pupils.
The study performed in 2003 was focused on mathematics. Note, that PISA 2012 was focused on mathematics as well, so it will be very interesting to compare results between both studies [when only date from PISA 2012 data become public].

The package PISA2003lite is on github, so to install it you just need

library(devtools)
 
# don't download 120MB of compressed data if the package is already installed
if (length(find.package("PISA2003lite", quiet = TRUE)) == 0) 
     install_github("PISA2003lite", "pbiecek")
 
# and load the package
library(PISA2003lite)

You will find three data sets in this package. These are: data from student questionnaire, school questionnaire and cognitive items.

dim(student2003)
## [1] 276165    407
 
dim(school2003)
## [1] 10274   192
 
dim(scoredItem2003)
## [1] 276165    178

Let's plot something! What about strong and weak sides in particular MATH sub-areas?
In this dataset the overall performance is represented by five plausible values: PV1MATH, PV2MATH, PV3MATH, PV4MATH, PV5MATH. But for each student also performance in four sub-scales is measured. These sub-scales are: Space and Shape, Change and Relationships, Uncertainty and Quantity (plausible values: PVxMATHx, x=1..5, y=1..4).

Let's find out how good are top performers in each country in different sub-scales.
For every country, let's calculate the 95% quantile of performance in every subscale.

res <- by(student2003[,c("PV1MATH1", "PV1MATH2", "PV1MATH3", "PV1MATH4")], student2003$COUNTRY, function(x) {
  apply(x, 2, quantile, 0.95)
})
res <- t(simplify2array(res))

Just few more lines to add the proper row- and col- names.

subAreasNames <- sapply(strsplit(student2003dict[colnames(res)], split = " *- *"), `[`, 2)
colnames(res) <- subAreasNames

And here are results. Table looks nice, but there is so many numbers.
Let's use PCA to reduce dimensionality of the data.

res
 
##                    Space and Shape Change and Relationships Uncertainty
## Australia                    687.5                    679.8       687.2
## Austria                      706.3                    669.0       652.5
## Belgium                      704.8                    712.2       692.1
## Brazil                       513.7                    546.0       523.2
## Canada                       664.8                    674.7       672.0
## Czech Republic               744.4                    702.3       673.4
## Denmark                      674.2                    666.2       661.4
## Finland                      685.7                    694.6       679.1
## France                       675.9                    677.9       653.9
## Germany                      684.4                    679.0       649.0
## Greece                       595.7                    604.9       601.7
## Hong Kong-China              733.4                    702.0       712.8
## Hungary                      660.3                    656.3       631.4
## Iceland                      655.1                    663.7       678.9
## Indonesia                    508.1                    506.8       497.5
## Ireland                      632.8                    647.1       664.8
## Italy                        675.8                    644.5       641.2
## Japan                        724.9                    707.6       682.5
## Korea                        743.2                    705.4       680.9
## Latvia                       656.1                    651.9       613.7
## Liechtenstein                701.3                    708.5       670.5
## Luxembourg                   653.9                    652.5       649.7
## Macao-China                  688.7                    674.3       674.8
## Mexico                       535.8                    534.8       535.0
## Netherlands                  676.9                    704.1       692.2
## New Zealand                  697.1                    693.5       700.1
## Norway                       651.4                    646.2       675.9
## Poland                       668.4                    654.0       632.2
## Portugal                     609.4                    623.7       604.8
## Russian Federation           666.2                    644.6       593.7
## Slovak Republic              702.8                    667.7       622.8
## Spain                        628.9                    642.3       632.1
## Sweden                       657.9                    680.9       672.8
## Switzerland                  701.7                    684.5       663.8
## Thailand                     590.9                    583.9       561.1
## Tunisia                      513.5                    510.8       485.6
## Turkey                       596.9                    629.8       613.0
## United Kingdom               661.7                    671.3       672.8
## United States                631.3                    639.3       649.8
## Uruguay                      579.3                    601.8       582.8
##                    Quantity
## Australia             671.3
## Austria               655.2
## Belgium               692.2
## Brazil                542.8
## Canada                668.2
## Czech Republic        700.9
## Denmark               660.5
## Finland               681.4
## France                657.1
## Germany               675.1
## Greece                605.8
## Hong Kong-China       699.2
## Hungary               645.5
## Iceland               666.5
## Indonesia             509.8
## Ireland               645.5
## Italy                 662.3
## Japan                 683.5
## Korea                 679.3
## Latvia                619.4
## Liechtenstein         675.9
## Luxembourg            647.2
## Macao-China           669.7
## Mexico                562.0
## Netherlands           681.7
## New Zealand           670.9
## Norway                646.2
## Poland                636.2
## Portugal              619.3
## Russian Federation    625.8
## Slovak Republic       663.3
## Spain                 652.3
## Sweden                655.5
## Switzerland           669.2
## Thailand              591.4
## Tunisia               520.1
## Turkey                611.3
## United Kingdom        664.2
## United States         640.7
## Uruguay               603.4
 
par(xpd = NA)
biplot(prcomp(res))

plot of chunk unnamed-chunk-5

Quite interesting!
It looks like first PCA coordinate is an average over all sub-scales. Thus on the plot above the further left, the better are top performers in all sub-scales.
But the second PCA coordinate differentiates between countries in which top performers are better in 'Space and Shape' [top] versus 'Uncertainty’ [bottom]. Compare this plot with the table above, and you will see that for Czech Republic, Slovak Republic, Russian Federation the 'Space and Shape' is the strongest side of top performers.
On the other side Sweden, USA, Norway, Ireland score higher in 'Uncertainty’.

As you may easily check, that results are pretty similar if you focus on averages or performers from the bottom tail.

Which direction is better? Of course it depends. But since ,,change is the only sure thing'', understanding of uncertainty might be useful.

Raport o stanie bezpieczeństwa cyberprzestrzeni RP 2012

Krzysiek T. podesłał mi interesujący raport ,,Raport o stanie bezpieczeństwa cyberprzestrzeni RP 2012” (dostępny na tej stronie). Treść ciekawa ale miejscami przerażająca (nie sądziłem, że w 2012 roku kilkanaście procent stron rządowych jest podatnych na SQL-injection). Pod koniec raportu opisanych jest kilka przykładów udanych ataków, krótko pisząc ciekawa lektura.

Ale niestety pod kątem prezentacji danych niedopracowana.
Pomijam kwestię wykresów kołowych, które występują w różnych kolorach, rozdzielczościach i pod różnymi kątami (oczywiście w 3D, ale czasem bardziej płasko a czasem mniej). Wykresom kołowym mówimy dzisiaj stanowcze 'nie’ i nie będziemy ich tu pokazywać. Za to poniżej pokażemy cztery wykresy z tego raportu, które mają na sumieniu poważniejszy błąd, niż fałszywa perspektywa utrudniająca odczytanie poprawne wartości i zależności.

Ten ciekawy wykres noszący tytuł 'Źródła zgłoszonych incydentów’ uniemożliwia porównanie źródeł zgłoszonych incydentów [;-)]. Nie sposób odczytać z którego źródła pochodzi więcej zgłoszeń incydentów, ponieważ wszystkie sumują się do 100% (prawdopodobnie, ech ta perspektywa). W tej postaci trudno odczytać jakąś historię z tego wykresu. Nawet stwierdzenie, że zgłoszenia z systemów najczęściej były zgłaszane w drugim kwartale trudno jest obronić. Być może między kwartałami liczba zgłoszeń bardzo się różniła. Jest wykres, ale nie ma do niego historii.

Czytaj dalej Raport o stanie bezpieczeństwa cyberprzestrzeni RP 2012

The PISA2009lite package is released

This post introduces a new R package named PISA2009lite. I will show how to install this package, what is inside and how to use it.

Introduction

PISA (Programme for International Student Assessment) is a worldwide study focused on measuring performance of 15-year-old school pupils. More precisely, scholastic performance on mathematics, science and reading is measured in more than 500 000 pupils from 65 countries.

First PISA study was performed in 2000, second in 2003, and then in 2006, 2009 and the last one in 2012. Data from the last study will be made public on December 2013. Data from previous studies are accessible through the PISA website http://www.oecd.org/pisa/.
Note that this data set is quite large. This is why the PISA2009lite package will use more than 220MB of your disk [data sets are compressed on disk] and much more RAM [data sets will be decompressed after [lazy]loading to R].

Let's see some numbers. In PISA 2009 study, number of examined pupils: 515 958 (437 variables for each pupil), number of examined parents: 106 287 (no, their questions are not related to scholastic performance), number of schools from which pupils were sampled: 18 641. Pretty large, complex and interesting dataset!

On the official PISA webpage there are instructions how to read data from 2000-2009 studies into SAS and SPSS statistical packages. I am transforming these dataset to R packags, to make them easier to use for R users.
Right now, PISA2009lite is mature enough to share it. There are still many things to correct/improve/add. Fell free to point them [or fix them].

This is not the first attempt to get the PISA data available for R users. On the github you can find 'pisa' package maintained by Jason Bryer (https://github.com/jbryer/pisa) with data from PISA 2009 study.
But since I need data from all PISA editions, namely 2000, 2003, 2006, 2009 and 2012 I've decided to create few new packages, that will support consistent way to access data from different PISA studies.

Open the R session

The package is on github, so in order to install it you need just

library(devtools)
# dont download 220MB of compressed data if the package is already
# installed
if (length(find.package("PISA2009lite", quiet = TRUE)) == 0) install_github("PISA2009lite", 
    "pbiecek")

now PISA2009lite is ready to be loaded

library(PISA2009lite)

You will find five data sets in this package [actually ten, I will explain this later]. These are: data from student questionnaire, school questionnaire, parent questionnaire, cognitive items and scored cognitive items.

dim(student2009)
## [1] 515958    437
dim(parent2009)
## [1] 106287     90
dim(school2009)
## [1] 18641   247
dim(item2009)
## [1] 515958    273
dim(scoredItem2009)
## [1] 515958    227

You can do a lot of things with these data sets. And I am going to show some examples in next posts.

Country ranking in just few lines of code

But as a warmer let's use it to calculate average performance in mathematics for each country.

Note that student2009$W_FSTUWT stands for sampling weights, student2009$PV1MATH stands for first plausible value from MATH scale while student2009$CNT stands for country

means <- unclass(by(student2009[, c("PV1MATH", "W_FSTUWT")], student2009$CNT, 
                        function(x) weighted.mean(x[, 1], x[, 2])))
# sort them
means <- sort(means)

And plot it.


dotchart(means, pch = 19)
abline(v = seq(350, 600, 50), lty = 3, col = "grey")

plot of chunk unnamed-chunk-6

Regionalizmy, jak je pięknie pokazać?

Dziś kontynuujemy temat ,,informacja jest piękna”.
Joshua Katz używając R i biblioteki Shiny przedstawił graficznie zróżnicowanie dialektów w Stanach Zjednoczonych.

Przykładowo mapa poniżej pokazuje obszary, w których na określenie gazowanego, słodzonego napoju używa się częściej słowa 'soda’ (czerwony) 'pop’ (niebieski) lub 'coke’ (zielony) [pytanie 105].

Czytaj dalej Regionalizmy, jak je pięknie pokazać?

Test Cressie-Read, czyli jak mierzyć zależności pomiędzy parą zmiennych jakościowych

Po raz kolejny gościmy na blogu wpis Krzyśka Trajkowskiego [wielkie dzięki za wsparcie!!!]. Tym razem napisze on o teście Cressie-Read oraz przedstawi przykłady wywołania tego testu z pakietu CressieReadTest dla programu R. Warto zaznaczyć, że Krzysiek jest autorem tego pakietu.

Pakiet CressieReadTest można pobrać z tej strony.

Poniżej przedstawiony jest opis testu w formie strony html. Można też ten opis pobrać jako plik pdf z tej strony.

Statystyka Cressie-Read jest uogólnieniem kilku innych statystyk, popularnie wykorzystywanych w badaniu tablic kontyngencji dla dwóch zmiennych ilościowych. Warto więc się z nią zaznajomić.

Test Cressie-Read

Krzysztof Trajkowski

Czytaj dalej Test Cressie-Read, czyli jak mierzyć zależności pomiędzy parą zmiennych jakościowych

Czego najlepiej użyć do wizualizacji danych i analiz statystycznych?

Program R aspiruje do miana lidera zarówno jeżeli chodzi o statystyczną analizę danych jak i wizualizację danych.
Ale nie tylko R, podobne ambicje ma SAS [który zresztą przez długi czas był liderem jeżeli chodzi o analizy statystyczne], Stata, SPSS, Statistica, toolboxy Pythona, Matlaba, Mathematica, Gretla, Weki, Orange, Java, Julia, biblioteka D3 i dziesiątek innych większych i mniejszych pakietów czy bibliotek.

Które z tych narzędzi jest prawdziwym liderem?

Za miesiąc, 10 lipca, w Hiszpanii będzie miała miejsce kolejna coroczna konferencja użytkowników R o nazwie useR!
W tym roku podczas konferencji organizowane są dwa konkursy, na najlepszą wizualizację danych i najtrafniejsze analizy danych wykonane z użyciem programu R.

Co będzie wynikiem tego konkursu? Otóż zobaczymy czy pasjonaci R stworzą wizualizacje i analizy danych, które rzucą użytkowników innych pakietów na kolana.

Więcej o regułach konkursu przeczytać można tutaj lub tutaj.

Analizy i wizualizacja powinny dotyczyć jednego lub dwóch zbiorów danych przygotowanych przez organizatorów. Jeden dotyczy trzech sezonów formuły 1. Drugi zbiór danych dotyczy pięciu sezonów ligi piłki nożnej w Hiszpanii.

Co Polska importuje a co eksportuje?

Kilka dni temu Alek J. podesłał mi ciekawy projekt wykonany przez MIT media lab (link do media labu, tak, MIT, jedna z najlepszych na świecie uczelni technicznych, ma media lab pracujący nad technikami wizualizacji danych. Co więcej to w MIT powstał pierwszy media lab).

Projekt nazywa się ,,The Observatory of Economic Complexity”, pozwala na przedstawienie wymiany produktów pomiędzy państwami, przedstawienie w bardzo prosty i interesujący sposób.

Ten portal pozwala na zobaczenie jak wygląda struktura importu, eksportu rozmaitych krajów w różnych latach.

Świetnie przygotowana praca magisterska [!!!] udostępniona na wolnej licencji.