---
title: "Item Review Sheets produced using conquestr"
author: "Leigh Patterson"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Item Review Sheets produced using conquestr}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r knitr setup, include=FALSE}
# global options for all chunks
knitr::opts_chunk$set(echo = FALSE)

```

A number of libraries are required.
This is becasue we will format some objects with our own R markdown.

```{r prep}
# Required packages
library("conquestr")
library("kableExtra")

```

## Item Review Sheets produced using RMarkdown

This is an example of implementation of Item Review Sheets using **RMarkdown** and conquestr.
We will use the default system file, analysis, and plots from the conquestr library.
First we can read in the system file (output by ACER ConQuest). Item analysis (itanal) and 
iteration history are stored in the system file.


```{r sysfile, }

# Read default system file
mySys <- ConQuestSys()

# Read itanal
mySys_itanal <- getCqItanal(mySys)

# Summary stats are alwasy the last element of the list returned by getCqItanal
SumStat <- mySys_itanal[[length(mySys_itanal)]]

# internal formatting of itanal
mySys_itanalFmt <- fmtCqItanal(mySys_itanal)

# iteration history
iter_hist <- getCqHist(mySys)

```

Output from plot files are stored separately in _Rout_ files.

```{r rout}
#generate a ICC/MCC plot from an 'ACER ConQuest' Rout file - traditional ICC/MCC plot
my_Rout <- ConQuestRout()

```

There are also helper functions to plot iteration history and Rout files.

```{r plots}
# iteration history plot of item parameters 
iter_hist_plot <- plotCqHist(iter_hist, centre = FALSE, legend = TRUE, params = "Xsi")
# ICC plot
my_Rout_plot <- plotRout(my_Rout)

```


## Test Summary Information

**Summary Statistics:**

```{r summary stats}
SumStat %>%
  kbl(digits = 2) %>% # could set digits as a global option
  kable_styling()
```


**Visual summary of convergence**

```{r convergence plot, message=FALSE, warning=FALSE, fig.cap = "Iteration history of item parameters."}

plot(iter_hist_plot)

```


## Item 1 Summary

<!-- sprintf is deprecated, and snprintf is not imported by default
# ```{r, results summary}
# with(
#  mySys_itanal[[1]]$table,
#  cat(
#    snprintf(
#      "%i students selected response category %s. This response category was scored %s. The point-biserial was %.2f. The students responding in this category had an average ability of  %.2f.",
#      Count[1], 
#      Category[1],
#      Score[1],
#      `Pt Bis`[1], 
#      `Ability mean (D1)`[1]
#    )
#  )
# )
# ```
--> 

**Item 1 Statistics**:
```{r item_1_stats}
#Item 1 name only
mySys_itanal[[1]]$name %>%
  kbl() %>%
  kable_styling()

#Item 1 table only
mySys_itanal[[1]]$table %>%
  kbl(digits = 2) %>%
  kable_styling()

#Item 1 item corrs only
mySys_itanal[[1]]$item_rest_total %>%
  kbl(digits = 2) %>%
  kable_styling()

```



**Item 1 ICC**:

```{r, plot_icc}
plot(my_Rout_plot)
```

Inserting <span style="color:red">red</span> text for demo purposes.
