functional programming - errors when using fpca package in R -
i using fpca package apply reduced rank model in james et al. (2000), every time try use fpca.score function, returns me error:
error in eigenfuncs.u[gridtime, 1:k] : subscript out of bounds so pulled out source code:
function (data.m, grids.u, muhat, eigenvals, eigenfuncs, sig2hat, k) { temp <- table(data.m[, 1]) n <- length(temp) m.l <- as.vector(temp) result <- matrix(0, n, k) n <- length(grids.u) evalmat <- diag(eigenvals[1:k]) current <- 0 eigenfuncs.u <- t(eigenfuncs) data.u <- matrix(as.numeric(as.vector(data.m[, -1])),nrow=nrow(data.m[,-1]), ncol = ncol(data.m[, -1])) (i in 1:n) { y <- as.vector(data.u[(current + 1):(current + m.l[i]), 1]) meastime <- data.u[(current + 1):(current + m.l[i]), 2] gridtime <- ceiling(n * meastime) muy <- muhat[gridtime] phiy <- matrix(eigenfuncs.u[gridtime, 1:k], ncol = k) sigy <- phiy %*% evalmat %*% t(phiy) + sig2hat * diag(m.l[i]) temp.y <- matrix(y - muy) result[i, ] <- evalmat %*% t(phiy) %*% solve(sigy, temp.y) current <- current + m.l[i] } return(result) } data.m three-column data matrix first column id, second column measurement, third column time. input of fpca.mle function outputs include other inputs of above fpca.score function: grids, muhat, eigenvals, eigenfuncs, sig2hat, k.
apparently error occurs here
eigenfuncs.u[gridtime, 1:k] which comes
n <- length(grids.u) meastime <- data.u[(current + 1):(current + m.l[i]), 2] gridtime <- ceiling(n * meastime) is there fda guru knows how fix this? appreciated.
the issue might come mismatch between grids value , values of time in data. using newton algorithm, default value grids seq(0,1,0.002), time data needs re-scaled fall between (0,1).
Comments
Post a Comment