
#########################
#kernel smoothing
#########################


library(KernSmoothIRT)

source('LstepArchetypesMod.R')
source('LFunctions_to_calculate_real_archetypes_with_swap2.R')
source('LstepArchetypoids.R')

a=read.table("actmR.txt",header=F,sep=' ')

a1 <- ksIRT(responses = a, key = 1, format = 1)
plot(a1,plottype='PCA') #many local curves

fu=a1$OCC[ a1$OCC[,2]==1,4:54]

t=a1$evalpoints

set.seed(1234)
pit=fu

a4=stepLArchetypoids3(fu, k=4, norep=20)
#  2 60 14 54

#plot(a1,items=c(2,14,54,60))


matplot(t,t(fu),type='l',xlab=expression(theta),ylab=expression(paste('P(',theta,')')))


matplot(t,t(fu[c(2,14,54,60),]),type='l',xlab=expression(theta),ylab=expression(paste('P(',theta,')')))

legend(2,0.3,legend =c('2','14','54','60') , col = 1:4, lty = 1:4)


############################

#################
#3PL model
################


library(irtoys)


source('LstepArchetypesMod.R')
source('LFunctions_to_calculate_real_archetypes_with_swap2.R')
source('LstepArchetypoids.R')


a=read.table("actmR.txt",header=F,sep=' ')

a3=est(a,model='3PL',engine='ltm')


fu=irf(a3)

t=fu$x


set.seed(1234)
tfut=t(fu$f)
a4=stepLArchetypoids3(tfut, k=4, norep=20)

#4 51 60  2 


matplot(t,as.matrix(fu$f),type='l',xlab=expression(theta),ylab=expression(paste('P(',theta,')')))


matplot(t,as.matrix(fu$f[,c(2,4,51,60)]),type='l',xlab=expression(theta),ylab=expression(paste('P(',theta,')')))

legend(2,0.3,legend =c('2','4','51','60') , col = 1:4, lty = 1:4)
