Hi! I am Mike Marin and in this video we'll discuss a package for calculating
"relative risk", "odds ratio", and "attributable risk"
or "risk difference" using R statistical software. the "relative risk",
"odds ratio" and "attributable risk" in statistics are all measures
of the direction and the strength of the association between two
categorical variables. we'll be working with the lung capacity data
that was introduced earlier in the series of videos. I've already gone ahead
and imported the data into R and attached it. we'll explore the
relationship between Gender and Smoking;
we'll start by producing a 2-way table and saving it in the object TAB
we can use the "table" command, and here we like a 2-way table
for the variables Gender and Smoke. to visually examine the relationship
between these two variables
we can produce a bar plot; here we like a bar plot of the table
we'll set the "beside" argument equal to TRUE
to have these bar plots placed side by side and I also set the "legend" argument
equal to TRUE
to have a default legend produced. you can see my earlier video in series two
for more on producing bar plots. it appears that the non-smoking group
has more males than females and the smoking group has more females than
males,
suggesting that there may be a relationship between these two variables.
in the previous video we learned how to conduct the chi-square test of
independence
although we noted that this test gives no indication
of the strength or direction of any association; the "relative risk"
"odds ratio" and "attributable risk" are all measures of the direction
and the strength of the association between two categorical variables.
we will be using the epiR package to calculate these summaries
although it should be noted that there are many other options of packages that
one may choose from. I've already installed this package
so I'm gonna go ahead and load the library for it. for help on installing packages
you can see my earlier video in series 1 on installing packages in R programming language.
to access the Help menu for this package you can type "help"
and then: package="epiR"
in quotations. we will be using
the "2by2" command to produce these summeries. here you can see the
documentation for the help.
now recall the 2by2 table we had produced
we can calculate "relative risks", "odds ratios"
and "attributable risks" using the "epi.2by2" command.
here we'd like to produce this for our table. we can set the method argument
equal to "cohort.count" if our data has come from a cohort study
and we can set this to "case.control" for a case-control study
it's worth noting that if we set the method to case-control
the relative risk will not be returned. we can also set the
"conf.level" argument for the desired level of confidence we would like
95 percent being the default. we can see
that we are returned the "relative risk", here called the "incidence risk ratio"
along with the 95 percent confidence interval, the "odds ratio"
along with the confidence interval and the "attributable risk"
along with the confluence interval. We are also returned other adjusted measures
of attributable risk. taking a look at the odds ratio of 0.71
this can be interpreted as the "odds of a female
not smoking are 0.71 times the odds of a male
not smoking". if we take the inverse of this
we can have females as the reference group
or in the denominator. then we can interpret this
as "the odds of a male not smoking are 1.4 times the odds of a female
not smoking". it's worth noting that often
books or notes have formulas and interpretations
presented using a table using a, b, c, d
notation. we can see this in the picture here. the exposure
,in this example gender, would appear in rows with the first row
being yes or exposed and the second row
being no or unexposed. the outcome variable
is presented in columns, in this example smoking,
the first column being yes or diseased
and the second column being no or not-diseased. we can reorganize our table
to look like this so that our interpretations with match the standard
a, b, c, d interpretations. recall the table that we had produced earlier
if we would like to set up this table in the standard a, b, c, d format
we can do this in a few ways: first I'll create a new table call table 2 (TAB2)
here we will store the information in a matrix
using values of: 44, 314,
33 and 334.
we will let R know the number of rows is 2
and to insert this information by rows
so we'll set the "byrow" argument equal to TRUE
here we can now see the table set up in the standard a, b, c, d format.
the "matrix" command was introduced in one of my series 1 videos
so you can take a look at that for more information on how to create a matrix in R.
we could also create this table
using the square brackets and the "cbind" commands
we learned about these in earlier videos as well. I'll demonstrate
saving it in an object called table 3
and here we would like to bind together in a column-wise fashion
we'll take it from our original table the values stored in column 2
and then we'll bind to that the values from our table
stored in column 1. here we are just reversing
the order in column 1 and column 2.
if you would like to add names to the columns we can use the
"colnames" command. Here we would like to create column names for this
object table 3 and we will make the names
"yes" and "no".
now we can take a look at table 3 again
and now we can see the columns have names as well.
Now let's go ahead and calculate these summaries again using the epi.2by2
command and we will do this for table 3. again we will set our method
to "cohort.count"
and I will leave the confidence level empty using the default 95%
here we see the odds ratio of 1.42 which would be interpreted as
"the odds of a female smoking are 1.42
times the odds of a male smoking". it's worth noting here
that the confidence interval contains the value 1 indicating that the odds
ratio is not significant
in the next video in this series we will start to talk about correlation
and then linear regression.
thanks for watching this video and make sure to subscribe to MarinStatsLectures for more videos on R Programming and Statistics