# psBinomial: Smoothing scattered binomial data using P-splines. In JOPS: Practical Smoothing with P-Splines

 psBinomial R Documentation

## Smoothing scattered binomial data using P-splines.

### Description

`psBinomial` is used to smooth scattered binomial data using P-splines using a logit link function.

### Usage

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

### Arguments

 `x` the vector for the continuous regressor of `length(y)` and the abcissae, on which the B-spline basis is constructed. `y` the response vector, usually 0/1 or binomial counts. `xl` the lower limit for the domain of `x` (default is min(`x`)). `xr` the upper limit for the domain of `x` (default is max(`x`)). `nseg` the number of evenly spaced segments between xl and xr. `bdeg` the number of the degree of the basis, usually 1, 2 (default), or 3. `pord` the number of the order of the difference penalty, usually 1, 2, or 3 (defalult). `lambda` the (positive) number for the tuning parameter for the penalty. `ntrials` the vector for the number of binomial trials (default = 1). `wts` the vector of weights, default is 1, zeros allowed. `show` Set to TRUE or FALSE to display iteration history. `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. `p` a vector of length `m` of estimated probabilities. `muhat` a vector of length `m` of estimated means (`ntrials*p`). `dev` deviance `effdim` effective dimension of the smooth. `aic` AIC `wts` a vector of preset weights (default = 1). `nseg` the number of B-spline segments. `bdeg` the degree of the B-spline basis. `pord` the order of the difference penalty. `family` the GLM family (repsonse distribution). `link` the link function. `y` the binomial response. `x` the regressor on which the basis is constructed. `P` "half" of the penalty matrix, `P'P = lambda*D'D`. `B` the B-spline basis. `lambda` the positive tuning parameter. `dispersion` dispersion parameter estimated `dev/(m-effdim)`. `xgrid` gridded `x` values,useful for plotting. `ygrid` gridded fitted linear predictor values, useful for plotting. `pgrid` gridded (inverse link) fitted probability values, useful for plotting. `se_eta` gridded standard errors for the linear predictor.

### 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)
# Extract data
library(rpart)
Kyphosis <- kyphosis\$Kyphosis
Age <- kyphosis\$Age
y <- 1 * (Kyphosis == "present") # make y 0/1
fit1 <- psBinomial(Age, y,
xl = min(Age), xr = max(Age), nseg = 20,
bdeg = 3, pord = 2, lambda = 10
)
names(fit1)
plot(fit1, xlab = "Age", ylab = "0/1", se = 2)
``````

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