HopkinsIDD / ForecastFramework

Create modular models. Quickly prototype models whose input includes (multiple) time series data. Create pieces of model use cases separately, and swap out particular models as desired. Create modeling competitions, data processing pipelines, and re-useable models.
GNU General Public License v3.0
12 stars 4 forks source link

$mean() and $median() do not remove NAs #30

Open katiehouse3 opened 6 years ago

katiehouse3 commented 6 years ago

If there is an NA value in the simulated incidence matrix, then the $mean(na.rm=TRUE) and $median(na.rm=TRUE) are still outputting NA values.

Example

forecast_sarimaTD$mean(na.rm=TRUE)$mat
                1       2        3        4        5        6        7        8         9        10
National 1.572601 1.48406 1.427495 1.339845 1.224292 1.133543 1.085421 1.083631 0.9779845 0.9100129
                11        12       13       14        15        16       17        18       19
National 0.8676632 0.8207395 0.830351 0.821035 0.8307324 0.8371848 0.916311 0.9972239 1.134101
               20       21       22       23       24       25       26       27       28      29
National 1.194943 1.211229 1.251874 1.370581 1.435053 1.473851 1.510241 1.638875 1.708428 2.02999
               30       31       32       33  34     
National 2.153604 2.236891 2.636346 3.515892 NaN
nickreich commented 6 years ago

Not sure if this makes a difference or not, but NaN is different than NA in R world.

https://www.r-bloggers.com/difference-between-na-and-nan-in-r/

nickreich commented 5 years ago

This is an issue for me as well. Here is another example, note how calculating the median directly using na.rm=TRUE returns a number:

> tmp_forecast$median(na.rm=TRUE)$mat
                             1           2           3            4            5
Saxony              0.01040127  0.04171795  0.01208403 -0.002226797  0.017309182
Saxony-Anhalt       0.03188128  0.02682220  0.02218045  0.023772320  0.017003589
Schleswig-Holstein -0.01680898 -0.01078023 -0.01137909           NA -0.006069802
                            6
Saxony             0.04642985
Saxony-Anhalt      0.01604485
Schleswig-Holstein 0.03033324
> apply(tmp_forecast$data$arr, FUN=function(x) median(x), MARGIN =c(1,2))
                             1           2           3            4            5
Saxony              0.01040127  0.04171795  0.01208403 -0.002226797  0.017309182
Saxony-Anhalt       0.03188128  0.02682220  0.02218045  0.023772320  0.017003589
Schleswig-Holstein -0.01680898 -0.01078023 -0.01137909           NA -0.006069802
                            6
Saxony             0.04642985
Saxony-Anhalt      0.01604485
Schleswig-Holstein 0.03033324
> apply(tmp_forecast$data$arr, FUN=function(x) median(x, na.rm=TRUE), MARGIN =c(1,2))
                             1           2           3            4            5
Saxony              0.01040127  0.04171795  0.01208403 -0.002226797  0.017309182
Saxony-Anhalt       0.03188128  0.02682220  0.02218045  0.023772320  0.017003589
Schleswig-Holstein -0.01680898 -0.01078023 -0.01137909  0.094572982 -0.006069802
                            6
Saxony             0.04642985
Saxony-Anhalt      0.01604485
Schleswig-Holstein 0.03033324