Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implicit ordering problem with mfpca.sc #92

Open
julia-wrobel opened this issue Nov 15, 2019 · 0 comments
Open

implicit ordering problem with mfpca.sc #92

julia-wrobel opened this issue Nov 15, 2019 · 0 comments

Comments

@julia-wrobel
Copy link
Contributor

julia-wrobel commented Nov 15, 2019

issue raised by @andrew-leroux (thank you), bug in MFPCA due to function implicitly assuming ids are ordered. Code below reproduces the bug:

library("refund")
data(DTI)
DTI <- subset(DTI, Nscans < 6)
id <- as.numeric(factor(DTI$ID)); summary(diff(id)) ## IMPORTANT: the IDs are already ordered
Y <- DTI$cca
id2 <- rev(id) ## create new vector of ids which are NOT ordered
mfpca.DTI1 <- mfpca.sc(Y=Y, id = id, twoway = TRUE) ## works
mfpca.DTI2 <- mfpca.sc(Y=Y, id = id2, twoway = TRUE) ## fails

The code below raises a similar issue; there is no bug but estimation is wrong. See the plot, the first row of the first fit and the last row of the second fit should have the same fitted values but they don't.

data(DTI)
library("refund")
DTI <- subset(DTI, Nscans == 4)
id <- as.numeric(factor(DTI$ID)); summary(diff(id))
Y <- DTI$cca

Y2 <- Y[rev(1:nrow(Y)),] ## create new vector of ids which are NOT ordered
id2 <- id[rev(1:nrow(Y))]

mfpca.DTI1 <- mfpca.sc(Y=Y, id = id, twoway = TRUE)
mfpca.DTI2 <- mfpca.sc(Y=Y2, id = id2, twoway = TRUE)

plot(mfpca.DTI1$Yhat[1,])
lines(mfpca.DTI2$Yhat[nrow(Y),])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant