#Ucitavanje baze
library(haven)
disleksija <- read_sav("D:/Vita/Disleksija/Baze/disleksija_procisceno.sav")
View(disleksija)

library(dplyr)
## Warning: package 'dplyr' was built under R version 3.5.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.5.3
## -- Attaching packages --------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.1.0     v readr   1.2.1
## v tibble  2.1.3     v purrr   0.2.5
## v tidyr   0.8.2     v stringr 1.3.1
## v ggplot2 3.1.0     v forcats 0.3.0
## Warning: package 'tibble' was built under R version 3.5.3
## -- Conflicts ------------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(readxl)
library(Amelia)
## Warning: package 'Amelia' was built under R version 3.5.3
## Loading required package: Rcpp
## Warning: package 'Rcpp' was built under R version 3.5.3
## ## 
## ## Amelia II: Multiple Imputation
## ## (Version 1.7.5, built: 2018-05-07)
## ## Copyright (C) 2005-2019 James Honaker, Gary King and Matthew Blackwell
## ## Refer to http://gking.harvard.edu/amelia/ for more information
## ##
library(data.table)
## Warning: package 'data.table' was built under R version 3.5.2
## 
## Attaching package: 'data.table'
## The following object is masked from 'package:purrr':
## 
##     transpose
## The following objects are masked from 'package:dplyr':
## 
##     between, first, last
library(psycho)
## Warning: package 'psycho' was built under R version 3.5.2
library(ggplot2)
library(MASS)
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
library(DescTools)
## Warning: package 'DescTools' was built under R version 3.5.3
## 
## Attaching package: 'DescTools'
## The following object is masked from 'package:data.table':
## 
##     %like%
library(ggpubr)
## Warning: package 'ggpubr' was built under R version 3.5.2
## Loading required package: magrittr
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
## 
##     set_names
## The following object is masked from 'package:tidyr':
## 
##     extract
library(car)
## Warning: package 'car' was built under R version 3.5.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 3.5.2
## 
## Attaching package: 'car'
## The following object is masked from 'package:DescTools':
## 
##     Recode
## The following object is masked from 'package:purrr':
## 
##     some
## The following object is masked from 'package:dplyr':
## 
##     recode
library(tibble)
library(nnet)


df2 <- disleksija
summary(df2)
##  Brzo_imenovanje  Nizanje_kuglica  Jednominutno_citanje
##  Min.   : 20.00   Min.   : 1.000   Min.   :  3.0       
##  1st Qu.: 38.00   1st Qu.: 4.000   1st Qu.: 28.0       
##  Median : 45.00   Median : 5.000   Median : 46.0       
##  Mean   : 47.82   Mean   : 5.387   Mean   : 46.6       
##  3rd Qu.: 53.00   3rd Qu.: 6.000   3rd Qu.: 60.0       
##  Max.   :185.00   Max.   :12.000   Max.   :105.0       
##  Posturalna_stabilnost Dvominutni_speling Brojcani_niz_unazad
##  Min.   : 0.000        Min.   : 0.000     Min.   :0.000      
##  1st Qu.: 0.000        1st Qu.: 8.000     1st Qu.:2.000      
##  Median : 3.000        Median : 8.000     Median :3.000      
##  Mean   : 2.787        Mean   : 9.812     Mean   :2.482      
##  3rd Qu.: 4.000        3rd Qu.:12.000     3rd Qu.:3.000      
##  Max.   :23.000        Max.   :22.000     Max.   :8.000      
##  Citanje_besmislenog_teksta Jednominutno_pisanje Verbalna_fluentnost
##  Min.   : 0.00              Min.   : 0.000       Min.   : 0.000     
##  1st Qu.:46.75              1st Qu.: 5.000       1st Qu.: 6.000     
##  Median :60.00              Median : 7.000       Median : 9.000     
##  Mean   :53.74              Mean   : 8.067       Mean   : 8.922     
##  3rd Qu.:66.00              3rd Qu.:11.000       3rd Qu.:11.000     
##  Max.   :77.00              Max.   :24.000       Max.   :25.000     
##  Semanticka_fluentnost   Vokabular    
##  Min.   : 2.00         Min.   : 7.00  
##  1st Qu.:13.00         1st Qu.:12.00  
##  Median :16.00         Median :13.00  
##  Mean   :16.16         Mean   :13.13  
##  3rd Qu.:19.00         3rd Qu.:14.00  
##  Max.   :40.00         Max.   :16.00
str(df2)
## Classes 'tbl_df', 'tbl' and 'data.frame':    600 obs. of  11 variables:
##  $ Brzo_imenovanje           : num  44 42 47 48 40 59 40 39 52 41 ...
##   ..- attr(*, "format.spss")= chr "F8.0"
##  $ Nizanje_kuglica           : num  5 6 5 5 7 4 6 6 2 5 ...
##   ..- attr(*, "format.spss")= chr "F8.0"
##  $ Jednominutno_citanje      : num  28 41 33 24 52 81 36 26 32 28 ...
##   ..- attr(*, "format.spss")= chr "F8.0"
##  $ Posturalna_stabilnost     : num  1 4 6 4 4 4 8 4 5 8 ...
##   ..- attr(*, "format.spss")= chr "F8.0"
##  $ Dvominutni_speling        : num  8 8 7 8 8 8 7 8 8 8 ...
##   ..- attr(*, "format.spss")= chr "F8.0"
##  $ Brojcani_niz_unazad       : num  2 2 3 2 3 1 2 1 4 1 ...
##   ..- attr(*, "format.spss")= chr "F8.0"
##  $ Citanje_besmislenog_teksta: num  46 58 64 32 61 66 42 46 56 35 ...
##   ..- attr(*, "format.spss")= chr "F8.0"
##  $ Jednominutno_pisanje      : num  4 5 6 5 6 6 5 5 5 5 ...
##   ..- attr(*, "format.spss")= chr "F8.0"
##  $ Verbalna_fluentnost       : num  4 7 7 5 14 4 5 8 5 5 ...
##   ..- attr(*, "format.spss")= chr "F8.0"
##  $ Semanticka_fluentnost     : num  9 15 12 12 16 16 12 11 14 12 ...
##   ..- attr(*, "format.spss")= chr "F8.0"
##  $ Vokabular                 : num  13 14 13 12 13 13 14 14 14 12 ...
##   ..- attr(*, "format.spss")= chr "F8.0"
df2 %<>% mutate_if(is.character,as.numeric)

