#############################################################################
# SIMULATED EXAMPLE 1: Scale scores
#############################################################################
set.seed(899)
n <- 5000 # number of students
x <- round( runif( n , 0 ,1 ) )
y <- rnorm(n)
# simulate true score theta
theta <- .6 + .4*x + .5 * y + rnorm(n)
# simulate observed score by adding measurement error
sig.e <- rep( sqrt(.40) , n )
theta_obs <- theta + rnorm( n , sd=sig.e)
# calculate alpha
( alpha <- var( theta ) / var( theta_obs ) )
# [1] 0.7424108
# => Ordinarily, sig.e or alpha will be known, assumed or estimated by using items,
# replications or an appropriate measurement model.
# create matrix of predictors
X <- as.matrix( cbind(x , y ) )
# plausible value imputation with scale score
imp1 <- draw.pv.ctt( y=theta_obs , x = X , sig.e =sig.e )
# check results
lm( imp1 ~ x + y )
# imputation with alpha as an input
imp2 <- draw.pv.ctt( y=theta_obs , x = X , alpha = .74 )
lm( imp2 ~ x + y )
Run the code above in your browser using DataLab