# NOT RUN {
#The below will take *a long* time to run- of the order a few days for the LD tests.
# }
# NOT RUN {
Ngen=1e3
sdsamp=3
testvec=c(5,10,20,50,100)
set.seed(650)
fittestmean={}
for(Nsamp in testvec){
print(paste('Nsamp=', Nsamp))
fittest=matrix(0, nrow=Ngen, ncol=3)
for(i in 1:Ngen){
if(i <!-- %% 100==0){print(paste('Ngen=',i))} -->
mockx=runif(Nsamp, -100, 100)
mocky=mockx*tan(45*pi/180)+rnorm(Nsamp, sd=sdsamp)
fittest[i,]=hyper.fit(X=cbind(mockx,mocky), coord.type='theta', scat.type='vert.axis')$parm
}
convtest2dOpt=rbind(convtest2dOpt, c(N=Nsamp,Raw=mean(fittest[,3]),
mean(fittest[,3])*hyper.sigcor(Nsamp, 2)))
}
fittestmeanLD={}
for(Nsamp in testvec){
print(paste('Nsamp=', Nsamp))
fittest=matrix(0, nrow=Ngen, ncol=3)
for(i in 1:Ngen){
if(i <!-- %% 100==0){print(paste('Ngen=',i))} -->
mockx=runif(Nsamp, -100, 100)
mocky=mockx*tan(45*pi/180)+rnorm(Nsamp, sd=sdsamp)
fittest[i,]=hyper.fit(X=cbind(mockx,mocky), coord.type='theta', scat.type='vert.axis',
algo.func='LD', algo.method='GG', Specs=list(Grid=seq(-0.1,0.1, len=5), dparm=NULL,
CPUs=1, Packages=NULL, Dyn.libs=NULL))$parm
print(fittest[i,])
}
convtest2dLD=rbind(convtest2dLD, c(N=Nsamp, Raw=mean(fittest[,3]),
mean(fittest[,3])*hyper.sigcor(Nsamp, 2)))
}
normtestmean={}
for(Nsamp in testvec){
print(paste('Nsamp=', Nsamp))
normtest={}
for(i in 1:Ngen){
if(i <!-- %% 100==0){print(paste('Ngen=',i))} -->
normtemp=rnorm(Nsamp, sd=sdsamp)
normtest=c(normtest, sqrt(sum((normtemp-mean(normtemp))^2)/Nsamp))
}
convtest1dNorm=rbind(convtest1dNorm, c(N=Nsamp, Raw=mean(normtest),
mean(normtest)*hyper.sigcor(Nsamp, 1)))
}
# }
# NOT RUN {
#The runs above have been pre-generated and can be loaded via
data(convtest2dOpt)
data(convtest2dLD)
data(convtest1dNorm)
magplot(convtest2dOpt[,c('N','Raw')],xlim=c(5,100),ylim=c(0,4),type='b',log='x')
lines(convtest2dOpt[,c('N','sampbias2popunbias')],type='b',lty=2,pch=4)
lines(convtest2dLD[,c('N','Raw')],type='b',col='blue')
lines(convtest2dLD[,c('N','bias2unbias')],type='b',lty=2,pch=4,col='blue')
lines(convtest1dNorm[,c('N','Raw')],type='b',col='red')
lines(convtest1dNorm[,c('N','sampbias2popunbias')],type='b',lty=2,pch=4,col='red')
legend('topleft', legend=c('2 DoF and optim fit','2 DoF and LD fit', '1 DoF and direct SD'),
col=c('black','blue','red'),pch=1)
legend('topright', legend=c('Raw intrinsic scatter', 'Corrected intrinsic scatter'),
lty=c(1,2))
# }
Run the code above in your browser using DataLab