# load data
data( data.noharm )
dat <- data.noharm
I <- ncol(dat) # number of items
# locate noharm.path
noharm.path <- "c:/NOHARM"
#############################################################################
# EXAMPLE 1: 1-dimensional Rasch model (1-PL model)
#############################################################################
# estimate one factor variance
P.pattern <- matrix( 1 , ncol=1 , nrow=1 )
P.init <- P.pattern
# fix all entries in the loading matrix to 1
F.pattern <- matrix( 0 , nrow=I , ncol=1 )
F.init <- 1 + 0*F.pattern #
# estimate model
mod <- R2noharm( dat = dat , model.type="CFA" ,
F.pattern = F.pattern , F.init = F.init , P.pattern = P.pattern ,
P.init = P.init , writename = "ex1__1dim_1pl" ,
noharm.path = noharm.path , dec ="," )
# summary
summary(mod , logfile="ex1__1dim_1pl__SUMMARY")
# jackknife
jmod <- R2noharm.jackknife( mod , jackunits = 20 )
summary(jmod, logfile="ex1__1dim_1pl__JACKKNIFE")
# extract factor scores
emod <- R2noharm.EAP(mod)
#############################################################################
# EXAMPLE 2: 1-dimensional 2PL Model
#############################################################################
# set trait variance equal to 1
P.pattern <- matrix( 0 , ncol=1 , nrow=1 )
P.init <- 1+0*P.pattern
# loading matrix
F.pattern <- matrix( 1 , nrow=I , ncol=1 )
F.init <- 1 + 0*F.pattern
mod <- R2noharm( dat = dat , model.type="CFA" ,
F.pattern = F.pattern , F.init = F.init , P.pattern = P.pattern ,
P.init = P.init , writename = "ex2__1dim_2pl" ,
noharm.path = noharm.path , dec = "," )
summary(mod)
jmod <- R2noharm.jackknife( mod , jackunits = 20 )
summary(jmod)
#############################################################################
# EXAMPLE 3: 1-dimensional 3PL Model with fixed guessing parameters
#############################################################################
# set trait variance equal to 1
P.pattern <- matrix( 0 , ncol=1 , nrow=1 )
P.init <- 1+0*P.pattern
# loading matrix
F.pattern <- matrix( 1 , nrow=I , ncol=1 )
F.init <- 1 + 0*F.pattern #
# fix guessing parameters equal to .2 (for all items)
guesses <- rep( .1 , I )
mod <- R2noharm( dat = dat , model.type="CFA" ,
F.pattern = F.pattern , F.init = F.init , P.pattern = P.pattern ,
P.init = P.init , guesses = guesses ,
writename = "ex3__1dim_3pl" , noharm.path = noharm.path , dec="," )
summary(mod)
jmod <- R2noharm.jackknife( mod , jackunits = 20 )
summary(jmod)
#############################################################################
# EXAMPLE 4: 3-dimensional Rasch model
#############################################################################
# estimate one factor variance
P.pattern <- matrix( 1 , ncol=3 , nrow=3 )
P.init <- .8*P.pattern
diag(P.init) <- 1
# fix all entries in the loading matrix to 1
F.init <- F.pattern <- matrix( 0 , nrow=I , ncol=3 )
F.init[1:6,1] <- 1
F.init[7:12,2] <- 1
F.init[13:18,3] <- 1
F.init
mod <- R2noharm( dat = dat , model.type="CFA" ,
F.pattern = F.pattern , F.init = F.init , P.pattern = P.pattern ,
P.init = P.init , writename = "ex4__3dim_1pl" ,
noharm.path = noharm.path , dec ="," )
# write output from R console in a file
summary(mod , logfile="ex4__3dim_1pl__SUMMARY.Rout")
jmod <- R2noharm.jackknife( mod , jackunits = 20 )
summary(jmod)
# extract factor scores
emod <- R2noharm.EAP(mod)
#############################################################################
# EXAMPLE 5: 3-dimensional 2PL model
#############################################################################
# estimate one factor variance
P.pattern <- matrix( 1 , ncol=3 , nrow=3 )
P.init <- .8*P.pattern
diag(P.init) <- 0
# fix all entries in the loading matrix to 1
F.pattern <- matrix( 0 , nrow=I , ncol=3 )
F.pattern[1:6,1] <- 1
F.pattern[7:12,2] <- 1
F.pattern[13:18,3] <- 1
F.init <- F.pattern
mod <- R2noharm( dat = dat , model.type="CFA" ,
F.pattern = F.pattern , F.init = F.init , P.pattern = P.pattern ,
P.init = P.init , writename = "ex5__3dim_2pl" ,
noharm.path = noharm.path , dec = "," )
summary(mod)
# use 50 jackknife units with 4 persons within a unit
jmod <- R2noharm.jackknife( mod , jackunits = seq( 1:50 , each = 4 ) )
summary(jmod)
#############################################################################
# EXAMPLE 6: Exploratory Factor Analysis with 3 factors
#############################################################################
mod <- R2noharm( dat = dat , model.type="EFA" , dimensions = 3 ,
writename = "ex6__3dim_efa" , noharm.path = noharm.path ,
dec = ",")
summary(mod)
jmod <- R2noharm.jackknife( mod , jackunits = 20 )
Run the code above in your browser using DataLab