Overview
\[P(\mathsf{Target\ outcome}) = \frac{\mathsf{Number\ of\ target\ outcomes}}{\mathsf{Number\ of\ all\ outcomes}}\]
\[P = \frac{72}{200} = .36\]
pain.df <- data.frame(Ethnicity = c("Latin", "Non-Latin"),
Diagnosed = c(72, 223),
Not_Diagnosed = c(128, 241)
)
<-
assigns a value, function, etc. to an “object”
data.frame
pain.df
c
“concatenates” (combines) a series of values, etc.
into a single list (“array” or “vector”)library(knitr)
library(kableExtra)
table.of.pain <- pain.df %>%
kable(col.names = c("Ethnicity", "Diagnosed", "Not Diagnosed"),
align = c("l", "c", "c")) %>%
kable_styling(font_size = 42) %>% kable_material("hover") %>%
add_header_above(c(" " = 1, "Pain Disorder Diagnosis" = 2))
R
are available in add-on packages;
library
invokes a given package
knitr
prepares
output for reportskableExtras
pimps out tables (kable
s)
made by knitr
%>%
is a “pipe” command, which essentially nests
commands inside other commands
pain.df
data frametable.of.pain
object
Pain Disorder Diagnosis
|
||
---|---|---|
Ethnicity | Diagnosed | Not Diagnosed |
Latin | 72 | 128 |
Non-Latin | 223 | 241 |
\[P(\mathsf{Latino\ Patient\ Has\ a\ Pain\ Disorder}) = \frac{\mathsf{Target\ Event}}{\mathsf{All\ Events}}\]
\[= \frac{\mathsf{Latinos\ \overline{c}\ Pain\ Disorders}}{(\mathsf{Latinos\ \overline{c}\ Pain\ Disorders})+(\mathsf{Latinos\ \overline{s}\ Pain\ Disorders})}\]
\[= \frac{72}{72+128} = \frac{72}{200} = .36\]
[]
) index parts (“elements”) of an
object## [1] "Latin"
## [1] 72
## Ethnicity Diagnosed Not_Diagnosed
## 1 Latin 72 128
## Ethnicity Diagnosed Not_Diagnosed
## 1 Latin 72 128
## 2 Non-Latin 223 241
## [1] 200
p.latin.patient.diagnosed.with.pain.disorder <- pain.df[1, 2] / (pain.df[1, 2] + pain.df[1, 3])
p.latin.patient.diagnosed.with.pain.disorder
## [1] 0.36
$
accesses a column (or other variable-like element) of
an object…## [1] "Latin" "Non-Latin"
## [1] 72 223
## [1] 0.3600000 0.4806034
pain.df$Risk_of_Pain_Diagnosis <- pain.df$Diagnosed /
(pain.df$Diagnosed + pain.df$Not_Diagnosed)
pain.df$Risk_of_Pain_Diagnosis
## [1] 0.3600000 0.4806034
## Ethnicity Diagnosed Not_Diagnosed Risk_of_Pain_Diagnosis
## 1 Latin 72 128 0.3600000
## 2 Non-Latin 223 241 0.4806034
\[\mathsf{Risk\ Ratio} = \frac{\mathsf{Risk\ Among\ Latino\ Patients}}{\mathsf{Risk\ Among\ Non\text{-}Latino\ Patients}}\]
\[= \frac{.36}{\sim.48} \approx .75 \]
## [1] 0.7490583
Probability of continued opioid use for ≤ 365 days for patients with
childbirth, surgery, trauma, or other pain diagnosis in the week before
their first opioid prescription or chronic pain diagnosis in the 6
months before their first opioid prescription.
Abbreviation: CNCP,
chronic non-cancer pain
Shah, Hayes, & Martin (2017)
\[P(\mathsf{Being\ Diagnosed\ \overline{c}\ Pain\ Disorder})= \frac{72}{72+128} = \frac{72}{200}\]
\[\mathsf{Odds\ of\ Being\ Diagnosed\ \overline{c}\ Pain\ Disorder} = \frac{72}{128} \approx .56\]
Event Happening | Odds Versus the Event Not Happening |
---|---|
Dying in a plane crash | 1 : 11,000,000 |
Dying in a shark attack | 1 : 7,000,000 |
Being killed by a meteorite | 1 : 250,000 |
Dying in a hurricane | 1 : 62,288 |
Dying in a motorcycle accident | 1 : 722 |
Dying by heart disease | 1 : 6 |
Being saved by CPR | 1 : 1.44 |
Being an adult with hearing issues | 1 : 6.14 |
Being an elderly adult with hearing issues | 1 : 1 |
Earn any degree within 6 years of enrolling in a 4-year for-profit college | 1 : 1.68 |
Earn any degree within 6 years of enrolling in a 4-year public college | 1 : 0.52 |
Having an application accepted by Harvard | 1 : 30.25 |
Identifying as LGBTQ+ | 1 : 16.86 |
Being audited by the IRS | 1 : 220 |
Giving birth on the actual due date | 1 : 249 |
Getting your car stolen | 1 : 332 |
Being matched as a bone marrow donor | 1 : 430 |
Loosing your home to fire | 1 : 3,000 |
Finding a four-leaf clover | 1 : 10,000 |
Being involved in a mass shooting | 1 : 11,125 |
Getting struck by lightning within an 80-year life | 1 : 15,300 |
Winning an Olympic medal | 1 : 622,999 |
From Stacker
Ethnicity | Diagnosed | Not Diagnosed |
---|---|---|
Latin | 72 | 128 |
Non-Latin | 223 | 241 |
Odds—not odds ratios—for each group:
Group | Present | Not Present) |
---|---|---|
Target | A | B |
Reference | C | D |
\[OR = \frac{(\textsf{Target & Present / Target & Not Present})}{(\textsf{Reference & Present / Reference & Not Present})}\]
\[OR = \frac{(\textsf{A / B)}}{\textsf{(C / D)}}\]
Ethnicity | Diagnosed | Not Diagnosed |
---|---|---|
Latin | 72 | 128 |
Non-Latin | 223 | 241 |
\[OR = \frac{(\textsf{Latin & Diagnosed / Latin & Not Diagnosed})}{(\textsf{Non-Latin & Diagnosed / Non-Latin & Not Diagnosed})}\]
\[OR = \frac{(72 / 128)}{(223 / 241)} \approx \frac{.56}{.92}\approx .61\]
\[OR = \frac{(223 / 241)}{(72 / 128)} = \frac{.92}{.56} \approx 1.6\]
Note that \(\frac{1}{.61} \approx 1.6\)
Yeah, like this:
Ethnicity | Diagnosed | Not Diagnosed |
---|---|---|
Latin | 72 | 128 |
Non-Latin | 223 | 241 |
pain.df.counts <- subset(pain.df, select = c("Diagnosed", "Not_Diagnosed"))
fisher.test(pain.df.counts)
##
## Fisher's Exact Test for Count Data
##
## data: pain.df.counts
## p-value = 0.00491
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
## 0.4250886 0.8665430
## sample estimates:
## odds ratio
## 0.6083658
p-value = 0.00491
0.425
–
0.866
) for the odds ratio (0.608
) doesn’t
overlap 1fisher.test
also creates an objectsummary()
command:## Length Class Mode
## p.value 1 -none- numeric
## conf.int 2 -none- numeric
## estimate 1 -none- numeric
## null.value 1 -none- numeric
## alternative 1 -none- character
## method 1 -none- character
## data.name 1 -none- character
str()
command:
str()
works to “look inside” most any object or
function in R
## List of 7
## $ p.value : num 0.00491
## $ conf.int : num [1:2] 0.425 0.867
## ..- attr(*, "conf.level")= num 0.95
## $ estimate : Named num 0.608
## ..- attr(*, "names")= chr "odds ratio"
## $ null.value : Named num 1
## ..- attr(*, "names")= chr "odds ratio"
## $ alternative: chr "two.sided"
## $ method : chr "Fisher's Exact Test for Count Data"
## $ data.name : chr "pain.df.counts"
## - attr(*, "class")= chr "htest"
$
can access any of those elements of the
fisher.test
object:## [1] 0.004910079
## [1] 0.4250886 0.8665430
## attr(,"conf.level")
## [1] 0.95
Formula for a normal distribution:
\[f(x, \mu, \sigma) = \frac{1}{\sigma\sqrt{2\pi}}e^{\frac{-(x - \mu)^2}{2\sigma^2}}\]
From StackExchange
Formula for χ² value:
\[\chi^2 = \sum{\frac{(\mathsf{Observed} - \mathsf{Expected})^2}{\mathsf{Expected}}}\]
Ethnicity | Diagnosed | Not Diagnosed | Total |
---|---|---|---|
Latin | 72 | 128 | 200 |
Value Type | Diagnosed | Not Diagnosed | Total |
---|---|---|---|
Observed | 72 | 128 | 200 |
Expected | 100 | 100 | 200 |
Value Type | Diagnosed | Not Diagnosed |
---|---|---|
Observed | 72 | 128 |
Expected | 100 | 100 |
Observed – Expected | -28 | 28 |
lower.tail = FALSE
gives the max value for a χ²
from the null distribution)## [1] 3.841459
Notes: “AA” = African Americans; p-values are from tests of χ²s
Zhang, A. Y., Koroukian, S., Owusu, C., Moore, S. E., & Gairola, R. (2022). Socioeconomic correlates of health outcomes and mental health disparity in a sample of cancer patients during the COVID-19 pandemic. Journal of Clinical Nursing. https://doi.org/10.1111/jocn.16266