data(eggs)
uni.C <- sort( unique(eggs$Code) )
ind <- 1
Data <- eggs[eggs$Code==uni.C[ind], ]
x0 <- Data$x
y0 <- Data$y
Res1 <- adjdata(x0, y0, ub.np=200, times=1.2, len.pro=1/20)
x1 <- Res1$x
y1 <- Res1$y
Res2 <- adjdata(x0, y0, ub.np=40, times=1, len.pro=1/2, index.sp=20)
x2 <- Res2$x
y2 <- Res2$y
Res3 <- adjdata(x0, y0, ub.np=100, times=1, len.pro=1/2, index.sp=100)
x3 <- Res3$x
y3 <- Res3$y
dev.new()
plot( x2, y2, asp=1, cex.lab=1.5, cex.axis=1.5,
xlab=expression(italic("x")), ylab=expression(italic("y")),
pch=1, col=4 )
points( x3, y3, col=2)
# \donttest{
x0.ini <- mean( x1 )
y0.ini <- mean( y1 )
theta.ini <- pi
a.ini <- sqrt(2) * max( y0.ini-min(y1), x0.ini-min(x1) )
n1.ini <- c(5, 25)
n2.ini <- c(15, 25)
if(ind == 2){
n1.ini <- c(0.5, 1)
n2.ini <- c(6, 12)
}
ini.val <- list(x0.ini, y0.ini, theta.ini, a.ini, n1.ini, n2.ini)
Res4 <- fitGE( GE, x=x1, y=y1, ini.val=ini.val,
m=1, simpver=1, nval=1, unit="cm",
par.list=FALSE, fig.opt=TRUE, angle=NULL,
control=list(reltol=1e-20, maxit=20000),
np=2000 )
Res4$par
sqrt(sum((Res4$y.stand.obs-Res4$y.stand.pred)^2)/Res4$sample.size)
xx <- Res4$x.stand.obs
yy <- Res4$y.stand.obs
library(spatstat.geom)
poly0 <- as.polygonal(owin(poly=list(x=xx, y=yy)))
area(poly0)
areaGE(GE, P = Res4$par[4:6],
m=1, simpver=1)
# The following code is used to
# calculate the root-mean-square error (RMSE) in the y-coordinates
ind1 <- which(yy >= 0)
ind2 <- which(yy < 0)
xx1 <- xx[ind1] # The upper part of the egg
yy1 <- yy[ind1]
xx2 <- xx[ind2] # The lower part of the egg
yy2 <- yy[ind2]
Para <- c(0, 0, 0, Res4$par[4:length(Res4$par)])
PartU <- curveGE(GE, P=Para, phi=seq(0, pi, len=100000), m=1, simpver=1, fig.opt=FALSE)
xv1 <- PartU$x
yv1 <- PartU$y
PartL <- curveGE(GE, P=Para, phi=seq(pi, 2*pi, len=100000), m=1, simpver=1, fig.opt=FALSE)
xv2 <- PartL$x
yv2 <- PartL$y
ind3 <- c()
for(q in 1:length(xx1)){
ind.temp <- which.min(abs(xx1[q]-xv1))
ind3 <- c(ind3, ind.temp)
}
ind4 <- c()
for(q in 1:length(xx2)){
ind.temp <- which.min(abs(xx2[q]-xv2))
ind4 <- c(ind4, ind.temp)
}
RSS <- sum((yy1-yv1[ind3])^2) + sum((yy2-yv2[ind4])^2)
RMSE <- sqrt( RSS/length(yy) )
# To calculate the volume of the Gielis egg when simpver=1 & m=1
VolumeSGE(P=Res4$par[4:6])
# To calculate the surface area of the Gielis egg when simpver=1 & m=1
SurfaceAreaSGE(P=Res4$par[4:6])
# }
graphics.off()
Run the code above in your browser using DataLab