-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
113 lines (84 loc) · 4.01 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# Modana
<!-- badges: start -->
[![DOI](https://pubmed.ncbi.nlm.nih.gov/36721908/status.svg)](https://doi.org/ 10.1177/09622802231151206)
[![R-CMD-check](https://github.com/Quamena/Modana/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Quamena/Modana/actions/workflows/R-CMD-check.yaml)
[![Project Status: Active](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![Travis build status](https://travis-ci.com/Quamena/Modana.svg?branch=master)](https://travis-ci.com/Quamena/Modana)
[![R build status](https://github.com/Quamena/Modana/workflows/R-CMD-check/badge.svg)](https://github.com/Quamena/Modana/actions)
[![Codecov test coverage](https://codecov.io/gh/Quamena/Modana/branch/master/graph/badge.svg)](https://codecov.io/gh/Quamena/Modana)
<!-- badges: end -->
The goal of the `Modana` package is to implement a refinement of moderation analysis with binary outcomes, as proposed by [Anto and Su (2023)](https://doi.org/10.1177/09622802231151206). The function fits three models of interest: a direct model, an inverse model, and a generalized estimating equation (GEE) model. The direct and inverse models are fitted using the `glm` function to verify the symmetry property of odds ratio/relative risk in moderation analysis for the main treatment effect as well as the moderating effects. The GEE model is fitted using the `geeglm` function and is used to estimate the treatment effect accounting for within-cluster correlation. The `Modana` package has three different built functions.
## Installation
You can install the development version of Modana like so:
``` r
devtools::install_github("Quamena/Modana")
```
## Example
This is a basic example which shows you how to solve a common problem:
```{r example}
library(Modana)
## basic example code
```
You can simulate some data to run moderation analysis
```{r data}
set.seed(1099)
b0 <- c(1, 1.2, 1, 1.5, -2, -.5, 1.2, 1.5)
a0 <- c(-1, 1.5, -1, 1.5)
#a0 <- c(-2, 2, 2, 0, 1)
b0 <- c(-1.5, 1.5, 1.5, -2, 2, -.5, -1, 1.5)
datt <- sim_data(n = 100, b0, a0 = NULL, binary.Xs = FALSE,
sigma = 1, uniform = FALSE, c0 = 1,
link.function = "logistic", rho = 0.2,
observational = FALSE, trt.p = 0.5,
interaction = 1:2, details = FALSE)
head(datt)
```
The `refinedmod()` function implements refined moderation analysis to estimate both main treatment effect and moderating effects associated with two logistic regression models with binary outcomes/treatment via generalized estimating equations (GEE).
The function first performs a role swap algorithm on the original data to obtain a clustered data of size `2` (i.e., swapping the roles of the response variable and treatment variable columns in the original data data and then stacking the resultant data on top of the original data).
```{r analysis}
getres <- refinedmod(formula = y ~ trt + x1 + x2 + x3 + x4,
detail = TRUE, y = "y",
trt = "trt", data = datt,
effmod = c("x1", "x2"),
corstr = "independence")
#names(getres)
summary(getres, 4)
```
You can call each elements of listed models
Mostly importantly, we can print the results of the refined estimation.
```{r}
print(getres, model = 2)
```
Example usage on a real-world data
```{r}
data(Warts, package = "Modana")
dat <- Warts
#data wrangling
dat$type <- ifelse(dat$type == 3, 1, 0)
```
```{r}
res <- refinedmod(formula = response ~ cryo + age + time + type,
detail = FALSE, y = "response",
trt = "cryo", data = dat,
effmod = c("age", "type"),
corstr = "independence")
summary(res, 4)
```
```{r}
plot(res)
```
```{r}
confint(res, model = 3)
```