#Standardizacija varijabli
df2 <- disleksija %>% 
  psycho::standardize() 


#Prikaz distribucija za svaki subtest instrumenta DST-j
df2 %>% 
  dplyr::select(Brzo_imenovanje, 
                Nizanje_kuglica, 
                Jednominutno_citanje, 
                Posturalna_stabilnost, 
                Dvominutni_speling, 
                Brojcani_niz_unazad, 
                Citanje_besmislenog_teksta, 
                Jednominutno_pisanje, 
                Verbalna_fluentnost,
                Semanticka_fluentnost,
                Vokabular) %>% 
  gather(Variable, Value) %>% 
  ggplot(aes(x=Value, fill=Variable)) +
  geom_density(alpha=0.3) +
  geom_vline(aes(xintercept=0)) +
  xlim(-3,3) +
  xlab("Standardizovani z-skor")+
  ylab("gustina")+
  ggtitle("Distribucija subtestova baterije DST-J")+
  labs(fill = "Subtestovi baterije DST-J")+
  theme_bw() +
  scale_fill_brewer(palette="Spectral")
## Warning: Removed 68 rows containing non-finite values (stat_density).

#Pojedinacni prikazi ucestalosti - nestandardizovani skrovi

df2 <- disleksija
df2 %<>% mutate_if(is.character,as.numeric)

df2 %>% 
  dplyr::select(Brzo_imenovanje, 
                Nizanje_kuglica, 
                Jednominutno_citanje) %>% 
  gather(Variable, Value) %>% 
  ggplot(aes(x=Value, fill=Variable)) +
  geom_bar(alpha=0.9, position = "dodge") +
  xlim(-3,80) +
  xlab("Postignuce")+
  ylab("Broj ispitanika")+
  ggtitle("Distribucija subtestova baterije DST-J")+
  labs(fill = "Subtestovi baterije DST-J")+
  theme_bw() +
  scale_fill_brewer(palette = "Paired")
## Warning: Removed 75 rows containing non-finite values (stat_count).
## Warning: Removed 1 rows containing missing values (geom_bar).

df2 %>% 
  dplyr::select(Posturalna_stabilnost, 
                Dvominutni_speling, 
                Brojcani_niz_unazad) %>% 
  gather(Variable, Value) %>% 
  ggplot(aes(x=Value, fill=Variable)) +
  geom_bar(alpha=0.9, position = "dodge") +
  xlim(-0,20) +
  xlab("Postignuce")+
  ylab("Broj ispitanika")+
  ggtitle("Distribucija subtestova baterije DST-J")+
  labs(fill = "Subtestovi baterije DST-J")+
  theme_bw() +
  scale_fill_brewer(palette="Spectral")
## Warning: Removed 29 rows containing non-finite values (stat_count).
## Warning: Removed 2 rows containing missing values (geom_bar).

df2 %>% 
  dplyr::select(Citanje_besmislenog_teksta, 
                Jednominutno_pisanje, 
                Verbalna_fluentnost,
                Semanticka_fluentnost,
                Vokabular) %>% 
  gather(Variable, Value) %>% 
  ggplot(aes(x=Value, fill=Variable)) +
  geom_bar(alpha=0.7, position = "dodge") +
  geom_vline(aes(xintercept=13)) +
  xlim(-3,50) +
  xlab("Postignuce")+
  ylab("Broj ispitanika")+
  ggtitle("Distribucija subtestova baterije DST-J")+
  labs(fill = "Subtestovi baterije DST-J")+
  theme_bw() +
  scale_fill_brewer(palette="Paired")
## Warning: Removed 411 rows containing non-finite values (stat_count).
## Warning: Removed 1 rows containing missing values (geom_bar).

df2 %>% 
  dplyr::select(Verbalna_fluentnost, 
                Semanticka_fluentnost,
                Brzo_imenovanje) %>% 
  gather(Variable, Value) %>% 
  ggplot(aes(x=Value, fill=Variable)) +
  geom_bar(alpha=0.7, position = "dodge") +
  geom_vline(aes(xintercept=13)) +
  xlim(-3,80) +
  xlab("Postignuce")+
  ylab("Broj ispitanika")+
  ggtitle("Distribucija subtestova baterije DST-J")+
  labs(fill = "Subtestovi baterije DST-J")+
  theme_bw() +
  scale_fill_brewer(palette="Paired")
## Warning: Removed 20 rows containing non-finite values (stat_count).

## Warning: Removed 1 rows containing missing values (geom_bar).