View source: R/addNonlinearity.R
addNonlinearity | R Documentation |
This function takes a model and adds a non-linear function if
the likelihood-ratio supports this (via the
anova(..., test = "chisq")
test for stats
while for rms you need to use the rcs()
spline
that is automatically evaluated for non-linearity).
addNonlinearity( model, variable, spline_fn, flex_param = 2:7, min_fn = AIC, sig_level = 0.05, verbal = FALSE, workers, ... ) ## S3 method for class 'negbin' addNonlinearity(model, ...)
model |
The model that is to be evaluated and adapted for non-linearity |
variable |
The name of the parameter that is to be tested for non-linearity. Note that the variable should be included plain (i.e. as a linear variable) form in the model. |
spline_fn |
Either a string or a function that is to be used for testing alternative non-linearity models |
flex_param |
A |
min_fn |
This is the function that we want to minimized if the variable supports
the non-linearity assumption. E.g. |
sig_level |
The significance level for which the non-linearity is deemed as significant, defaults to 0.05. |
verbal |
Set this to |
workers |
The function tries to run everything in parallel. Under some
circumstances you may want to restrict the number of parallel threads to less
than the default |
... |
Passed onto internal |
library(Greg) data("melanoma", package = "boot", envir = environment()) library(dplyr) melanoma <- mutate(melanoma, status = factor(status, levels = 1:3, labels = c("Died from melanoma", "Alive", "Died from other causes")), ulcer = factor(ulcer, levels = 0:1, labels = c("Absent", "Present")), time = time/365.25, # All variables should be in the same time unit sex = factor(sex, levels = 0:1, labels = c("Female", "Male"))) library(survival) model <- coxph(Surv(time, status == "Died from melanoma") ~ sex + age, data = melanoma ) nl_model <- addNonlinearity(model, "age", spline_fn = "pspline", verbal = TRUE, workers = FALSE ) # Note that there is no support for nonlinearity in this case
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.