### Install dosresmeta Package from GitHub Source: https://github.com/alecri/dosresmeta/blob/master/README.md This R code installs a development version of the 'dosresmeta' package directly from GitHub. It first installs the 'devtools' package if it's not already installed, then uses 'install_github' to fetch and install the package. This is useful for accessing the latest features or bug fixes. ```R install.packages("devtools") devtools::install_github("alecri/dosresmeta") ``` -------------------------------- ### Display dosresmeta Package Help Page Source: https://github.com/alecri/dosresmeta/blob/master/README.md This code snippet displays the main help page for the 'dosresmeta' R package. It requires the package to be installed. This is useful for getting a quick overview of the package's functionality and structure. ```R help("dosresmeta-package") ``` -------------------------------- ### R: Example Usage of dosresmeta Function with Control Options Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.control.html Demonstrates how to load data and use the `dosresmeta` function, potentially with control options implicitly passed through arguments. This example shows a basic application of the meta-analysis function, implying the use of default or user-specified control parameters for the fitting process. ```R data("alcohol_cvd") dosresmeta(formula = logrr ~ dose, type = type, id = id, se = se, ``` -------------------------------- ### Install dosresmeta Package from CRAN Source: https://github.com/alecri/dosresmeta/blob/master/README.md This R code installs the latest stable version of the 'dosresmeta' package from the Comprehensive R Archive Network (CRAN). This is the recommended method for general use. ```R install.packages("dosresmeta") ``` -------------------------------- ### Example Usage of fracpol for Dose-Response Modeling - R Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/fracpol.html This R example shows how to load data, apply the fracpol transformation within a dosresmeta model formula, and then test the significance of the dose-response association using a Wald test. It utilizes the 'alcohol_cvd' dataset and the 'dosresmeta' and 'waldtest' functions. ```R data("alcohol_cvd") with(alcohol_cvd, fracpol(dose, p = c(.5, .5))) model <- dosresmeta(formula = logrr ~ fracpol(dose, p = c(.5, .5)), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd) waldtest(b = coef(model), Sigma = vcov(model), Terms = 1:nrow(vcov(model))) ``` -------------------------------- ### Example: Quadratic Dose-Response Model and VPC Plot (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/vpc.html This example demonstrates how to fit a quadratic dose-response model using 'dosresmeta' and then visualize the variance partition components (vpc) against dose. It involves loading data, fitting the model, and then plotting the results using base R plotting functions like 'plot' and 'lines'. Note the warning about convergence not being reached. ```R # Loading data data("sim_os") # Quadratic (one-stage) dose-response model quadr <- dosresmeta(logrr ~ dose + I(dose^2), id = id, se = se, type = type, cases = cases, n = n, data = sim_os, proc = "1stage") # Warning: convergence not reached after maximum number of iterations # Plot of the estimated vpc plot(sim_os$dose[sim_os$se!=0], vpc(quadr), xlab = "dose") lines(sim_os$dose[sim_os$se!=0], lowess(sim_os$dose[sim_os$se!=0], vpc(quadr))) ``` -------------------------------- ### Dosresmeta Function Call Example Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.control.html This R code snippet demonstrates a typical call to the dosresmeta function for performing a dose-response meta-analysis. It specifies the formula, data, and control parameters for the analysis. ```r dosresmeta(formula = logrr ~ dose, id = id, type = type, cases = cases, n = n, data = alcohol_cvd, se = se, proc = "1stage", control = list(showiter = TRUE, igls.inititer = 20)) ``` -------------------------------- ### Example: Obtaining pseudo-counts for a single study in R Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/hamling.html This example demonstrates how to use the `hamling` function to obtain pseudo-counts for a specific study within the `alcohol_cvd` dataset. It subsets the data for `id = 1` and passes the relevant variables to the `hamling` function. ```R data("alcohol_cvd") hamling(y = logrr, v = I(se^2), cases = cases, n = n, type = type, data = subset(alcohol_cvd, id == 1)) ``` -------------------------------- ### Example: Test Significance of Dose-Response Association (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/waldtest.html This example demonstrates how to load data, fit a `dosresmeta` model, and then perform a Wald test to assess the significance of the overall dose-response association. It extracts coefficients and their variance-covariance matrix from the fitted model and uses them as input for the `waldtest` function. ```r data("alcohol_cvd") model <- dosresmeta(formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd) waldtest(b = coef(model), Sigma = vcov(model), Terms = 1:nrow(vcov(model))) ``` -------------------------------- ### Example: Obtaining pseudo-counts for all studies in R Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/hamling.html This example shows how to apply the `hamling` function to each study group within the `alcohol_cvd` dataset using the `by` function. It iterates through each `id` in the dataset and computes the pseudo-counts for the studies belonging to that `id`. ```R by(alcohol_cvd, alcohol_cvd$id, function(x) hamling(y = logrr, v = I(se^2), cases = cases, n = n, type = type, data = x)) ``` -------------------------------- ### Fit Continuous Outcome (SMD) with dosresmeta Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.html This example shows how to fit a dose-response meta-analysis for a continuous outcome using standardized mean differences (SMD). The dosresmeta function is used with a quadratic dose term, specifying 'smd' for the covariance. The summary output details the fixed-effects coefficients and heterogeneity. ```R data("ari") mod3 <- dosresmeta(formula = y ~ dose + I(dose^2), id = id, sd = sd, n = n, covariance = "smd", data = ari) summary(mod3) ``` -------------------------------- ### Compute Covariance Matrix for First Study (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/covar.logrr.html This example demonstrates how to compute the covariance matrix of log relative risks for the first study in the `alcohol_cvd` dataset. It utilizes the `covar.logrr` function with specific arguments for log relative risk, variance, cases, total subjects, and study type, subsetting the data for the first study. ```r ## Loading data data("alcohol_cvd") ## Obtaining the (co)variance matrix of log RR for the first study (id = 1) covar.logrr(y = logrr, v = I(se^2), cases = cases, n = n, type = type, data = subset(alcohol_cvd, id == 1)) ``` -------------------------------- ### Iterative Generalized Least Squares (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/mlprof.fun.html The iter.igls function in R performs an iterative generalized least squares algorithm. It is used to obtain starting values for optimization routines in random-effects meta-analysis models. ```R iter.igls(Psi, Xlist, Zlist, ylist, Slist, nalist, q) ``` -------------------------------- ### Compute Covariance Matrix for All Studies (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/covar.logrr.html This example shows how to compute the covariance matrices of log relative risks for all studies in the `alcohol_cvd` dataset. It uses the `by` function to apply `covar.logrr` to each study group defined by `id`, providing the necessary arguments for each subset. ```r ## Obtaining the (co)variance matrices of log RRfor all study by(alcohol_cvd, alcohol_cvd$id, function(x) covar.logrr(y = logrr, v = I(se^2), cases = cases, n = n, type = type, data = x)) ``` -------------------------------- ### R: Control Parameters for dosresmeta Model Fitting Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.control.html Defines the control parameters for fitting dose-response meta-analytical models. This function sets default values for optimization and model fitting, and it is usually called internally by `dosresmeta.fit`. It allows customization of optimization algorithms, starting values, and convergence criteria. ```R dosresmeta.control(optim = list(), showiter = FALSE, maxiter = 100, initPsi = NULL, Psifix = NULL, Scor = NULL, addSlist = NULL, inputna = FALSE, inputvar = 10^4, loglik.iter = "hybrid", igls.inititer = 10, gr = FALSE, hessian = FALSE, vc.adj = TRUE, reltol = sqrt(.Machine$double.eps), checkPD = NULL, set.negeigen = sqrt(.Machine$double.eps)) ``` -------------------------------- ### Compute MD using covar.smd in R Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/covar.smd.html This example shows how to compute mean differences (md) for all studies in the 'ari' dataset using the covar.smd function. It applies the function to each study group defined by 'id' and then extracts the mean differences, variances, and covariance matrices from the results. ```R cov.md <- by(ari, ari$id, function(x) covar.smd(y, sd, n, "md", data = x)) # Extracting mean differences unlist(lapply(cov.md, function(x) x$y)) # Extracting variances for the mean differences unlist(lapply(cov.md, function(x) x$v)) # List of the (co)variance matrices for the mean differences lapply(cov.md, function(x) x$S) ``` -------------------------------- ### Compute SMD using covar.smd in R Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/covar.smd.html This example demonstrates how to use the covar.smd function to calculate standardized mean differences (smd) for a specific study subset. It takes outcome means, standard deviations, and sample sizes as input, along with the desired measure and method. The output includes the calculated SMD values, their variances, and the covariance matrix. ```R covar.smd(y, sd, n, measure = "smd", data = subset(ari, id == 1)) ``` -------------------------------- ### dosresmeta.fit Function Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.html A wrapper for actual fitting functions used by dosresmeta, implementing various estimation methods. ```APIDOC ## DOSRESMETA.FIT Function ### Description A wrapper for actual fitting functions based on different estimation methods, usually called internally by `dosresmeta`. ### Method `dosresmeta.fit` ### Endpoint N/A (R Function) ### Arguments - **X** (matrix) - Processed design matrix of fixed effects. - **Z** (matrix) - Processed design matrix of random effects. - **y** (vector) - Processed outcome vector. - **Slist** (list) - List of approximated or given (co)variance matrices. - **id** (vector) - Study ID vector. - **method** (string) - Estimation method ('fixed', 'ml', 'reml', 'mm'). - **control** (list) - Parameters for controlling the fitting process. - **proc** (string) - Procedure type ('2stage' or '1stage'). - **mod** (formula) - Meta-regression model formula. - **v** (vector) - Variances of the outcome. - **data** (data frame) - Data frame containing the variables. ### Value Returns the results of the fitting process, typically used internally by `dosresmeta`. ``` -------------------------------- ### Print dosresmeta Model Summary (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/summary.dosresmeta.html The `print.summary.dosresmeta` function displays a concise summary of the `dosresmeta` model results. It can show significance stars and is customizable regarding the number of digits displayed. This provides a quick overview of the model's key findings. ```R model <- dosresmeta(formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd) print(model, digit = 2) ``` -------------------------------- ### Summarize and Print dosresmeta Model Results Source: https://context7.com/alecri/dosresmeta/llms.txt Demonstrates how to print and summarize a fitted dosresmeta model object, including controlling decimal places and confidence interval levels. This provides a comprehensive overview of the model's findings. Requires the dosresmeta package. ```r data("alcohol_cvd") model <- dosresmeta( formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd ) print(model) print(model, digits = 2) summary(model) summary(model, ci.level = 0.90) ``` -------------------------------- ### Compute Variance Partition Components (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/vpc.html The 'vpc' function computes variance partition components for dose-response meta-analysis. It requires an object of class 'dosresmeta' as input and returns a vector of variance partition components for each non-referent observation. No external dependencies are needed beyond the 'dosresmeta' package itself. ```R vpc(object) # Arguments: # object: An object of class 'dosresmeta' produced by 'dosresmeta'. # # Value: # A vector containing the variance partition components for each non-referent observation. ``` -------------------------------- ### Summarize dosresmeta Model (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/summary.dosresmeta.html The `summary.dosresmeta` function computes additional statistics and tests for a fitted `dosresmeta` model. It returns a list object of class `summary.dosresmeta` containing details on coefficients, heterogeneity, and model fit. This function is crucial for a comprehensive analysis of dose-response relationships. ```R model <- dosresmeta(formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd) summary(model, ci.level = .8) ``` -------------------------------- ### Fit Single Case-Control Study using dosresmeta (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.html This snippet demonstrates fitting a linear dose-response trend for a single case-control study using the dosresmeta function. It requires specifying the formula, study type, and data columns for cases, sample size, lower bound, and upper bound. The output includes a summary of the fixed-effects meta-analysis. ```r data("cc_ex") mod1 <- dosresmeta(formula = logrr ~ dose, type = "cc", cases = case, n = n, lb = lb, ub = ub, data= cc_ex) summary(mod1) ``` -------------------------------- ### Fit dosresmeta Model and Perform Wald Tests Source: https://context7.com/alecri/dosresmeta/llms.txt Loads data, fits a dose-response meta-analysis model using dosresmeta, and performs overall and specific coefficient Wald tests. It also demonstrates testing linear combinations using an L matrix. Requires the dosresmeta package. ```r data("alcohol_cvd") model <- dosresmeta( formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd ) wald_overall <- waldtest( b = coef(model), Sigma = vcov(model), Terms = 1:nrow(vcov(model)) ) print(wald_overall) wald_quad <- waldtest( b = coef(model), Sigma = vcov(model), Terms = 2 ) L <- matrix(c(1, 0), nrow = 1) wald_custom <- waldtest( b = coef(model), Sigma = vcov(model), L = L ) ``` -------------------------------- ### Fit Multiple Studies with Random-Effects dosresmeta (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.html This snippet illustrates fitting a random-effects meta-analysis for multiple studies using dosresmeta. It handles linear and potentially quadratic trends and requires specifying the formula, study type, unique study identifiers, standard errors, cases, and sample size. The summary provides details on fixed-effects coefficients and between-study variance components. ```r data("alcohol_cvd") lin <- dosresmeta(formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd) summary(lin) ``` -------------------------------- ### Implement One-Stage vs. Two-Stage Procedures in Dosresmeta Source: https://context7.com/alecri/dosresmeta/llms.txt Controls the estimation procedure using one-stage ('1stage') or two-stage ('2stage') approaches within the 'dosresmeta' function. The default procedure is '2stage'. This allows for comparing different estimation strategies for dose-response meta-analysis. ```R # Load data data("alcohol_cvd") # Two-stage procedure (default) two_stage <- dosresmeta( formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd, proc = "2stage" ) # One-stage procedure one_stage <- dosresmeta( formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd, proc = "1stage" ) # Compare results summary(two_stage) summary(one_stage) ``` -------------------------------- ### Compute BLUP Predictions with dosresmeta Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/blup.dosresmeta.html This R code demonstrates how to fit linear and quadratic dose-response meta-analytical models using the 'dosresmeta' function and then compute the best linear unbiased predictions (BLUP) for these models using the 'blup' method. It requires the 'alcohol_cvd' dataset and assumes the presence of the 'dosresmeta' package. ```R ## Load data and run the linear and quadratic models data("alcohol_cvd") lin <- dosresmeta(formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd) quadr <- dosresmeta(formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd) ## blup prediction for the previous models blup(lin) blup(quadr) ``` -------------------------------- ### Dosresmeta Control List Configuration Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.control.html This R code snippet shows how to configure the control parameters for the dosresmeta function. It specifically enables iteration reporting and sets the initial iteration count for IGLS. ```r control = list(showiter = TRUE, igls.inititer = 20) ``` -------------------------------- ### Fit Fixed-Effects Linear Model with Dosresmeta Source: https://context7.com/alecri/dosresmeta/llms.txt Estimates a fixed-effects linear dose-response model using generalized least squares. Requires loading the 'dosresmeta' package and relevant data. The function 'dosresmeta' is used with method = 'fixed'. ```R # Load colorectal cancer data data("alcohol_crc") # Fixed-effects linear model fixed_model <- dosresmeta( formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = peryears, data = alcohol_crc, method = "fixed" ) summary(fixed_model) # Extract coefficients and variance coef(fixed_model) vcov(fixed_model) logLik(fixed_model) AIC(fixed_model) BIC(fixed_model) ``` -------------------------------- ### Fixed-Effects Model Estimation using dosresmeta Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.fixed.html Demonstrates how to fit a fixed-effect dose-response model using the `dosresmeta` function from the `dosresmeta` package. It takes a formula, study identifiers, outcome data, and other relevant parameters to estimate the fixed-effects coefficients. ```r data("alcohol_crc") # Fixed-effect dose-response model assuming linearity dosresmeta(formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = peryears, data = alcohol_crc, method = "fixed") ``` -------------------------------- ### Fit Linear Dose-Response Model and Extract Log-Likelihood (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/logLik.dosresmeta.html This snippet demonstrates fitting a linear dose-response model using the 'dosresmeta' function and then extracting the log-likelihood of the fitted model. It requires the 'alcohol_crc' dataset and specifies the model formula and other necessary parameters. ```R data("alcohol_crc") # Dose-response model assuming linearity lin <- dosresmeta(formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = peryears, data = alcohol_crc, proc = "1stage") # Log-likelihood ll <- logLik(lin) ll attributes(ll) # AIC and BIC AIC(ll) BIC(ll) ``` -------------------------------- ### Control Optimization Parameters in Dosresmeta Source: https://context7.com/alecri/dosresmeta/llms.txt Fine-tunes the fitting process of dose-response meta-analysis models using the 'control' argument in the 'dosresmeta' function. Parameters like 'showiter', 'igls.inititer', 'maxiter', and 'reltol' can be adjusted to modify the optimization process. ```R # Load data data("alcohol_cvd") # Show iterations and modify optimization parameters controlled_model <- dosresmeta( formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd, proc = "1stage", control = list( showiter = TRUE, igls.inititer = 20, maxiter = 200, reltol = 1e-8 ) ) ``` -------------------------------- ### Fit Non-linear (Quadratic) Trend with dosresmeta Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.html This snippet demonstrates fitting a non-linear (quadratic) trend using the dosresmeta function. It models the log-risk ratio (logrr) as a function of dose and the square of the dose, incorporating study-specific parameters (type, id, se, cases, n). The summary provides detailed statistical outputs. ```R quadr <- dosresmeta(formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd) summary(quadr) ``` -------------------------------- ### Fit and Predict with dosresmeta Models (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/predict.dosresmeta.html This snippet demonstrates how to fit linear and quadratic dose-response models using the `dosresmeta` function and then generate predictions with confidence intervals from these models. It requires the `alcohol_cvd` dataset and utilizes the `predict` function for generating predictions on the relative risk (RR) scale. ```r data("alcohol_cvd") lin <- dosresmeta(formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd) quadr <- dosresmeta(formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd) # Predicted linear trend (on RR scale) predict(lin, delta = 12, expo = TRUE) # Predicted modeled data from quadratic model (on RR scale) predict(quadr, expo = TRUE) ``` -------------------------------- ### Extract Model Information using dosresmeta Source: https://context7.com/alecri/dosresmeta/llms.txt Fits a dosresmeta model and extracts key information such as coefficients, variance-covariance matrix, log-likelihood, and model dimensions. Dependencies include the dosresmeta package and its associated data. ```r data("alcohol_cvd") model <- dosresmeta( formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd ) beta <- coef(model) V <- vcov(model) ll <- logLik(model) attributes(ll) AIC(model) BIC(model) Psi <- model$Psi residuals(model) fitted(model) model$dim model$df ``` -------------------------------- ### Generate Fractional Polynomial Grids (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/fpgrid.html The fpgrid function computes combinations of coefficients 'p' for two-order fractional polynomials. It accepts a numeric vector of coefficients and returns a data frame containing the combinations. This is useful for modeling continuous covariates with fractional polynomials. ```r grd <- fpgrid() head(grd) ``` -------------------------------- ### Generate Graphical Results for Continuous Outcome Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.html This code generates a plot for a continuous outcome meta-analysis, visualizing the predicted trend and confidence intervals based on SMD. It creates a data frame for prediction, calculates fitted values using 'predict', and then plots the trend line with confidence bands and rug plots. ```R newdata <- data.frame(dose = seq(0, 30, 1)) with(predict(mod3, newdata, order = TRUE), { plot(dose, pred, type = "l", ylim = c(0, .6)) lines(dose, ci.lb, lty = 2) lines(dose, ci.ub, lty = 2) rug(dose, quiet = TRUE) }) ``` -------------------------------- ### Compute Goodness-of-Fit Statistics for dosresmeta Objects in R Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/gof.html This R code snippet demonstrates how to compute and display goodness-of-fit statistics for a linear dose-response meta-analysis model. It first loads data, then fits a 'dosresmeta' model, and finally applies the 'gof' function to evaluate its fit. ```R data("milk_ov") lin <- dosresmeta(formula = logrr ~ dose, type = type, id = id, se = se, cases = case, n = n, data = milk_ov) gof(lin) ``` -------------------------------- ### Compute Goodness-of-Fit for Meta-Regression dosresmeta Models in R Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/gof.html This R code snippet illustrates the computation of goodness-of-fit statistics for a meta-regression model fitted using 'dosresmeta'. It defines a model with a meta-regression term and then uses the 'gof' function to assess its fit, showing how to evaluate more complex models. ```R lin_reg <- dosresmeta(formula = logrr ~ dose, type = type, id = id, se = se, cases = case, n = n, data = milk_ov, mod = ~ type) gof(lin_reg) ``` -------------------------------- ### Perform Cochran Q Test for dosresmeta Models (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/qtest.dosresmeta.html The qtest.dosresmeta S3 method function performs a Cochran Q test of residual heterogeneity on fitted dose-response meta-analytical models. It is implemented only for a two-stage approach and returns NULL otherwise. It takes an object of class 'dosresmeta' as input. ```R # S3 method for dosresmeta qtest(object, ...) # S3 method for qtest.dosresmeta print(x, digits = 3, ...) ``` -------------------------------- ### Apply Fractional Polynomial Transformation - R Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/fracpol.html This R code demonstrates how to use the fracpol function to transform a continuous covariate. It takes a numeric vector 'x' and a vector 'p' of powers, along with optional scaling parameters, to generate a matrix of transformed values. This is useful for modeling non-linear relationships in statistical models. ```R fracpol(x, p = c(1, 1), shift, scale, scaling = TRUE) ``` -------------------------------- ### Compute Log-Likelihood (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/mlprof.fun.html These R functions compute the log-likelihood for random-effects dose-response meta-analysis models. They take model parameters and data structures as input and return the log-likelihood value. They are designed for internal use by fitting functions. ```R remlprof.fn(par, Xlist, Zlist, ylist, Slist, nalist, q, nall, ctrl) remlprof.gr(par, Xlist, ylist, Slist, nalist, p, nall, ctrl) mlprof.fn(par, Xlist, Zlist, ylist, Slist, nalist, q, nall, ctrl) mlprof.gr(par, Xlist, ylist, Slist, nalist, p, nall, ctrl) ``` -------------------------------- ### Perform Cochran Q Test for Heterogeneity with Dosresmeta Source: https://context7.com/alecri/dosresmeta/llms.txt Tests for residual heterogeneity in two-stage dose-response meta-analysis models fitted with 'dosresmeta'. The 'qtest' function is used on the fitted model object, and its components (Q statistic, df, p-value) can be accessed. ```R # Load data and fit model data("alcohol_cvd") model <- dosresmeta( formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd, proc = "2stage" ) # Perform Q-test qtest_result <- qtest(model) print(qtest_result) # Access components qtest_result$Q # Q statistic qtest_result$df # degrees of freedom qtest_result$pvalue # p-value # Included in summary summary(model) ``` -------------------------------- ### Generate Graphical Results for Quadratic Trend Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.html This code generates a plot visualizing the predicted non-linear (quadratic) trend and its confidence intervals. It uses the 'predict' function to obtain fitted values and then plots the trend line with confidence bands and rug plots for the observed doses. ```R with(predict(quadr, expo = TRUE, order = TRUE), { plot(dose, pred, log = "y", type = "l", xlim = c(0, 45), ylim = c(.4, 2)) lines(dose, ci.lb, lty = 2) lines(dose, ci.ub, lty = 2) rug(dose, quiet = TRUE) }) ``` -------------------------------- ### dosresmeta Function Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.html Estimates a dose-response curve from summarized dose-response data, accounting for correlation and heterogeneity. ```APIDOC ## DOSRESMETA Function ### Description Estimates a dose-response curve from either single or multiple summarized dose-response data, taking into account the correlation among observations and heterogeneity across studies. The `dosresmeta.fit` function is a wrapper for actual fitting functions based on different estimation methods, usually called internally. ### Method `dosresmeta` ### Endpoint N/A (R Function) ### Arguments - **formula** (formula) - Symbolic description of the dose-response functional relation. Terms can be provided in the `data`. - **id** (vector) - Specifies the study ID. Optional for single-study analysis. - **v** (vector) - Specifies the variances of the outcome. Alternatively, `se`, `lb`, and `ub` can be provided. - **type** (vector or string) - Optional. Specifies study-specific design for log relative risks (`cc`, `ir`, `ci`). - **cases** (vector) - Number of cases for each exposure level. Required for reconstructing (co)variance matrices for log relative risks. - **n** (vector) - Total number of subjects for each exposure level. For incidence-rate data, specifies person-time. - **sd** (vector) - Standard deviation. Required for reconstructing (co)variance matrices for differences and standardized mean differences. - **data** (data frame) - Data frame containing the variables used in the arguments. - **mod** (formula) - Symbolic description of the meta-regression model (default: `~ 1`). - **intercept** (logical) - Specifies if an intercept term should be included (default: `FALSE`). - **center** (logical) - Specifies if the design matrix should be centered at the referent ones (default: `TRUE`). - **se** (vector) - Optional. Standard error of reported log relative risks; needed if `v` is not provided. - **lb** (vector) - Optional. Lower bound of the confidence interval for reported relative risks; needed if `v` and `se` are not provided. - **ub** (vector) - Optional. Upper bound of the confidence interval for reported relative risks; needed if `v` and `se` are not provided. - **covariance** (string) - Method to approximate the (co)variance matrix. Options: 'gl', 'h', 'md', 'smd', 'user' (default: 'gl'). - **method** (string) - Estimation method: 'fixed', 'ml', 'reml', 'mm' (default: 'reml'). - **proc** (string) - Procedure type: '2stage' or '1stage' (default: '2stage'). - **Slist** (list) - List of approximated or given (co)variance matrices. - **method.smd** (string) - Method for standardized mean differences ('cohens', 'hedges', 'glass'). Required if `covariance` is 'smd'. - **control** (list) - Parameters for controlling the fitting process, passed to `dosresmeta.control`. ### Value Returns an object of class 'dosresmeta' containing the estimation results. ``` -------------------------------- ### Print Wald Test Results (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/waldtest.html Prints the results of a Wald test, typically generated by the `waldtest` function. This method formats the output to display the test statistic (e.g., Chi-squared), degrees of freedom, and the associated p-value. It allows control over the number of decimal places shown. ```r # S3 method for waldtest print(x, digits = 2, ...) ``` -------------------------------- ### Fit Dose-Response Meta-Analysis Models in R Source: https://context7.com/alecri/dosresmeta/llms.txt Fits dose-response meta-analytical models from single or multiple studies using linear or non-linear formulas. It handles various data types and estimation methods, with options for prediction and visualization. ```r # Load example data for cardiovascular disease and alcohol consumption data("alcohol_cvd") # Linear dose-response model with random effects (default REML) linear_model <- dosresmeta( formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd ) summary(linear_model) # Non-linear (quadratic) dose-response model quadratic_model <- dosresmeta( formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd, method = "reml" ) # Predict dose-response relationship with confidence intervals predictions <- predict(quadratic_model, expo = TRUE, order = TRUE) # Visualize the dose-response curve with(predictions, { plot(dose, pred, log = "y", type = "l", xlim = c(0, 45), ylim = c(.4, 2), xlab = "Alcohol (g/day)", ylab = "Relative Risk") lines(dose, ci.lb, lty = 2) lines(dose, ci.ub, lty = 2) rug(dose, quiet = TRUE) }) # Predict linear trend per 12 g/day increase predict(linear_model, delta = 12, expo = TRUE) ``` -------------------------------- ### Estimate Random-Effects Models (ML/REML) with Dosresmeta Source: https://context7.com/alecri/dosresmeta/llms.txt Estimates random-effects dose-response models using maximum likelihood (ML) or restricted maximum likelihood (REML). The 'dosresmeta' function is used with method = 'ml' or method = 'reml'. REML is the default and recommended method. Model comparison using AIC and BIC is demonstrated. ```R # Load data data("alcohol_cvd") # ML estimator ml_model <- dosresmeta( formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd, method = "ml" ) summary(ml_model) # REML estimator (default and recommended) reml_model <- dosresmeta( formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd, method = "reml" ) summary(reml_model) # Compare models using likelihood-based criteria AIC(ml_model) AIC(reml_model) BIC(ml_model) BIC(reml_model) ``` -------------------------------- ### Extract Coefficients from dosresmeta Model Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/coef.dosresmeta.html Extracts the fixed-effects coefficients from a fitted `dosresmeta` object. The output can be a vector or a matrix, depending on the 'format' argument. This function is essential for interpreting the model's estimated effect sizes. ```r # Load data and run the model data("alcohol_cvd") model <- dosresmeta(formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd) # Fixed-effect coefficients coef(model) ``` -------------------------------- ### Fit Dosresmeta Model and Plot Smoothed Relation (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/predict.dosresmeta.html Loads 'ari' data, fits a dose-response model using 'dosresmeta', and then plots the smoothed dose-response relation with confidence intervals. The model uses a quadratic term for dose and assumes 'smd' covariance. Predictions are made for a sequence of dose values using 'predict' and visualized with 'plot', 'lines', and 'rug'. ```r data("ari") mod <- dosresmeta(y ~ dose + I(dose^2), id = id, sd = sd, n = n, data = ari, covariance = "smd") newdata <- data.frame(dose = seq(0, 30, 1)) with(predict(mod, newdata), { plot(dose, pred, type = "l", ylim = c(0, .6)) lines(dose, ci.lb, lty = 2) lines(dose, ci.ub, lty = 2) rug(dose, quiet = TRUE) }) ``` -------------------------------- ### Predict Linear Trend with dosresmeta Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.html This function predicts the linear trend from a dosresmeta model. It takes a fitted model object and optionally parameters for delta and exponentiation. The output includes delta values, predicted values, and confidence interval bounds. ```R predict(lin, delta = 1, expo = TRUE) ``` -------------------------------- ### Plot Predicted Dose-Response Relation (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/predict.dosresmeta.html Plots the predicted dose-response relationship and confidence intervals. This function uses the 'with' and 'predict' functions to generate the plot, and 'lines' and 'rug' for adding confidence intervals and data points respectively. It assumes 'quadr', 'dose', 'pred', 'ci.lb', and 'ci.ub' are defined in the environment. ```r with(predict(quadr, order = TRUE, expo = TRUE), { plot(dose, pred, log = "y", type = "l", xlim = c(0, 45), ylim = c(.4, 2)) lines(dose, ci.lb, lty = 2) lines(dose, ci.ub, lty = 2) rug(dose, quiet = TRUE) }) ``` -------------------------------- ### R: ML and REML Estimation for Dose-Response Meta-Analysis Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.ml.html Implements Maximum Likelihood (ML) and Restricted Maximum Likelihood (REML) estimators for random-effects dose-response meta-analysis. These functions are typically used internally. They require study-specific design matrices (Xlist, Zlist), outcome vectors (ylist), covariance matrices (Slist), and missing outcome indicators (nalist). They return an intermediate list object for further processing. ```R dosresmeta.ml(Xlist, Zlist, ylist, Slist, nalist, q, nall, control, ...) dosresmeta.reml(Xlist, Zlist, ylist, Slist, nalist, q, nall, control, ...) ``` ```R lin.ml <- dosresmeta(formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd, , method = "ml") lin.reml <- dosresmeta(formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd, , method = "reml") ``` -------------------------------- ### Extract (Co)Variance Matrix from dosresmeta Model Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/coef.dosresmeta.html Extracts the (co)variance matrix of the estimated fixed-effects coefficients from a fitted `dosresmeta` object. This matrix is crucial for calculating standard errors of contrasts and confidence intervals for the estimated coefficients. ```r # Load data and run the model data("alcohol_cvd") model <- dosresmeta(formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd) # Fixed-effect (co)variance matrix vcov(model) ``` -------------------------------- ### Predict Dose-Response Trends with dosresmeta (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/dosresmeta.html This snippet shows how to predict dose-response trends from a fitted dosresmeta model. The predict function can be used with the fitted model object and parameters like 'delta' (dose level) and 'expo' (exponentiate results) to obtain predicted values and confidence intervals. ```r predict(mod1, delta = 1, expo = TRUE) ``` -------------------------------- ### Calculate Effective Counts (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/grl.html This function reconstructs pseudo-numbers of cases and non-cases consistent with input data. It requires log relative risks (y), their variances (v), number of cases, and total subjects (n), along with study type. The output is a matrix of approximated effective cases (A) and total effective subjects (N). ```r grl(y, v, cases, n, type, data, tol = 1e-05) ``` ```r # Example: Obtaining pseudo-counts for the first study (id = 1) library(dosresmeta) data("alcohol_cvd") grl(y = logrr, v = I(se^2), cases = cases, n = n, type = type, data = subset(alcohol_cvd, id == 1)) ``` ```r # Example: Obtaining pseudo-counts for all studies library(dosresmeta) data("alcohol_cvd") by(alcohol_cvd, alcohol_cvd$id, function(x) grl(y = logrr, v = I(se^2), cases = cases, n = n, type = type, data = x)) ``` ```r # Example: Restructuring results for all studies in a matrix library(dosresmeta) data("alcohol_cvd") do.call("rbind", by(alcohol_cvd, alcohol_cvd$id, function(x) grl(y = logrr, v = I(se^2), cases = cases, n = n, type = type, data = x))) ``` -------------------------------- ### Restructure Results into List of Matrices in R Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/covar.logrr.html This code restructures previous meta-analysis results into a list of matrices. It uses `do.call` to combine results from `covar.logrr` applied to subsets of the `alcohol_cvd` data, grouped by `alcohol_cvd$id`. Dependencies include base R functions like `list`, `by`, `covar.logrr`, and `I`. ```R do.call("list", by(alcohol_cvd, alcohol_cvd$id, function(x) covar.logrr(y = logrr, v = I(se^2), cases = cases, n = n, type = type, data = x))) ``` -------------------------------- ### Predict New Values from Quadratic Model (R) Source: https://github.com/alecri/dosresmeta/blob/master/docs/reference/predict.dosresmeta.html Generates predictions for new dose values from a quadratic dose-response model. It creates a new data frame with dose values and then uses the predict function to calculate predicted response, lower confidence bound (ci.lb), and upper confidence bound (ci.ub). The 'expo = TRUE' argument indicates that the predictions should be on the response ratio scale. ```r newdata <- data.frame(dose = seq(0, 50, 5)) predict(quadr, newdata, expo = TRUE) ``` -------------------------------- ### Reconstruct Effective Counts using Greenland-Longnecker Method in R Source: https://context7.com/alecri/dosresmeta/llms.txt Reconstructs effective counts using the Greenland-Longnecker algorithm, which is another method for estimating counts in meta-analysis when dealing with summarized data, particularly for binary outcomes. ```r # Load data data("alcohol_cvd") # Obtain pseudo-counts for first study grl_counts <- grl( y = logrr, v = I(se^2), cases = cases, n = n, type = type, data = subset(alcohol_cvd, id == 1) ) # Pseudo-counts for all studies all_grl <- by(alcohol_cvd, alcohol_cvd$id, function(x) { grl( y = logrr, v = I(se^2), cases = cases, n = n, type = type, data = x ) }) # Restructure as matrix grl_matrix <- do.call("rbind", all_grl) ``` -------------------------------- ### Predict Dose-Response with Confidence Intervals using Dosresmeta Source: https://context7.com/alecri/dosresmeta/llms.txt Predicts dose-response values and their confidence intervals for new or existing exposure levels using the 'predict' function with a fitted 'dosresmeta' model. The 'expo = TRUE' argument transforms predictions to the exponential scale (e.g., for relative risks). ```R # Load data and fit model data("alcohol_cvd") model <- dosresmeta( formula = logrr ~ dose + I(dose^2), type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd ) # Predict at modeled values (exponential scale for RR) predict(model, expo = TRUE) # Predict linear trend for specific increment linear_model <- dosresmeta( formula = logrr ~ dose, type = type, id = id, se = se, cases = cases, n = n, data = alcohol_cvd ) predict(linear_model, delta = 12, expo = TRUE) # Predict at new exposure values newdata <- data.frame(dose = seq(0, 50, 5)) new_predictions <- predict(model, newdata, expo = TRUE, ci.level = 0.95) # Include standard errors predictions_se <- predict(model, newdata, expo = TRUE, se.incl = TRUE) ```