Title: | Perform Linear or Nonlinear Cross Lag Analysis |
---|---|
Description: | Linear or nonlinear cross-lagged panel model can be built from input data. Users can choose the appropriate method from three methods for constructing nonlinear cross lagged models. These three methods include polynomial regression, generalized additive model and generalized linear mixed model.In addition, a function for determining linear relationships is provided. Relevant knowledge of cross lagged models can be learned through the paper by Fredrik Falkenström (2024) <doi:10.1016/j.cpr.2024.102435> and the paper by A Gasparrini (2010) <doi:10.1002/sim.3940>. |
Authors: | Yaxin Li [aut, cre] |
Maintainer: | Yaxin Li <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-02-12 04:41:45 UTC |
Source: | https://github.com/cran/crosslag |
Title Generate covariates' residuals
adjust_target(X, y1, y2 = NULL, cor_vars)
adjust_target(X, y1, y2 = NULL, cor_vars)
X |
A dataset containing y1, y2, and covariates. The row name is the name of x,y and covariate |
y1 |
If cross lagged analysis is used between x and y, 'y1' is the name of x. |
y2 |
y2 can be NULL. If cross lagged analysis is used between x and y, 'y2' is the name of y. 'y1' and 'y2' come from the same time point. |
cor_vars |
the name of covariate |
a list containing the covariate-adjusted value of y1 and y2 (If y2 is not NULL)
data(test_data1) result <- adjust_target(X=test_data1,y1="ASI",y2=NULL,cor_vars=c("HDL_C","LDL_C"))
data(test_data1) result <- adjust_target(X=test_data1,y1="ASI",y2=NULL,cor_vars=c("HDL_C","LDL_C"))
Title Nonlinear Cross Lag Analysis
clpm_gam_c(xname, yname, data.x1, data.y1, data.xt, data.yt)
clpm_gam_c(xname, yname, data.x1, data.y1, data.xt, data.yt)
xname |
If nonlinear cross lagged analysis is used between x and y, 'xname' is the name of x |
yname |
If nonlinear cross lagged analysis is used between x and y, 'yname' is the name of y |
data.x1 |
A numeric variable. |
data.y1 |
A numeric variable. 'data.x1' and 'data.y1' comes from the first time point |
data.xt |
A numeric variable. |
data.yt |
A numeric variable. 'data.xt' and 'data.yt' comes from the another time point |
A list containing two elements
clpm_gam_result |
a dataframe containing the result of nonlinear cross lag analysis |
clpm_gam_plot |
a list of plot generated by 'ggplot' and 'ggarrange', you can use 'ggarrange(clpm_gam_plot[[2]])' to plot it |
data(test_data1) data(test_data2) result <- clpm_gam_c(xname="ASI",yname = "PWRI", data.x1 = test_data1$ASI,data.y1 = test_data1$PWRI, data.xt = test_data2$ASI,data.yt = test_data2$PWRI)
data(test_data1) data(test_data2) result <- clpm_gam_c(xname="ASI",yname = "PWRI", data.x1 = test_data1$ASI,data.y1 = test_data1$PWRI, data.xt = test_data2$ASI,data.yt = test_data2$PWRI)
Title Nonlinear Cross Lag Analysis: autoregression
clpm_gam_r(xname, yname, data.x1, data.y1, data.xt, data.yt)
clpm_gam_r(xname, yname, data.x1, data.y1, data.xt, data.yt)
xname |
If cross lagged analysis is used between x and y, 'xname' is the name of x |
yname |
If cross lagged analysis is used between x and y, 'yname' is the name of y |
data.x1 |
A numeric variable. |
data.y1 |
A numeric variable. 'data.x1' and 'data.y1' comes from the first time point |
data.xt |
A numeric variable. |
data.yt |
A numeric variable. 'data.xt' and 'data.yt' comes from the another time point |
A dataframe containing the result of autoregression: 'Xt~X1' 'Yt~Y1'
data(test_data1) data(test_data2) clpm_gam_r(xname="ASI",yname = "PWRI",data.x1 = test_data1$ASI, data.y1 = test_data1$PWRI,data.xt = test_data2$ASI,data.yt = test_data2$PWRI)
data(test_data1) data(test_data2) clpm_gam_r(xname="ASI",yname = "PWRI",data.x1 = test_data1$ASI, data.y1 = test_data1$PWRI,data.xt = test_data2$ASI,data.yt = test_data2$PWRI)
Title Cross-lag analysis based on generalized additive mixture models
clpm_gamm4_c(xname, yname, data.x1, data.y1, data.xt, data.yt, z)
clpm_gamm4_c(xname, yname, data.x1, data.y1, data.xt, data.yt, z)
xname |
If cross lagged analysis is used between x and y, 'xname' is the name of x |
yname |
If cross lagged analysis is used between x and y, 'yname' is the name of y |
data.x1 |
A numeric variable. |
data.y1 |
A numeric variable. 'data.x1' and 'data.y1' comes from the first time point |
data.xt |
A numeric variable. |
data.yt |
A numeric variable. 'data.xt' and 'data.yt' comes from the another time point 'data.x1', 'data.y1','data.xt' and 'data.yt' can be the data processed by the function 'adjust_target()' |
z |
In the generalized additive mixture model, a random intercept is specified and the random effects are grouped by z. 'z' and 'data.x1', 'data.y1','data.xt','data.yt' are all numeric variables that should ideally correspond to each other. |
A dataframe containing the result of generalized additive mixture model (consists of a smoothing term, a linear term and a stochastic intercept).
data(test_data1) data(test_data2) result <- clpm_gamm4_c("ASI","PWRI",test_data1$ASI,test_data1$PWRI, data.xt = test_data2$ASI,data.yt = test_data2$PWRI,z=test_data1$time)
data(test_data1) data(test_data2) result <- clpm_gamm4_c("ASI","PWRI",test_data1$ASI,test_data1$PWRI, data.xt = test_data2$ASI,data.yt = test_data2$PWRI,z=test_data1$time)
Title Cross-lag analysis based on generalized additive mixture models: autoregression
clpm_gamm4_r(xname, yname, data.x1, data.y1, data.xt, data.yt, z)
clpm_gamm4_r(xname, yname, data.x1, data.y1, data.xt, data.yt, z)
xname |
If cross lagged analysis is used between x and y, 'xname' is the name of x |
yname |
If cross lagged analysis is used between x and y, 'yname' is the name of y |
data.x1 |
A numeric variable. |
data.y1 |
A numeric variable. 'data.x1' and 'data.y1' comes from the first time point |
data.xt |
A numeric variable. |
data.yt |
A numeric variable. 'data.xt' and 'data.yt' comes from the another time point 'data.x1', 'data.y1','data.xt' and 'data.yt' can be the data processed by the function 'adjust_target()' |
z |
In the generalized additive mixture model, a random intercept is specified and the random effects are grouped by z. 'z' and 'data.x1', 'data.y1','data.xt','data.yt' are all numeric variables that should ideally correspond to each other. |
A dataframe containing the result of autoregression based on generalized additive mixture model:'Xt~X1' 'Yt~Y1'.
data(test_data1) data(test_data2) result <- clpm_gamm4_r("ASI","PWRI",test_data1$ASI,test_data1$PWRI, data.xt = test_data2$ASI,data.yt = test_data2$PWRI,z=test_data1$time)
data(test_data1) data(test_data2) result <- clpm_gamm4_r("ASI","PWRI",test_data1$ASI,test_data1$PWRI, data.xt = test_data2$ASI,data.yt = test_data2$PWRI,z=test_data1$time)
Title Nonlinear Cross Lag Analysis based on Polynomial linear regression
clpm_poly_c(xname, yname, data1, data2, adjust = FALSE, adjust_name = NULL)
clpm_poly_c(xname, yname, data1, data2, adjust = FALSE, adjust_name = NULL)
xname |
If cross lagged analysis is used between x and y, 'xname' is the name of x |
yname |
If cross lagged analysis is used between x and y, 'xname' is the name of x |
data1 |
A dataframe containing data of x and y at the same time point. If covariate adjustments are made (adjust=T), data of covariates should also be included. The input 'xname','yname' and 'adjust_name' is written in the same way among the 'data1' column names |
data2 |
A dataframe containing data of x and y at the another time point. If covariate adjustments are made (adjust=T), data of covariates should also be included. The input 'xname','yname' and 'adjust_name' is written in the same way among the 'data2' column names |
adjust |
The default value is F. If you want to perform covariate adjustments on x and y based on adjust_target(), please use T. |
adjust_name |
The name of the covariate, corresponding to the data contained in data1 or data2. If there are multiple covariates, they need to be saved in a vector. |
A dataframe containing the result of Nonlinear Cross Lag Analysis after polynomial regression
data(test_data1) data(test_data2) # Not adjusting for covariates result <- clpm_poly_c(xname = "PWRI",yname = "LDL_C", data1 = test_data1,data2 = test_data2,adjust = FALSE) # Adjust for covariates result_ad <- clpm_poly_c(xname = "ASI",yname = "PWRI", data1 = test_data1,data2 = test_data2, adjust = TRUE,adjust_name=c("HDL_C","LDL_C"))
data(test_data1) data(test_data2) # Not adjusting for covariates result <- clpm_poly_c(xname = "PWRI",yname = "LDL_C", data1 = test_data1,data2 = test_data2,adjust = FALSE) # Adjust for covariates result_ad <- clpm_poly_c(xname = "ASI",yname = "PWRI", data1 = test_data1,data2 = test_data2, adjust = TRUE,adjust_name=c("HDL_C","LDL_C"))
Title Nonlinear Cross Lag Analysis based on Polynomial linear regression: autoregression
clpm_poly_r(xname, yname, data1, data2, adjust = FALSE, adjust_name = NULL)
clpm_poly_r(xname, yname, data1, data2, adjust = FALSE, adjust_name = NULL)
xname |
If cross lagged analysis is used between x and y, 'xname' is the name of x |
yname |
If cross lagged analysis is used between x and y, 'xname' is the name of x |
data1 |
A dataframe containing data of x and y at the same time point. If covariate adjustments are made (adjust=T), data of covariates should also be included. The input 'xname','yname' and 'adjust_name' is written in the same way among the 'data1' column names |
data2 |
A dataframe containing data of x and y at the another time point. If covariate adjustments are made (adjust=T), data of covariates should also be included. The input 'xname','yname' and 'adjust_name' is written in the same way among the 'data2' column names |
adjust |
The default value is F. If you want to perform covariate adjustments on x and y based on adjust_target(), please use T. |
adjust_name |
The name of the covariate, corresponding to the data contained in data1 or data2. If there are multiple covariates, they need to be saved in a vector. |
A dataframe containing the result of Nonlinear Cross Lag Analysis after polynomial regression: Xt~X1,Yt~Y1
data(test_data1) data(test_data2) # Not adjusting for covariates result <- clpm_poly_r(xname = "ASI",yname = "PWRI", data1 = test_data1,data2 = test_data2,adjust = FALSE) # Adjust for covariates result_ad <- clpm_poly_r(xname = "ASI",yname = "PWRI", data1 = test_data1,data2 = test_data2, adjust = TRUE,adjust_name=c("HDL_C","LDL_C"))
data(test_data1) data(test_data2) # Not adjusting for covariates result <- clpm_poly_r(xname = "ASI",yname = "PWRI", data1 = test_data1,data2 = test_data2,adjust = FALSE) # Adjust for covariates result_ad <- clpm_poly_r(xname = "ASI",yname = "PWRI", data1 = test_data1,data2 = test_data2, adjust = TRUE,adjust_name=c("HDL_C","LDL_C"))
Title Linear Cross lagged analysis
crlog_line(xname, yname, data.x1, data.y1, data.xt, data.yt)
crlog_line(xname, yname, data.x1, data.y1, data.xt, data.yt)
xname |
If linear cross lagged analysis is used between x and y, 'xname' is the name of x |
yname |
If linear cross lagged analysis is used between x and y, 'yname' is the name of y |
data.x1 |
A numeric variable. |
data.y1 |
A numeric variable. 'data.x1' and 'data.y1' comes from the first time point |
data.xt |
A numeric variable. |
data.yt |
A numeric variable. 'data.xt' and 'data.yt' comes from the another time point |
a datafrme containing 'Relation','beta','se','z','pvalue','x','y','rmr' and 'cfi'. Relation: This is a string that represents the relationship between the variables. beta: This is the estimated coefficient of the model. p: This is the p-value of the model coefficient, used to test whether the coefficient is significantly different from 0. x: This is the input xname, representing the name of the x variable. y: This is the input yname, representing the name of the y variable. rmr: This is one of the model fit measures, representing the root mean square residual of the model. cfi: This is one of the model fit measures, representing the comparative fit index of the model.
data(test_data1) data(test_data2) result <- crlog_line(xname="ASI",yname = "PWRI",data.x1 = test_data1$ASI, data.y1 = test_data1$PWRI,data.xt = test_data2$ASI, data.yt = test_data2$PWRI)
data(test_data1) data(test_data2) result <- crlog_line(xname="ASI",yname = "PWRI",data.x1 = test_data1$ASI, data.y1 = test_data1$PWRI,data.xt = test_data2$ASI, data.yt = test_data2$PWRI)
Title Determine a linear relationship between x and y by Restricted Cubic Splines(RCS) and plot it
judge_line(xname, yname, Data, parm)
judge_line(xname, yname, Data, parm)
xname |
A character, the name of the x. If there are multiple covariates, they need to be saved in a vector |
yname |
A character, the name of the y. If there are multiple covariates, they need to be saved in a vector |
Data |
A dataframe containing data of x and y. The input 'xname' and 'yname' is written in the same way among the 'Data' column names |
parm |
the number of knots of RCS |
A list containing the information of RCS plots. You can use 'ggpubr::ggarrange()' to plot the list. The list is a list of ggplot objects. Each ggplot object is a plot that represents the relationship between one independent variable (from xname) and one dependent variable (from yname). These plots are based on a linear regression model that uses a restricted cubic spline to handle the independent variable. Each plot includes a line of predicted values (solid blue line) and a confidence interval for these predictions (transparent blue area). The title of each plot includes the p-value for non-linearity, as well as the names of the independent and dependent variables.
data(test_data1) # Get RCS plots result <- judge_line(xname="ASI",yname="HDL_C",Data = test_data1,parm = 4) ## Plot an RCS curve graph ggpubr::ggarrange(result[[1]]) # Simultaneously determining multiple linear relationships results <- judge_line("ASI",c("HDL_C","LDL_C"),Data = test_data1,parm = 4) ## Plot many RCS curve graphs ## Adjust 'nrow' and 'ncol' according to actual situation ggpubr::ggarrange(plotlist = results, nrow = 1, ncol = 2)
data(test_data1) # Get RCS plots result <- judge_line(xname="ASI",yname="HDL_C",Data = test_data1,parm = 4) ## Plot an RCS curve graph ggpubr::ggarrange(result[[1]]) # Simultaneously determining multiple linear relationships results <- judge_line("ASI",c("HDL_C","LDL_C"),Data = test_data1,parm = 4) ## Plot many RCS curve graphs ## Adjust 'nrow' and 'ncol' according to actual situation ggpubr::ggarrange(plotlist = results, nrow = 1, ncol = 2)
Data for the first time point used for testing
A dataframe.
Generated from case information of a hospital in Hebei province
data(test_data1)
data(test_data1)
Data for the second time point used for testing
A dataframe.
Generated from case information of a hospital in Hebei province
data(test_data2)
data(test_data2)