PACKAGES

require("tidyverse")
require("lubridate") #for dates
require("knitr")

DATA CLEANING

Data in https://docs.google.com/spreadsheets/d/154tcURPHwgmGcmndhQyEIT_dLzmbA_ZPSAKZTwHyGgw/edit?usp=sharing

Main dataset

Size of the dataset in rows, columns

df <- read.csv("2016_prevalence_Latvia.csv", header = T, sep = ";", encoding = "UTF8")
dim(df) #check size of the dataset rows, columns
[1] 2904  427

Fix dates

df$X2..Examination.date <- as.Date(df$X2..Examination.date, format = "%m/%d/%Y")
df$X4..Birth.date <- as.Date(df$X4..Birth.date, format = "%m/%d/%Y")
df <- df %>% 
  mutate(Age = as.numeric(difftime(as.Date(X2..Examination.date), as.Date(X4..Birth.date),
                                   unit="weeks"))/52.25)

Age statistics of the original dataset

summarise(df,  "Mean age" = mean(Age), "Min age" = min(Age), "Max age" = max(Age))

Unselect the kappa dataset

df <- df %>% 
  filter(X3.d.Examination.time..forst.or.second. !=2)
dim(df) #check size of the dataset. 222 observations removed. Original dataset 2904
[1] 2682  427

Select only the age = 12

df <- df %>% 
  filter(Age >=12, Age <13)
dim(df)
[1] 2138  427
summarise(df,  "Mean age" = mean(Age), "Min age" = min(Age), "Max age" = max(Age))

Everything ready now

df <- df %>% 
  rename(RegionsKods = X3.a.Region) %>% 
  rename(SkolasKods = X3.b.School)
Codes_Skolas <- read_csv("Codes - Skolas.csv")
Codes_Region <- read_csv("Codes - Region.csv")
df <- df %>% 
  left_join(Codes_Region, by="RegionsKods") %>% 
  left_join(Codes_Skolas, by="SkolasKods")
rm(Codes_Region)
rm(Codes_Skolas)

DESCRIPTIVE

Total children

addmargins(table(df$X1..Dzimums))

Meitene    Z?ns     Sum 
   1075    1061    2136 

There must be 2138 but there are 2316. Hence, I will subset to extract the rows without Dzimums

REMOVE AFTER CLEANING ————————————-

# new_DF <- df[is.na(df$X1..Dzimums),]
# write.csv(new_DF, "WithoutDzimums.csv")

Region & School

