Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/GloSpheGeoReg.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#' @import trust trust

GloSpheGeoReg <- function(xin, yin, xout) {
k = length(xout)
n = length(xin)
k = nrow(xout)
n = nrow(xin)
m = ncol(yin)

xbar <- colMeans(xin)
Expand Down
2 changes: 1 addition & 1 deletion R/GloSpheReg.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ GloSpheReg <- function(xin=NULL, yin=NULL, xout=NULL){
if(is.vector(xout)){
xout <- as.matrix(xout)
}
if (length(xin)!=nrow(yin))
if (nrow(xin)!=nrow(yin))
stop("The length of xin should be the same as the number of rows in yin.")
if (sum(abs(rowSums(yin^2) - rep(1,nrow(yin))) > 1e-6)){
yin = yin / sqrt(rowSums(yin^2))
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test_GloSpheReg.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ test_that("truth: great circle (no noise)", {
expect_lt( mean(sapply(seq_len(n), function(i) SpheGeoDist(res$yout[i,], ytrue[,i]))), 5e-3 )
})

test_that("truth: great circle (no noise) with multiple covariates", {
n <- 101
xin <- seq(-1,1,length.out = n)
theta_true <- rep(pi/2,n)
phi_true <- (xin + 1) * pi / 4
err_sd <- 0
ytrue <- apply( cbind( 1, phi_true, theta_true ), 1, pol2car )
if (err_sd > 0) {
basis <- apply( ytrue, 2, frameSphere ) # [1:3,] - 1st basis vector; [4:6,] - 2nd basis vector
set.seed(1)
yin_tg <- basis[1:3,] * rnorm(n, mean = 0, sd = err_sd) +
basis[4:6,] * rnorm(n, mean = 0, sd = err_sd)
yin <- t( sapply( seq_len(n), function(i) expSphere( base = ytrue[,i], tg = yin_tg[,i] ) ) )
} else {
yin <- t( ytrue )
}

xin <- cbind(xin, c(0, rep(c(-0.95, 0.95), 50)))
xout <- xin
res <- GloSpheReg(xin=xin, yin=yin, xout=xout)
expect_lt( mean(sapply(seq_len(n), function(i) SpheGeoDist(res$yout[i,], ytrue[,i]))), 5e-3 )
})

# How to generate data according to a global model?
test_that("truth: great circle + noise", {
n <- 101
Expand Down