rm(list=ls())
### install package
# install.packages('C:/Users/659014/Downloads/causalMediation_1.0.tar.gz', repos=NULL, type='source')
### load package
# library(causalMediation, lib.loc='C:/Users/659014/Documents/R/win-library/3.1')
library(causalMediation)
### first example
df <- data.frame('smoking' = c(0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0),
'lbw' = c(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0),
'death' = c(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
'drinking' = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0),
'agebelow20' = c(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
)
result <- causalMediation::causalMediation(nbootstraps = 1000, interaction = TRUE, debug = TRUE, yreg = "logistic", mreg = "logistic",
casecontrol = TRUE, baseline = 0)
print(result)
subset(df, death == 0)
### second example
df <- read.table(file='~/Downloads/Linda.csv', header=TRUE, sep = ';')
head(df)
result <- causalMediation::causalMediation(data = df,
outcome = 'satis',
treatment = 'therapy',
mediator = 'attrib',
covariates = c(),
nbootstraps = 0,
interaction = FALSE)
print(result)
### third example
df <- read.table(file='~/Downloads/Linda-duplicated.csv', header=TRUE, sep = ';')
result <- causalMediation::causalMediation(data = df,
outcome = 'satis',
treatment = 'therapy',
mediator = 'attrib',
covariates = c(),
nbootstraps = 1000,
interaction = FALSE)
print(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.