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{
simpver <- NULL
res1 <- lmPE( x1, y1, simpver=simpver, dev.angle=seq(-0.05, 0.05, by=0.0001),
unit="cm", fig.opt=FALSE )
x0.ini <- mean( x1 )
y0.ini <- mean( y1 )
theta.ini <- res1$theta
a.ini <- res1$scan.length / 2
b.ini <- res1$scan.width / 2
c1.ini <- res1$par[2] / res1$par[1]
c2.ini <- res1$par[3] / res1$par[1]
c3.ini <- res1$par[4] / res1$par[1]
ini.val <- list(x0.ini, y0.ini, theta.ini, a.ini, b.ini, c1.ini, c2.ini, c3.ini)
res0 <- fitEPE( x=x1, y=y1, ini.val=ini.val,
simpver=simpver, 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 <- fitEPE( x=x1, y=y1, ini.val=ini.val,
simpver=simpver, 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
VolumeEPE(P=res0$par[4:8])
# To calculate the surface area of the egg
SurfaceAreaEPE(P=res0$par[4:8])
# }
graphics.off()
Run the code above in your browser using DataLab