locpolycor: Local Modeling of Thresholds and Polychoric Correlations

View source: R/locpolycor.R

locpolycorR Documentation

Local Modeling of Thresholds and Polychoric Correlations

Description

Estimates thresholds and polychoric correlations as a function of a continuous moderator variable x.

Usage

locpolycor(y, data.mod, moderator.grid, h=1.1, model_thresh, model_polycor,
     sampling_weights=NULL, kernel="gaussian", eps=1e-10)

Arguments

y

Matrix with columns referrring to ordinal items

data.mod

Values of the moderator variable x

moderator.grid

Grid of x values to be used for local estimation of thresholds and polychoric correlations

h

Bandwidth factor

model_thresh

Model for thresholds: can be 'const' (constant function) or 'lin' (linear function)

model_polycor

Model for polychoric correlations: can be 'const' (constant function) or 'lin' (linear function)

sampling_weights

Optional vector of sampling weights

kernel

Used kernel function, see lsem_local_weights

eps

Parameter added in likelihood optimization

Value

A list with entries

thresh_list

Threshold parameters

thresh_stat

Estimated thresholds

polycor_stat

Estimated polychoric correlations

...

...

Examples

## Not run: 
#############################################################################
# EXAMPLE 1: Two items, moderator on (0,1)
#############################################################################


#*** simulate data

# functions for thresholds
th1_fun <- function(x){ -0.3*(x-2)^2 + .2 }
th2_fun <- function(x){ 0.4*(x+1)^2 - 0.6 }
zh1_fun <- function(x){ 0.3*(x-1) }
# function polychoric correlation
cor_x12 <- function(x){ 0.2+0.1*(x-0.5)+0.09*(x-0.5)^2 }

# simulate moderator
x <- stats::runif(N)

# simulate data
yast <- matrix( NA, nrow=N, ncol=2)
for (nn in 1:N){
    rho12 <- cor_x12(x[nn])
    Sigma <- matrix(0, 2,2)
    Sigma[1,2] <- rho12
    Sigma <- Sigma + t(Sigma)
    diag(Sigma) <- 1
    yast_nn <- MASS::mvrnorm( 1, mu=rep(0,2), Sigma=Sigma )
    yast[nn,] <- yast_nn
}
y <- 0*yast
th1_x <- th1_fun(x)
th2_x <- th2_fun(x)
zh1_x <- zh1_fun(x)
y[,1] <- 1*( yast[,1] > th1_x ) + 1*( yast[,1] > th2_x )
y[,2] <- 1*( yast[,2] > zh1_x )
colnames(y) <- paste0("I",1:ncol(y))

dat <- data.frame(x=x, y)

#-- local modeling
res <- sirt::locpolycor(y, data.mod=x, moderator.grid=c(0, .25, .5, .75, 1 ), h=2,
                 model_thresh="lin", model_polycor="lin")
str(res)

## End(Not run)

alexanderrobitzsch/sirt documentation built on Dec. 1, 2024, 2:18 a.m.