nmecsys / nowcasting

R package for Dynamic Factor Models with mixed frequencies and unbalanced panel :chart_with_downwards_trend:
98 stars 39 forks source link

Column order matters? #6

Open erikgrenestam opened 4 years ago

erikgrenestam commented 4 years ago

Not sure if this is a bug or my own ignorance, but I've noticed that the ordering of columns in the data seem to matter. Example:

library(nowcasting)
data(NYFED)

base <- NYFED$base
blocks <- NYFED$blocks$blocks
trans <- NYFED$legend$Transformation
frequency <- NYFED$legend$Frequency

#randomly generated reordering
shuffle <- c(7, 11, 24, 21, 10, 15, 2,1, 22, 25, 19, 5, 18, 17, 4, 12, 16, 6, 14, 23, 8, 9, 3, 13, 20)

base_shuffle <- base[,shuffle]
frequency_shuffle <- frequency[shuffle]
blocks_shuffle <- blocks[shuffle,]
trans_shuffle <- trans[shuffle]

x <- Bpanel(base = base, trans = trans, NA.replace = F, na.prop = 1)
x_shuffle <- Bpanel(base = base_shuffle, trans = trans_shuffle, NA.replace = F, na.prop = 1)

nowEM <- nowcast(formula = GDPC1 ~ ., data = x, r = 1, p = 1, 
                 method = "EM", blocks = blocks, frequency = frequency)
nowEM_shuffle <- nowcast(formula = GDPC1 ~ ., data = x_shuffle, r = 1, p = 1, 
                 method = "EM", blocks = blocks_shuffle, frequency = frequency_shuffle)

You can verify that nowEM$yfcst and nowEM_shuffle$yfcst are different. Why is this? Do you have any recommendations for a "correct" column order?