# \donttest{
set.seed(1)
n <- 200
# simulate the data according to the simulation in Petersen & Müller (2019)
xin <- runif(n)
err_sd <- 0.2
xout <- seq(0,1,length.out = 51)
phi_true <- acos(xin)
theta_true <- pi * xin
ytrue <- cbind(
sin(phi_true) * cos(theta_true),
sin(phi_true) * sin(theta_true),
cos(phi_true)
)
basis <- list(
b1 = cbind(
cos(phi_true) * cos(theta_true),
cos(phi_true) * sin(theta_true),
-sin(phi_true)
),
b2 = cbind(
sin(theta_true),
-cos(theta_true),
0
)
)
yin_tg <- basis$b1 * rnorm(n, mean = 0, sd = err_sd) +
basis$b2 * rnorm(n, mean = 0, sd = err_sd)
yin <- t(sapply(seq_len(n), function(i) {
tgNorm <- sqrt(sum(yin_tg[i,]^2))
if (tgNorm < 1e-10) {
return(ytrue[i,])
} else {
return(sin(tgNorm) * yin_tg[i,] / tgNorm + cos(tgNorm) * ytrue[i,])
}
}))
res <- LocSpheReg(xin=xin, yin=yin, xout=xout, optns = list(bw = 0.15, kernel = "epan"))
# }
Run the code above in your browser using DataLab