Open bjorn81 opened 5 years ago
Thanks for your comment. I remember that I have fixed this bug in this version? In a earlier version of gsynth, out$alpha.tr is a vector when the model contains no factors. And in the current version, it will be converted to a matrix object in the final part of the main function. Have you updated the package?
I'm using package version 1.09, which seems to be the latest one on github. Perhaps there are some exceptions where the conversion to a matrix does not take place? Where the code would break for me, out$alpha.tr was a seemingly valid vector with decimal numbers, only it could not be supplied with row names, being a vector.
It seems like all that's needed is to wrap
alpha.tr.lv <- colMeans(U.lv)
with as.matrix()
Indeed this issue has been fixed on the git version. But in the cran version the if-clause that makes sure alpha.tr is a matrix is missing:
`
if (!is.null(out$alpha.tr)) {
if (class(out$alpha.tr) == "numeric") { #missing
out$alpha.tr <- as.matrix(out$alpha.tr) #missing
} #missing
rownames(out$alpha.tr) <- iname[which(out$tr == 1)]
colnames(out$alpha.tr) <- ""
}
`
Sorry I'm not able to do a better job at formatting the text above.
Thank you.
On Fri, Nov 23, 2018, 01:30 bjorn81 <notifications@github.com wrote:
Indeed this issue has been fixed on the git version. But in the cran version the if-clause that makes sure alpha.tr is a matrix is missing:
if (!is.null(out$alpha.tr)) { if (class(out$alpha.tr) == "numeric") { out$alpha.tr <- as.matrix(out$alpha.tr) } rownames(out$alpha.tr) <- iname[which(out$tr == 1)] colnames(out$alpha.tr) <- "" }
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/xuyiqing/gsynth/issues/22#issuecomment-441191460, or mute the thread https://github.com/notifications/unsubscribe-auth/AHT1GEvRtXiO7r5Aic1beljc389Z6T3fks5ux8BAgaJpZM4Ypnn5 .
This is where it breaks, line 531 in the main function:
if (!is.null(out$alpha.tr)) { rownames(out$alpha.tr) <- iname[which(out$tr == 1)] colnames(out$alpha.tr) <- "" }
I'm not sure whether
out$alpha.tr
should always be a matrix, but it seems to be either a vector or a matrix depending on the if statement here in synth.coreif (max(T0) == T0.min & (!0 %in% I.tr)) { alpha.tr.lv <- colMeans(U.lv) U.tr <- U.tr - matrix(alpha.tr.lv, TT, Ntr, byrow = TRUE) } else { alpha.tr.lv <- sapply(U.lv, mean) U.tr <- U.tr - matrix(alpha.tr.lv, TT, Ntr, byrow = TRUE) }
I'm not into the details of the package or the method enough to be more helpful than this.