Learn R Programming

FlexGAM (version 0.7.2)

predict.flexgam: Predicts values for the object of class flexgam

Description

Predicts values for the given object and a given dataset.

Usage

# S3 method for flexgam
predict(object, newdata=NULL, type=c("response","linear.predictor", 
        "terms"), ...)

Arguments

object

Object of class flexgam.

newdata

New data to build predicted values. Same behaviour as in standard predict.

type

Should the fitted values ('response') or the linear predictor ('linear.predictor') be predicted. Alternatively the linear predictor for each covariate separately is given ('terms').

...

Currently not used

Value

Numeric vector or matrix of fitted values

Details

Calculates the predicted values for the given model.

References

Spiegel, Elmar, Thomas Kneib and Fabian Otto-Sobotka. Generalized additive models with flexible response functions. Statistics and Computing (2017). https://doi.org/10.1007/s11222-017-9799-6

See Also

flexgam, deviance.flexgam, response.flexgam

Examples

Run this code
# NOT RUN {
set.seed(1)
n <- 1000
x1 <- runif(n)
x2 <- runif(n)
x3 <- runif(n)
eta_orig <- -1 + 2*sin(6*x1) + exp(x2) + x3
pi_orig <- pgamma(eta_orig, shape=2, rate=sqrt(2))
y <- rbinom(n,size=1,prob=pi_orig)

Data <- data.frame(y,x1,x2,x3)
formula <- y ~ s(x1,k=20,bs="ps") + s(x2,k=20,bs="ps") + x3

# Fix smoothing parameters to save computational time.
control2 <- list("fix_smooth" = TRUE, "quietly" = TRUE, "sm_par_vec" = 
                     c("lambda" = 100, "s(x1)" = 2000, "s(x2)" = 9000))

set.seed(2)
model_2 <- flexgam(formula=formula, data=Data, type="FlexGAM2", 
                   family=binomial(link=logit), control = control2)


set.seed(2)
n <- 1000
x1 <- runif(n)
x2 <- runif(n)
x3 <- runif(n)
eta_orig <- -1 + 2*sin(6*x1) + exp(x2) + x3
pi_orig <- pgamma(eta_orig, shape=2, rate=sqrt(2))
y <- rbinom(n,size=1,prob=pi_orig)

newData <- data.frame(y,x1,x2,x3)

fitted_2 <- predict(model_2, newdata=newData)

# }

Run the code above in your browser using DataLab