# psPoisson: Smoothing scattered Poisson data using P-splines. In JOPS: Practical Smoothing with P-Splines

 psPoisson R Documentation

## Smoothing scattered Poisson data using P-splines.

### Description

`psPoisson` is used to smooth scattered Poisson data using P-splines with a log link function.

### Usage

``````psPoisson(
x,
y,
xl = min(x),
xr = max(x),
nseg = 10,
bdeg = 3,
pord = 2,
lambda = 1,
wts = NULL,
show = FALSE,
iter = 100,
xgrid = 100
)
``````

### Arguments

 `x` the vector for the continuous regressor of `length(y)` and the abcissae used to build the B-spline basis. `y` the response vector, usually count data. `xl` the number for the min along `x` (default is min(`x`)). `xr` the number for the max along `x` (default is max(`x`)). `nseg` the number of evenly spaced segments between `xl` and `xr` (default 10). `bdeg` the number of the degree of the basis, usually 1, 2, or 3 (defalult). `pord` the number of the order of the difference penalty, usually 1, 2 (default), or 3. `lambda` the (positive) number for the tuning parameter for the penalty (default 1). `wts` the vector of general weights, zeros are allowed (default 1). `show` Set to TRUE or FALSE to display iteration history (default FALSE). `iter` a scalar to set the maximum number of iterations, default `iter=100`. `xgrid` a scalar or a vector that gives the `x` locations for prediction, useful for plotting. If a scalar (default 100) is used then a uniform grid of this size along (`xl`, `xr`).

### Value

 `pcoef` a vector of length `n` of estimated P-spline coefficients. `muhat` a vector of length `m` of estimated means. `B` the `m` by `n` B-spline basis. `dev` deviance of fit. `effdim` effective dimension of fit. `aic` AIC. `wts` the vector of given prior weights. `nseg` the number of B-spline segments. `bdeg` the degree of the B-spline basis. `pord` the order of the difference penalty. `lambda` the positive tuning parameter. `family` the family of the response ( `"Poisson"`). `link` the link function used (`"log"`). `xgrid` gridded x values, useful for plotting. `ygrid` gridded fitted linear predictor values, useful for plotting. `mugrid` gridded (inverse link) fitted mean values, useful for plotting. `se_eta` gridded standard errors for the linear predictor. `dispersion` Dispersion parameter estimated `dev/(m-effdim)`.

### Author(s)

Paul Eilers and Brian Marx

### References

Eilers, P.H.C. and Marx, B.D. (2021). Practical Smoothing, The Joys of P-splines. Cambridge University Press.

Eilers, P.H.C., Marx, B.D., and Durban, M. (2015). Twenty years of P-splines, SORT, 39(2): 149-186.

### Examples

``````library(JOPS)
library(boot)

# Extract the data
Count <- hist(boot::coal\$date, breaks = c(1851:1963), plot = FALSE)\$counts
Year <- c(1851:1962)
xl <- min(Year)
xr <- max(Year)

# Poisson smoothing
nseg <- 20
bdeg <- 3
fit1 <- psPoisson(Year, Count, xl, xr, nseg, bdeg, pord = 2, lambda = 1)
plot(fit1, xlab = "Year", ylab = "Count", se = 2)
``````

JOPS documentation built on Sept. 8, 2023, 5:42 p.m.