forked from manuelreif/PP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ppass_par_and_fit.Rmd
119 lines (74 loc) · 2.24 KB
/
ppass_par_and_fit.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
title: Analyzing a dataset
author: Manuel Reif
output:
prettydoc::html_pretty:
theme: cayman
highlight: github
---
<!--
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{Analyzing a dataset}
%\VignetteEncoding{UTF-8}
-->
# Analyzing a simulated data set
```{r loadall}
library(PP)
library(data.table)
```
## First example
```{r simulate_data1}
suppressWarnings(RNGversion("3.5.0"))
set.seed(1526)
# intercepts
diffpar <- seq(-3.6,3,length=15)
# slope parameters
sl <- round(runif(15,0.5,1.5),2)
la <- round(runif(15,0,0.25),2)
ua <- round(runif(15,0.8,1),2)
awm <- PP::sim_4pl(beta = diffpar, alpha = sl,
lowerA = la, upperA = ua,
theta = rnorm(200))
awm <- as.data.frame(awm)
```
### Estimating and using person parameters
```{r data_wrangling1}
out <- PPass(respdf = awm,thres = diffpar,
items="all", mod=c("1PL"),
fitindices=c("lz","lzstar","infit","outfit"))
# create a data.table
outdt <- data.table(out)
outdt[, ID := 1:.N]
outdt[, roundest := factor(round(estimate,8))]
# Compute Percentile Ranks with the Person Parameters
outdtu <- unique(outdt[,su := .N, keyby=roundest], by="roundest")
outdtu[,PR :=cumsum(su)/sum(su) * 100]
outdt <- outdt[outdtu[,list(roundest,PR)],,on="roundest"]
setorder(outdt,ID)
outdt[, c("su") := NULL]
# done
outdt
```
### Using person fit statistics
## Second example
Now there are two groups.
```{r simulate_data2}
awm <- PP::sim_4pl(beta = diffpar, alpha = sl, lowerA = la,
upperA = ua, theta = c(rnorm(500),rnorm(500,0.5,1.2)))
awm <- as.data.frame(awm)
```
### Estimating and using person parameters
```{r data_wrangling2}
out <- PPass(respdf = awm, thres = diffpar,
items="all", mod=c("1PL"),
fitindices= c("lz","lzstar","infit","outfit"))
outdt <- data.table(out)
outdt[, ID := 1:.N]
outdt[, agegroup := rep(c("young","old"),each=500)]
outdt[, roundest := factor(round(estimate,8))]
outdtu <- unique(outdt[,su := .N, keyby=c("agegroup","roundest")], by=c("agegroup","roundest"))[,PR :=cumsum(su)/sum(su) * 100, by=agegroup]
outdt <- outdt[outdtu[,list(agegroup,roundest,PR)],,on=c("agegroup","roundest")]
setorder(outdt,ID)
outdt[, c("su") := NULL]
outdt
```