tb
                                                  
                                                   Kurzeme Latgale Pierīga Rīga Vidzeme Zemgale  Sum
  Āgenskalna sākumskola                                  0       0       0   64       0       0   64
  Aizkraukles pilsētas sākumskola                        0       0       0    0       0      49   49
  Alūksnes novada vidusskola                             0       0       0    0       8       0    8
  Andreja Pumpura Rīgas 11. pamatskola                   1       0       0   28       0       0   29
  Cēsu pilsētas pamatskola                               0       0       0    0      48       0   48
  Cēsu pilsētas Pastariņa sākumskola                     0       0       0    0      15       0   15
  Daugavpils 10. vidusskola                              0      42       0    0       0       0   42
  Daugavpils 12. vidusskola                              0      27       0    0       0       0   27
  Daugavpils Krievu vidusskola - licejs                  0      46       0    0       0       0   46
  Dzērves pamatskola                                     6       0       0    0       0       0    6
  Ērgļu vidusskola                                       0       0       0    0      13       0   13
  Gulbenes 2. vidusskola                                 0       0       0    0      34       0   34
  Iecavas internātpamatskola                             0       0       0    0       0      12   12
  Ikšķiles vidusskola                                    0       0      46    0       0       0   46
  Ilūkstes 1. vidusskola                                 0      10       0    0       0       0   10
  Indras vidusskola                                      0       9       0    0       0       0    9
  J. Endzelīna Kauguru pamatskola                        0       0       0    0       6       0    6
  Jaunpiebalgas vidusskola                               0       0       0    0      19       0   19
  Jēkabpils pamatskola                                   0       0       0    0       0      67   67
  Jelgavas 2. pamatskola                                 0       0       0    0       0      35   35
  Jumpravas vidusskola                                   0       0      17    0       0       0   17
  Jūrmalas pilsētas Lielupes vidusskola                  0       0      10    0       0       0   10
  Jūrmalas pilsētas Mežmalas vidusskola                  0       0      17    0       0       0   17
  Kalnciema vidusskola                                   0       0       0    0       0      12   12
  Kandavas Kārļa Mīlenbaha vidusskola                    0       0      29    0       0       0   29
  Ķeipenes pamatskola                                    0       0       8    0       0       0    8
  Ķekavas vidusskola                                     0       0      68    0       0       0   68
  Krāslavas Varavīksnes vidusskola                       0      33       0    0       0       0   33
  Krimuldas vidusskola                                   0       0      21    0       0       0   21
  Kuldīgas Centra vidusskola                            26       0       0    0       0       0   26
  Kuldīgas Mākslas un humanitāro zinību vidusskola      18       0       0    0       0       0   18
  Lapmežciema pamatskola                                 0       0       3    0       0       0    3
  Lejasstrazdu sākumskola                                0       0       0    0       0       4    4
  Liepājas pilsētas 12. vidusskola                      35       0       0    0       0       0   35
  Liepājas Raiņa 6. vidusskola                          47       0       0    0       0       0   47
  Limbažu sākumskola                                     0       0      16    0       0       0   16
  Majoru vidusskola                                      0       0      14    0       0       0   14
  Mērsraga vidusskola                                    9       0       0    0       0       0    9
  Mores pamatskola                                       0       0       4    0       0       0    4
  Neretas Jāņa Jaunsudrabiņa vidusskola                  0       0       0    0       0       4    4
  Olaines 2. vidusskola                                  0       0      40    0       0       0   40
  Ozolnieku vidusskola                                   0       0       0    0       0      28   28
  Privātā pamatskola Gaismas tilts 97                    0       0       6    0       0       0    6
  Privātā pamatskola Maksima                             0       0       0    3       0       0    3
  Puškina licejs                                         0       0       0   45       0       0   45
  Rankas pamatskola                                      0       0       0    0       6       0    6
  Rēzeknes 3. vidusskola                                 0      17       0    0       0       0   17
  Rēzeknes 5. vidusskola                                 0      26       0    0       0       0   26
  Rēznas pamatskola                                      0       9       0    0       0       0    9
  Rīgas 22. vidusskola                                   0       0       0   22       0       0   22
  Rīgas 34. vidusskola                                   0       0       0   59       0       0   59
  Rīgas 46. vidusskola                                   0       0       0   32       0       0   32
  Rīgas 64. vidusskola                                   1       0       0   61       0       0   62
  Rīgas 86. vidusskola                                   0       0       0   39       0       0   39
  Rīgas Austrumu vsk bij. Rīgas 24. pamatskola           0       0       0   14       0       0   14
  Rīgas Hanzas vidusskola                                0       0       0   49       0       0   49
  Rīgas Jāņa Poruka vidusskola                           0       0       0   25       0       0   25
  Rīgas Klasiskā ģimnāzija                               0       0       0   82       0       0   82
  Rīgas Mūzikas internātvidusskola                       0       0       0   12       0       0   12
  Rīgas Ostvalda vidusskola                              0       0       0   37       0       0   37
  Rīgas Pļavnieku pamatskola                             1       0       0   32       0       0   33
  Rīgas Valda Zālīša sākumskola                          0       0       0   32       0       0   32
  Ropažu vidusskola                                      0       0      25    0       0       0   25
  Sabiles vidusskola                                     6       0       0    0       0       0    6
  Salas vidusskola                                       0       0       0    0       0      18   18
  Saldus 2. vidusskola                                  18       0       0    0       0       0   18
  Saldus novada pašvaldības Druvas vidusskola           11       0       0    0       0       0   11
  Saldus novada pašvaldības Lutriņu pamatskola           5       0       0    0       0       0    5
  Salienas vidusskola                                    0       6       0    0       0       0    6
  Siguldas pilsētas vidusskola                           0       0      40    0       0       0   40
  Smārdes pamatskola                                     0       0      12    0       0       0   12
  Špoģu vidusskola                                       0      24       0    0       0       0   24
  Stacijas pamatskola                                    0       4       0    0       0       0    4
  Staiceles vidusskola                                   0       0      11    0       0       0   11
  Stāķu pamatskola                                       0       0       0    0      11       0   11
  Sūnu pamatskola                                        0       0       0    1       0       7    8
  Talsu sākumskola                                      34       0       0    0       0       0   34
  Tilžas vidusskola                                      0       9       0    0       0       0    9
  Tumes vidusskola                                       0       0      15    0       0       0   15
  Uzvaras vidusskola                                     0       0       0    0       0       4    4
  Valmieras Viestura vidusskola                          0       0       0    0      41       0   41
  Vandzenes pamatskola                                   8       0       0    0       0       0    8
  Vārmes pamatskola                                     15       0       0    0       0       0   15
  Vecumnieku vidusskola                                  0       0       0    0       0      20   20
  Ventspils 2. pamatskola                               11       0       0    0       0       0   11
  Ventspils Centra sākumskola                           42       0       0    0       0       0   42
  Verēmu pamatskola                                      0       6       0    0       0       0    6
  Viesītes vidusskola                                    0       0       0    0       0      21   21
  Viļānu vidusskola                                      0      27       0    0       0       0   27
  Virgas pamatskola                                      8       0       0    0       0       0    8
  Zaļenieku komerciālā un amatniecības vidusskola        0       0       0    0       0      12   12
  Zemgales vidusskola                                    0       8       0    0       0       0    8
  Sum                                                  302     303     402  637     201     293 2138
Sepal.Length Sepal.Width Petal.Length
5.1 3.5 1.4
4.9 3.0 1.4
4.7 3.2 1.3
4.6 3.1 1.5
5.0 3.6 1.4
5.4 3.9 1.7

Citation

LS0tDQp0aXRsZTogIlByZXZhbGVuY2UgQ2FyaWVzIExhdHZpYSINCm91dHB1dDoNCiAgaHR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