---
title: "Item Analysis Report"
date: '`r Sys.Date()`'
output: 
    pdf_document:
       number_sections: true
       toc: true
subtitle: |
  This Report was generated by ShinyItemAnalysis package app version `r packageVersion("ShinyItemAnalysis")`
  
  Copyright 2016 Patricia Martinkova, Adela Drabinova, Ondrej Leder and Jakub Houdek.
  
  Supported by Czech Science Foundation under grant number [GJ15-15856Y](http://www.cs.cas.cz/martinkova/psychometrics.html)
params:
  a: NA
  k: NA
  gr: NA
  results: NA
  histogram_totalscores: NA
  corr_plot: NA
  scree_plot: NA
  difPlot: NA
  hist_distractor_by_group: NA
  graf: NA
  logreg: NA
  zlogreg: NA
  zlogreg_irt: NA
  nlsplot: NA
  multiplot: NA
  wrightMap: NA
  irt: NA
  irtiic: NA
  irttif: NA
  irtcoef: NA
  irtfactor: NA
  resultsgroup: NA
  histbyscoregroup0: NA
  histbyscoregroup1: NA
  deltaplot: NA
  DP_text_normal: NA
  DIF_logistic_print: NA
  DIF_logistic_plot: NA
  plot_DIF_logistic: NA
  plot_DIF_logistic_IRT_Z: NA
  plot_DIF_NLR: NA
  plot_DIF_IRT_Lord: NA
  plot_DIF_IRT_Raju: NA
  itemexam: NA
  itemReport: NA
  irt_type: NA
  model_DDF_print: NA
  plot_DDFReportInput: NA
  isGroupPresent: NA
  groupie: NA
---
\pagebreak

# Summary Report

## Summary of Total Scores

```{r echo=FALSE, results="hide"}

library(gridExtra)
params$irt_report
table=params$results
table=round(table, digits=4)
colnames(table)=NULL
table=tableGrob(t(table))
hist=ggplotGrob(params$histogram_totalscores)
lay=rbind(c(1,1,1),
          c(2,2,2),
          c(2,2,2),
          c(2,2,2),
          c(2,2,2))
grid.arrange(table, hist, ncol=1, top="Basic Summary and Histogram", layout_matrix=lay)

```

## Correlation Structure

```{r echo=FALSE, fig.height=4}
corrplot(params$corr_plot)
#grid.arrange(corrplot(params$corr_plot), top="Polychoric Correlation Heat Map")
params$scree_plot+ggtitle("Scree Plot")
```


\pagebreak


# Traditional Item Analysis Report

## Item Analysis

```{r echo=FALSE, results="hide"}
params$difPlot
```

```{r echo=FALSE, fig.height=8}
#params$itemexam
table=params$itemexam
table=format(round(table, 4), nsmall=3)
colnames(table)=c("Item", "Diff.", "SD", "D. ULI", "D. RIT", "D. RIR", "Alpha Drop")
rownames(table)=NULL
#grid.table(table)
table
```

## Distractor Analysis

```{r echo=FALSE, results="hide", fig.width=10}
for (i in 1:length(params$graf)) {
grid.arrange(params$graf[[i]], params$multiplot[[i]], ncol=2
             #,top=textGrob(paste0("Distractor and Multinomial Plots for item ",i), gp=gpar(fontsize=15))
             #,heights=unit(1.0, "npc")
             )
}
```


\pagebreak

#IRT Model

```{r echo=FALSE, results="hide"}
if (params$irt_type=="rasch") {
  head=" Rasch model"
}

if (params$irt_type=="1pl") {
head=" 1PL IRT model"
eq="$ {P}(Y_{ij} = 1|\theta_{i},a,b_j) =\frac{e^{a(\theta_i-b_j)}}{1+e^{a(\theta_i-b_j)}} $"
}

if (params$irt_type=="2pl") {
head=" 2PL IRT model"
eq="$$ {P}(Y_{ij} = 1|\theta_{i},a_j,b_j) = \frac{e^{a_j(\theta_i-b_j)}}{1+e^{a_j(\theta_i-b_j)}}$$"
}

if (params$irt_type=="3pl") {
head=" 3PL IRT model"
#eq="$$ {P}(Y_{ij} = 1|\theta_{i},a_j,b_j, c_j) =c_j + (1+c_j)\cdot\frac{e^{a_j(\theta_i-b_j)}}{1+e^{a_j(\theta_i-b_j)}}$$"
}
```



Available models:

Rasch model
$$ {P}(Y_{ij} = 1|\theta_{i},b_j) =\frac{e^{(\theta_i-b_j)}}{1+e^{(\theta_i-b_j)}} $$

1PL IRT model
$$ {P}(Y_{ij} = 1|\theta_{i},a,b_j) =\frac{e^{a(\theta_i-b_j)}}{1+e^{a(\theta_i-b_j)}}$$

2PL IRT model
$$ {P}(Y_{ij} = 1|\theta_{i},a_j,b_j) = \frac{e^{a_j(\theta_i-b_j)}}{1+e^{a_j(\theta_i-b_j)}}$$

3PL IRT model
$$ {P}(Y_{ij} = 1|\theta_{i},a_j,b_j, c_j) =c_j + (1+c_j)\cdot\frac{e^{a_j(\theta_i-b_j)}}{1+e^{a_j(\theta_i-b_j)}}$$

**Wright (Item-Person) Map using 1PL IRT Model**

```{r echo=FALSE, results="hide", fig.height=5, fig.width=10}
wrightMap(params$wrightMap[[1]], params$wrightMap[[2]], item.side=itemClassic)
```

\pagebreak

**Selected model:`r head`**

```{r echo=FALSE, results="hide", fig.height=4}
params$irt
params$irtiic
```

\pagebreak

```{r echo=FALSE, results="hide", fig.height=4}
params$irttif
params$irtfactor
```

```{r echo=FALSE, fig.height=6}
table=params$irtcoef
table=round(table,5)
grid.arrange(tableGrob(table), top="Parameter Estimates and Item Fit")
```



\pagebreak


# DIF/Fairness Report

`r if(!params$isGroupPresent){"Group Vector is not present. DIF and DDF Report could not be generated!"}`

`r if(params$isGroupPresent) {"## Total Scores"}`

```{r echo=FALSE}
if(params$isGroupPresent){
params$resultsgroup
}
```

```{r echo=FALSE, results="hide"}

if(params$isGroupPresent){
g1=params$histbyscoregroup0
g2=params$histbyscoregroup1
grid.arrange(g1, g2, ncol=1)
}
```

`r if(params$isGroupPresent) {"## DIF Detection Using Delta Plot"}`

```{r echo=FALSE, results="hide"}
if(params$isGroupPresent){
params$deltaplot
}
```

```{r echo=FALSE}
if(params$isGroupPresent){
params$DP_text_normal
}
```

`r if(params$isGroupPresent) {"## DIF Detection Using Logistic Regression"}`

```{r echo=FALSE}
if(params$isGroupPresent){
params$DIF_logistic_print
}
```

```{r echo=FALSE, results='hide', fig.height=4.2}
if(params$isGroupPresent){
params$DIF_logistic_plot
}
```

`r if(params$isGroupPresent) {"## DDF Detection Using Multinomial Regression"}`

```{r echo=FALSE}
if(params$isGroupPresent){
print(params$model_DDF_print)
}
```

```{r echo=FALSE, results='hide', fig.height=4.2}
if(params$isGroupPresent){
params$plot_DDFReportInput
}
```

\pagebreak

# Session Info

```{r echo=FALSE}
sessionInfo()
```

\pagebreak
