testLinear | R Documentation |
This function fits restricted cubic splines to linear and generalized linear models to detect non-linear relationship between outcome (dependent variable) and exposure, a single independent variable. It allows for controlling for covariates. The output includes (1) a set of p-values from the likelihood ratio tests for non-linearity (test 1), overall association (test 2) and linear relation between independent variable and outcome (test 3) and (2) a graph of the predicted outcome values and pointwise confidence bands versus exposure of interest, together with a density plot of the exposure. For binary outcome, the predicted outcome is odds ratio. Use restricted cubic spline model to test linear assumption on linear, log and logit scale and graph fitted curve.
testLinear(
ds,
var,
outcome,
adj = NULL,
nknots = 5,
knotsvalues = NULL,
method = "lm",
family,
link,
ref = NULL,
densplot = FALSE
)
ds |
The input dataframe. This dataframe should minimally include variables indicated in 'adj', 'var' and 'outcome'.Required. |
var |
single character representing independent variable being evaluated for linear relationship with 'outcome'. Required. |
outcome |
single character representing dependent variable being evaluated for linear relationship with 'var'.Required. |
adj |
Character vector of covariates to be adjusted in the model. For graphing purpose, mean values will be used for numeric values and mode will be used for binary and character variables. |
nknots |
Number of knots. Default is 5. The minimum value is 3 (i.e. one inner knot two outer knots).Required. |
knotsvalues |
knot locations. If not given, knots will be estimated using default quantiles of 'var'. For 3 knots, the outer quantiles used are 0.10 and 0.90. For 4-6 knots, the outer quantiles used are 0.05 and 0.95. For nk>6, the outer quantiles are 0.025 and 0.975. The knots are equally spaced between these on the quantile scale. For fewer than 100 non-missing values of 'var', the outer knots are the 5th smallest and largest 'var'. Must be unique values. |
method |
Methods for modeling, currently only 'lm' or 'glm' methods are available. Required. |
family |
Family parameter to pass to glm function. Not a character. Required if method="glm". |
link |
Link parameter to pass to glm function. Should be character. Required if method="glm". |
ref |
Reference value to be used. If not specified, use minimum of exposure values. Optional. |
densplot |
Produce exposure density plot. Default is FALSE. |
Two-object list that includes a printable dataframe of non-linearity test results and a fitted curve graph.
Wenze Tang and Molin Wang
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.