Description Usage Arguments Details Value Author(s) See Also Examples

This function does Kalman smoothing for the simple model that is used to predict new COVID-19 cases.

1 | ```
covidSmooth(par, y)
``` |

`par` |
Logarithms of the variance parameters of drift, seasonal component, and error term |

`y` |
Univariate numeric time series of new COVID-19 cases |

See loglikCovid.

`Xif` |
Matrix of filtered values, where the state vectors are given as rows |

`Xis` |
Matrix of smoothed values, where the state vectors are given as rows |

`Pmat` |
Array of state uncertainty matrices, evaluated at time |

`Pfmat` |
Array of state uncertainty matrices, evaluated at time |

`Psmat` |
Array of state uncertainty matrices, evaluated at time |

Arto Luoma

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ```
#Preparing a time series
library(zoo)
data(dataCovidFin)
timeindex <- dataCovidFin[dataCovidFin$Alue=="Kaikki Alueet","Aika"]
series <- dataCovidFin[dataCovidFin$Alue=="Kaikki Alueet","val"]
series <- window(zoo(series,order.by=timeindex),start="2020-03-01",
end="2021-03-01")
#Fitting a state space model and smoothing the components
p0 <- c(-9,-7,-3.3)
fit <- nlm(loglikCovid,p=p0,y=series)
out <- covidSmooth(fit$estimate,y=series)
#Plotting the filtered and smoothed components
smoothed <- zoo(out$Xis[,1:3],order.by=time(series))
filtered <- zoo(out$Xif[,1:3],order.by=time(series))
colnames(smoothed) <- colnames(filtered) <- c("Level","Drift","Seasonal")
plot(filtered,xlab="Time",main="Filtered components of the time series")
plot(smoothed,xlab="Time",main="Smoothed components of the time series")
#Plotting the original time series, and the filtered and smoothed local level
#series after transforming them to original scale
plot(series,xlab="Time",ylab="Time series")
lines(exp(filtered[,1])-2,col=3)
lines(exp(smoothed[,1])-2,col=2)
legend("topleft",c("original","filtered","smoothed"),col=c(1,3,2),lty=1)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.