#==========================================================
# help_functions.R
#
# Help functions for BayesTwin pacakge
# Subroutines to calculate probabilites for every response
# categories under the GPCM and PCM, check if response is binary
#
# BayesTwin - An R Package for Bayesian Inference of Item-Level Twin Data
# Copyright (C) 2014-2017 Inga Schwabe
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details
#
#==========================================================
#For warning in IRT_twin (check if dummy variables need to be used)
is.categorical = function(x){
length(unique(x)) <= 7 #allow for values 0,1 and NA.
}
#Help functions to simulate data under the GPCM/PCM
numerator <- function(a, b, theta, k, D=1.7) exp(sum(D*a*(theta-b[1:k])))
denominator <- function(a, b, theta, D=1.7) {
sumval <- 0
for (i in 1:length(b)) sumval <- sumval + numerator(a,b,theta,i,D)
return(sumval)
}
#Category characteristic curve
prm <- function(a, b, theta, k, D=1.7) numerator(a, b, theta, k, D)/denominator(a, b, theta, D)
#cumulative probability function
cprm <- function(a, b, theta, D=1.7) {
ncat = length(b)
p=1
for (i in 1:ncat) p[i]<- prm(a,b,theta,i,D)
pmf = p
for (i in 1:ncat) pmf[1:ncat>i]<-pmf[1:ncat>i]+p[i]
return(pmf)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.