Description Usage Arguments Details Value Author(s) References See Also Examples
Obtains predictions, forecasts and optionally estimated standard
errors of those predictions from a fitted Mort2Dsmooth
object.
1 2 3 4 |
object |
an object of class "Mort2Dsmooth", usually, a result of
a call to |
newdata |
optionally, a list in which to look for |
type |
the type of prediction required. The default ("link") is on the scale of the linear predictors; the alternative "response" is on the scale of the response variable. |
se.fit |
logical switch indicating if standard errors are
required. Default: |
... |
other predict parameters to passed to
|
If newdata
is omitted the predictions are based on the data
used for the fit. Note that, in common with other prediction
functions, any offset supplied as an argument is always ignored when
predicting, unlike offsets specified in modelling.
The user can provide also a single predictor (either x
or
y
) within the argument newdata
. The name within the list
newdata
must be named x
and y
.
Forecast is possible, therefore newdata
can include
values out of the range of the original x
and y
. See
example below.
Interpolation is also feasible. See example below.
If se.fit = FALSE
, a matrix of predictions. If se.fit =
TRUE
, a list with components:
fit |
a matrix of predictions. |
se.fit |
a matrix of estimated standard errors. |
Carlo G Camarda
Camarda, C. G. (2012). MortalitySmooth: An R Package for Smoothing Poisson Counts with P-Splines. Journal of Statistical Software. 50, 1-24. http://www.jstatsoft.org/v50/i01/.
Currie, I. D., M. Durban, and P. H. C. Eilers (2004). Smoothing and forecasting mortality rates. Statistical Modelling. 4, 279-298.
Mort2Dsmooth
for computing
Mort2Dsmooth.object
.
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | ## computing confidence intervals
## selected data
years <- 1980:2006
ages <- 80:100
death <- selectHMDdata("Denmark", "Deaths", "Females",
ages = ages, years = years)
exposure <- selectHMDdata("Denmark", "Exposures", "Females",
ages = ages, years = years)
## fit
fit <- Mort2Dsmooth(x=ages, y=years, Z=death,
offset=log(exposure),
method=3, lambdas=c(100,500))
## predict and computing standard errors
pre <- predict(fit, se.fit=TRUE)
## plotting over ages and years 95% confidence intervals
## !hard to distinguish between upper
## and lower confidence bounds
grid. <- expand.grid(x = ages, y = years, gr = 1:2)
grid.$lmx <- c(c(pre$fit - 2*pre$se.fit),
c(pre$fit + 2*pre$se.fit))
wireframe(lmx ~ x * y, data = grid., groups = gr,
scales = list(arrows = FALSE),
drape = TRUE, colorkey = TRUE)
## plotting age 80 (first row)
plot(years, log(death[1,] / exposure[1,]),
main="Mortality rates, log-scale.
Danish females, age 80, 1980:2006")
lines(years, pre$fit[1,], lwd=2, col=2)
lines(years, pre$fit[1,] + 2*pre$se.fit[1,],
lwd=2, col=2, lty=2)
lines(years, pre$fit[1,] - 2*pre$se.fit[1,],
lwd=2, col=2, lty=2)
## forecasting example
newyears <- 1980:2020
newdata <- list(x=ages, y=newyears)
pre.for <- predict(fit, newdata=newdata, se.fit=TRUE)
## plot fitted+forecast log-rates for all ages over years
matplot(years, t(log(death/exposure)), pch=1, cex=0.5,
col=rainbow(length(ages)),
xlim=range(newyears),
ylim=range(pre.for$fit),
ylab="log-mortality")
matlines(newyears, t(pre.for$fit), lty=1, lwd=2,
col=rainbow(length(ages)))
## plot selected ages over years, with 95% confidence intervals
whiA <- c(1,6,11)
matplot(years, t(log(death[whiA,]/exposure[whiA,])),
pch=1,
xlim=range(newyears),
ylim=c(-3.3, -1.5),
ylab="log-mortality")
matlines(newyears, t(pre.for$fit[whiA,]), lty=1, lwd=2)
matlines(newyears, t(pre.for$fit[whiA,]+
2*pre.for$se.fit[whiA,]), lty=2)
matlines(newyears, t(pre.for$fit[whiA,]-
2*pre.for$se.fit[whiA,]), lty=2)
## interpolation example
## compute log-death rates for
## each calendar month and calendar ages
newyears12 <- seq(1990, 2000, length=11*11)
newages12 <- seq(90, 100, length=11*11)
newdata12 <- list(x=newages12, y=newyears12)
pre12 <- predict(fit, newdata=newdata12, se.fit=TRUE)
## death rates in June 1995 at age 95.5
which.age <- which(newages12==95.5)
which.year <- which(newyears12==1995.5)
exp(pre12$fit[which.age, which.year] +
c(-2*pre12$se.fit[which.age, which.year],
0, 2*pre12$se.fit[which.age, which.year]))
|
Loading required package: svcm
Loading required package: Matrix
Loading required package: splines
Loading required package: lattice
[1] 0.3166732 0.3211764 0.3257437
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.