data(eggs)
uni.C <- sort( unique(eggs$Code) )
ind <- 8
Data <- eggs[eggs$Code==uni.C[ind], ]
x0 <- Data$x
y0 <- Data$y
Res1 <- adjdata(x0, y0, ub.np=2000, times=1.2, len.pro=1/20)
x1 <- Res1$x
y1 <- Res1$y
dev.new()
plot( x1, y1, asp=1, cex.lab=1.5, cex.axis=1.5, type="l", col=4,
xlab=expression(italic("x")), ylab=expression(italic("y")) )
# \donttest{
res1 <- lmTE( x1, y1, unit="cm", fig.opt=FALSE )
if(FALSE){
P0 <- c(res1$scan.length/2, res1$par)
xx <- seq(-res1$scan.length/2, res1$scan.length/2, len=2000)
yy1 <- ETE(P0, xx)
yy2 <- -ETE(P0, xx)
dev.new()
plot( xx, yy1, cex.lab=1.5, cex.axis=1.5, asp=1, col=2,
ylim=c(-res1$scan.length/2, res1$scan.length/2),
type="l", xlab=expression(x), ylab=expression(y) )
lines( xx, yy2, col=4 )
}
x0.ini <- mean( x1 )
y0.ini <- mean( y1 )
theta.ini <- res1$theta
a.ini <- res1$scan.length / 2
alpha0.ini <- res1$par[1]
alpha1.ini <- res1$par[2]
alpha2.ini <- res1$par[3]
ini.val <- list(x0.ini, y0.ini, theta.ini, a.ini, alpha0.ini, alpha1.ini, alpha2.ini)
res0 <- fitETE( x=x1, y=y1, ini.val=ini.val,
unit="cm", par.list=FALSE,
stand.fig=FALSE, angle=NULL, fig.opt=FALSE,
control=list(reltol=1e-30, maxit=50000),
np=2000 )
n.loop <- 12
Show <- FALSE
for(i in 1:n.loop){
ini.val <- res0$par
if(i==n.loop) Show <- TRUE
print(paste(i, "/", n.loop, sep=""))
res0 <- fitETE( x=x1, y=y1, ini.val=ini.val,
unit="cm", par.list=FALSE,
stand.fig=Show, angle=pi/4, fig.opt=Show,
control=list(reltol=1e-30, maxit=50000),
np=2000 )
}
# The numerical values of the location and model parameters
res0$par
# The root-mean-square error (RMSE) between
# the observed and predicted y values
sqrt(res0$RSS/res0$sample.size)
sqrt(sum((res0$y.stand.obs-res0$y.stand.pred)^2)/length(res0$y.stand.obs))
# To calculate the volume of the egg
VolumeETE(P=res0$par[4:7])
# To calculate the surface area of the egg
SurfaceAreaETE(P=res0$par[4:7])
# }
graphics.off()
Run the code above in your browser using DataLab