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

# CODE STARTS HERE.


###################n=15, 25 100###################################
############SLR equal spacing############################
# Y is a vector of responses.
# X1 vector values for the predictor.
library(MASS)
n=15
k=4     # k  must be greater 1. K is not used here.
S=500  
set.seed(2010)

X0=as.matrix(rep(1,n)) # vector of ones.
X1=matrix((seq(1,n)))


 par=matrix(c(2,1))


###########################################################
 sim=lapply(1:S, function(i)  cbind(2+X1+rt(n,df=3),X1))

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

 estNCK1=lapply( sim, betanck1 )
#########################################
 estNCK2=lapply( sim, betanck2 )

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

h1=matrix(unlist(estNCK1),S,2,byrow=T)
# h1 is a matrix in the first column we have intercepts.
# in the second culomn we have slopes. 

 MSEint1=(mean(h1[,1])-2)^2+var(h1[,1])

 MSEslope1=(mean(h1[,2])-1)^2+var(h1[,2])


h2=matrix(unlist(estNCK2),S,2,byrow=T)
# h2 is a matrix in the first column we have intercepts.
# in the second culomn we have slopes. 
 MSEint2=(mean(h2[,1])-2)^2+var(h2[,1])

 MSEslope2=(mean(h2[,2])-1)^2+var(h2[,2])

MSEint1
MSEslope1

MSEint2
MSEslope2
long1=system.time(estNCK1)
long2=system.time(estNCK2)

cat('time 1 and 2  ',long1[3],long2[3], file="sim1out",fill=F,append=T,"\n\n")

cat('   n=  ',n, file="sim1out",fill=F,append=T,"\n\n")
cat('   k=  ',k, file="sim1out",fill=F,append=T,"\n")
cat('   MSEint1  ',MSEint1, file="sim1out",fill=F,append=T,"\n\n")
cat('   MSEslope1  ',MSEslope1, file="sim1out",fill=F,append=T,"\n\n")
cat('   MSEint2  ',MSEint2, file="sim1out",fill=F,append=T,"\n\n")
cat('   MSEslope2  ',MSEslope2, file="sim1out",fill=F,append=T,"\n\n")

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



