The function calculates the effects of an exposure on a response,
possibly stratified by a stratifying variable, and/or controlled for one
or more confounding variables.
Usage
effx( response, type = "metric",
fup = NULL,
exposure,
strata = NULL,
control = NULL,
weights = NULL,
eff = NULL,
alpha = 0.05,
base = 1,
digits = 3,
data = NULL )
Arguments
response
The response variable - must be numeric or
logical. If logical, TRUE is considered the outcome.
type
The type of responsetype - must be one of "metric",
"binary", "failure", or "count"
fup
The fup variable contains the follow-up time for a
failure response
. This must be numeric.
exposure
The exposure variable can be numeric or a factor
strata
The strata stratifying variable - must be a factor
control
The control variable(s) (confounders) - these are
passed as a list if there are more than one.
weights
Frequency weights for binary response only
eff
How should effects be measured. If response is
binomial, the default is "OR" (odds-ratio) with "RR" (relative risk)
as an option. If response is failure, the default is "RR"
(rate-ratio) with "RD" (rate difference) as an option.
base
Baseline for the effects of a categorical exposure, either a
number or a name of the level. Defaults to 1
digits
Number of significant digits for the effects, default 3
alpha
1 - confidence level
data
data refers to the data used to evaluate the function
Details
The function is a wrapper for glm. Effects are calculated as
differences in means for a metric response, odds ratios/relatiev risks
for a binary response, and rate ratios/rate differences for a failure
or count response.
The k-1 effects for a categorical exposure with k levels are relative
to a baseline which, by default, is the first level. The effect of a
metric (quantitative) exposure is calculated per unit of exposure.
The exposure variable can be numeric or a factor, but if it is an
ordered factor the order will be ignored.
Value
comp1
Effects of exposure
comp2
Tests of significance
Author(s)
Michael Hills
References
www.mhills.pwp.blueyonder.co.uk
Examples
library(Epi)
data(births)
births$hyp <- factor(births$hyp,labels=c("normal","hyper"))
births$sex <- factor(births$sex,labels=c("M","F"))
# bweight is the birth weight of the baby in gms, and is a metric
# response (the default)
# effect of hypertension on birth weight
effx(bweight,exposure=hyp,data=births)
# effect of hypertension on birth weight stratified by sex
effx(bweight,exposure=hyp,strata=sex,data=births)
# effect of hypertension on birth weight controlled for sex
effx(bweight,exposure=hyp,control=sex,data=births)
# effect of gestation time on birth weight
effx(bweight,exposure=gestwks,data=births)
# effect of gestation time on birth weight stratified by sex
effx(bweight,exposure=gestwks,strata=sex,data=births)
# effect of gestation time on birth weight controlled for sex
effx(bweight,exposure=gestwks,control=sex,data=births)
# lowbw is a binary response coded 1 for low birth weight and 0 otherwise
# effect of hypertension on low birth weight
effx(lowbw,type="binary",exposure=hyp,data=births)
effx(lowbw,type="binary",exposure=hyp,eff="RR",data=births)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Epi)
Attaching package: 'Epi'
The following object is masked from 'package:base':
merge.data.frame
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Epi/effx.Rd_%03d_medium.png", width=480, height=480)
> ### Name: effx
> ### Title: Function to calculate effects
> ### Aliases: effx
> ### Keywords: models regression
>
> ### ** Examples
>
> library(Epi)
> data(births)
> births$hyp <- factor(births$hyp,labels=c("normal","hyper"))
> births$sex <- factor(births$sex,labels=c("M","F"))
>
> # bweight is the birth weight of the baby in gms, and is a metric
> # response (the default)
>
> # effect of hypertension on birth weight
> effx(bweight,exposure=hyp,data=births)
---------------------------------------------------------------------------
response : bweight
type : metric
exposure : hyp
hyp is a factor with levels: normal / hyper
baseline is normal
effects are measured as differences in means
---------------------------------------------------------------------------
effect of hyp on bweight
number of observations 500
Effect 2.5% 97.5%
-431 -585 -276
Test for no effects of exposure on 1 df: p-value= 4.9e-08
> # effect of hypertension on birth weight stratified by sex
> effx(bweight,exposure=hyp,strata=sex,data=births)
---------------------------------------------------------------------------
response : bweight
type : metric
exposure : hyp
stratified by : sex
hyp is a factor with levels: normal / hyper
baseline is normal
sex is a factor with levels: M/F
effects are measured as differences in means
---------------------------------------------------------------------------
effect of hyp on bweight
stratified by sex
number of observations 500
Effect 2.5% 97.5%
strata M level hyper vs normal -496 -696 -297
strata F level hyper vs normal -380 -617 -142
Test for effect modification on 1 df: p-value= 0.462
> # effect of hypertension on birth weight controlled for sex
> effx(bweight,exposure=hyp,control=sex,data=births)
---------------------------------------------------------------------------
response : bweight
type : metric
exposure : hyp
control vars : sex
hyp is a factor with levels: normal / hyper
baseline is normal
effects are measured as differences in means
---------------------------------------------------------------------------
effect of hyp on bweight
controlled for sex
number of observations 500
Effect 2.5% 97.5%
-448 -601 -295
Test for no effects of exposure on 1 df: p-value= 9.07e-09
> # effect of gestation time on birth weight
> effx(bweight,exposure=gestwks,data=births)
---------------------------------------------------------------------------
response : bweight
type : metric
exposure : gestwks
gestwks is numeric
effects are measured as differences in means
---------------------------------------------------------------------------
effect of an increase of 1 unit in gestwks on bweight
number of observations 490
Effect 2.5% 97.5%
197 180 214
Test for no effects of exposure on 1 df: p-value= <2e-16
> # effect of gestation time on birth weight stratified by sex
> effx(bweight,exposure=gestwks,strata=sex,data=births)
---------------------------------------------------------------------------
response : bweight
type : metric
exposure : gestwks
stratified by : sex
gestwks is numeric
sex is a factor with levels: M/F
effects are measured as differences in means
---------------------------------------------------------------------------
effect of an increase of 1 unit in gestwks on bweight
stratified by sex
number of observations 490
Effect 2.5% 97.5%
strata M 203 177 229
strata F 191 169 213
Test for effect modification on 1 df: p-value= 0.487
> # effect of gestation time on birth weight controlled for sex
> effx(bweight,exposure=gestwks,control=sex,data=births)
---------------------------------------------------------------------------
response : bweight
type : metric
exposure : gestwks
control vars : sex
gestwks is numeric
effects are measured as differences in means
---------------------------------------------------------------------------
effect of an increase of 1 unit in gestwks on bweight
controlled for sex
number of observations 490
Effect 2.5% 97.5%
196 179 213
Test for no effects of exposure on 1 df: p-value= <2e-16
>
> # lowbw is a binary response coded 1 for low birth weight and 0 otherwise
> # effect of hypertension on low birth weight
> effx(lowbw,type="binary",exposure=hyp,data=births)
---------------------------------------------------------------------------
response : lowbw
type : binary
exposure : hyp
hyp is a factor with levels: normal / hyper
baseline is normal
effects are measured as odds ratios
---------------------------------------------------------------------------
effect of hyp on lowbw
number of observations 500
Effect 2.5% 97.5%
3.73 2.03 6.87
Test for no effects of exposure on 1 df: p-value= 6.06e-05
> effx(lowbw,type="binary",exposure=hyp,eff="RR",data=births)
---------------------------------------------------------------------------
response : lowbw
type : binary
exposure : hyp
hyp is a factor with levels: normal / hyper
baseline is normal
effects are measured as relative risk
---------------------------------------------------------------------------
effect of hyp on lowbw
number of observations 500
Effect 2.5% 97.5%
2.97 1.85 4.78
Test for no effects of exposure on 1 df: p-value= 6.06e-05
>
>
>
>
>
> dev.off()
null device
1
>