Part 1

Exercise 1

Julie Long; September 8, 2024; EPID 7631 Lab 1

Exercise 2

getwd ()
## [1] "/Users/julielong/Desktop/Julie/_PhD/EPID 7631/Week 2/Lab 1"

Exercise 3

library(readxl)
frmgham2 <- read_excel("~/Desktop/Julie/_PhD/EPID 7631/Week 2/Lab 1/frmgham2.xls")
View(frmgham2)

Exercise 4

head(frmgham2)
## # A tibble: 6 × 39
##   RANDID   SEX TOTCHOL   AGE SYSBP DIABP CURSMOKE CIGPDAY   BMI DIABETES BPMEDS
##    <dbl> <dbl>   <dbl> <dbl> <dbl> <dbl>    <dbl>   <dbl> <dbl>    <dbl>  <dbl>
## 1   2448     1     195    39  106   70          0       0  27.0        0      0
## 2   2448     1     209    52  121   66          0       0  NA          0      0
## 3   6238     2     250    46  121   81          0       0  28.7        0      0
## 4   6238     2     260    52  105   69.5        0       0  29.4        0      0
## 5   6238     2     237    58  108   66          0       0  28.5        0      0
## 6   9428     1     245    48  128.  80          1      20  25.3        0      0
## # ℹ 28 more variables: HEARTRTE <dbl>, GLUCOSE <dbl>, educ <dbl>,
## #   PREVCHD <dbl>, PREVAP <dbl>, PREVMI <dbl>, PREVSTRK <dbl>, PREVHYP <dbl>,
## #   TIME <dbl>, PERIOD <dbl>, HDLC <dbl>, LDLC <dbl>, DEATH <dbl>,
## #   ANGINA <dbl>, HOSPMI <dbl>, MI_FCHD <dbl>, ANYCHD <dbl>, STROKE <dbl>,
## #   CVD <dbl>, HYPERTEN <dbl>, TIMEAP <dbl>, TIMEMI <dbl>, TIMEMIFC <dbl>,
## #   TIMECHD <dbl>, TIMESTRK <dbl>, TIMECVD <dbl>, TIMEDTH <dbl>, TIMEHYP <dbl>

Exercise 5

39 variables CURSMOKE is a categorical variable. PERIOD is a ordinal variable. HEARTRATE is a continuous variable.

str(frmgham2)
## tibble [11,627 × 39] (S3: tbl_df/tbl/data.frame)
##  $ RANDID  : num [1:11627] 2448 2448 6238 6238 6238 ...
##  $ SEX     : num [1:11627] 1 1 2 2 2 1 1 2 2 2 ...
##  $ TOTCHOL : num [1:11627] 195 209 250 260 237 245 283 225 232 285 ...
##  $ AGE     : num [1:11627] 39 52 46 52 58 48 54 61 67 46 ...
##  $ SYSBP   : num [1:11627] 106 121 121 105 108 ...
##  $ DIABP   : num [1:11627] 70 66 81 69.5 66 80 89 95 109 84 ...
##  $ CURSMOKE: num [1:11627] 0 0 0 0 0 1 1 1 1 1 ...
##  $ CIGPDAY : num [1:11627] 0 0 0 0 0 20 30 30 20 23 ...
##  $ BMI     : num [1:11627] 27 NA 28.7 29.4 28.5 ...
##  $ DIABETES: num [1:11627] 0 0 0 0 0 0 0 0 0 0 ...
##  $ BPMEDS  : num [1:11627] 0 0 0 0 0 0 0 0 0 0 ...
##  $ HEARTRTE: num [1:11627] 80 69 95 80 80 75 75 65 60 85 ...
##  $ GLUCOSE : num [1:11627] 77 92 76 86 71 70 87 103 89 85 ...
##  $ educ    : num [1:11627] 4 4 2 2 2 1 1 3 3 3 ...
##  $ PREVCHD : num [1:11627] 0 0 0 0 0 0 0 0 0 0 ...
##  $ PREVAP  : num [1:11627] 0 0 0 0 0 0 0 0 0 0 ...
##  $ PREVMI  : num [1:11627] 0 0 0 0 0 0 0 0 0 0 ...
##  $ PREVSTRK: num [1:11627] 0 0 0 0 0 0 0 0 0 0 ...
##  $ PREVHYP : num [1:11627] 0 0 0 0 0 0 0 1 1 0 ...
##  $ TIME    : num [1:11627] 0 4628 0 2156 4344 ...
##  $ PERIOD  : num [1:11627] 1 3 1 2 3 1 2 1 2 1 ...
##  $ HDLC    : num [1:11627] NA 31 NA NA 54 NA NA NA NA NA ...
##  $ LDLC    : num [1:11627] NA 178 NA NA 141 NA NA NA NA NA ...
##  $ DEATH   : num [1:11627] 0 0 0 0 0 0 0 1 1 0 ...
##  $ ANGINA  : num [1:11627] 0 0 0 0 0 0 0 0 0 0 ...
##  $ HOSPMI  : num [1:11627] 1 1 0 0 0 0 0 0 0 0 ...
##  $ MI_FCHD : num [1:11627] 1 1 0 0 0 0 0 0 0 0 ...
##  $ ANYCHD  : num [1:11627] 1 1 0 0 0 0 0 0 0 0 ...
##  $ STROKE  : num [1:11627] 0 0 0 0 0 0 0 1 1 0 ...
##  $ CVD     : num [1:11627] 1 1 0 0 0 0 0 1 1 0 ...
##  $ HYPERTEN: num [1:11627] 0 0 0 0 0 0 0 1 1 1 ...
##  $ TIMEAP  : num [1:11627] 8766 8766 8766 8766 8766 ...
##  $ TIMEMI  : num [1:11627] 6438 6438 8766 8766 8766 ...
##  $ TIMEMIFC: num [1:11627] 6438 6438 8766 8766 8766 ...
##  $ TIMECHD : num [1:11627] 6438 6438 8766 8766 8766 ...
##  $ TIMESTRK: num [1:11627] 8766 8766 8766 8766 8766 ...
##  $ TIMECVD : num [1:11627] 6438 6438 8766 8766 8766 ...
##  $ TIMEDTH : num [1:11627] 8766 8766 8766 8766 8766 ...
##  $ TIMEHYP : num [1:11627] 8766 8766 8766 8766 8766 ...
class (frmgham2$CURSMOKE)
## [1] "numeric"
class (frmgham2$PERIOD)
## [1] "numeric"
class (frmgham2$HEARTRTE)
## [1] "numeric"

Exercise 6

There are 11627 observations in the dataset. There are 4434 unique participants.

nrow(frmgham2)
## [1] 11627
length(unique(frmgham2$RANDID))
## [1] 4434

Exercise 7

You would take the natural log of variable to normalize skewed data and improve the variance. In this exercise the natural log transforms glucose results to the natural log scale.

frmgham2$LN_GLUCOSE <- log(frmgham2$GLUCOSE)

Exercies 8

Missing data are classified as NA as there were previously done in the original continuous variable BMI.

frmgham2$BMI_CATEGORY <- ifelse (frmgham2$BMI < 18.5, "Underweight", 
ifelse (frmgham2$BMI >= 18.5 & frmgham2$BMI <= 24.9, "Normal",
ifelse (frmgham2$BMI > 24.9 & frmgham2$BMI <= 29.9, "Overweight",
ifelse (frmgham2$BMI > 29.9 & frmgham2$BMI <= 34.9, "Obesity 1",                                         ifelse (frmgham2$BMI > 34.9 & frmgham2$BMI <= 39.9, "Obesity 2",                                        ifelse (frmgham2$BMI > 39.9, "Obesity 3", NA))))))

Exercise 9

There are 41 variables and 3262 observations in the restricted dataset.

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
frmgham_restricted = filter (frmgham2, PERIOD == '3')
str(frmgham_restricted)
## tibble [3,263 × 41] (S3: tbl_df/tbl/data.frame)
##  $ RANDID      : num [1:3263] 2448 6238 11252 11263 12806 ...
##  $ SEX         : num [1:3263] 1 2 2 2 2 1 1 2 2 2 ...
##  $ TOTCHOL     : num [1:3263] 209 237 NA 220 320 280 211 291 159 264 ...
##  $ AGE         : num [1:3263] 52 58 58 55 57 64 55 62 53 51 ...
##  $ SYSBP       : num [1:3263] 121 108 155 180 110 168 173 120 124 141 ...
##  $ DIABP       : num [1:3263] 66 66 90 106 46 100 123 70 78 81 ...
##  $ CURSMOKE    : num [1:3263] 0 0 1 0 1 0 0 0 0 1 ...
##  $ CIGPDAY     : num [1:3263] 0 0 30 0 30 0 0 0 0 15 ...
##  $ BMI         : num [1:3263] NA 28.5 24.6 31.2 22 ...
##  $ DIABETES    : num [1:3263] 0 0 0 1 0 0 0 0 0 0 ...
##  $ BPMEDS      : num [1:3263] 0 0 0 1 0 0 1 NA 0 0 ...
##  $ HEARTRTE    : num [1:3263] 69 80 74 86 75 92 75 62 68 85 ...
##  $ GLUCOSE     : num [1:3263] 92 71 NA 81 87 82 85 83 135 97 ...
##  $ educ        : num [1:3263] 4 2 3 2 2 1 1 1 3 2 ...
##  $ PREVCHD     : num [1:3263] 0 0 0 0 0 0 0 0 0 0 ...
##  $ PREVAP      : num [1:3263] 0 0 0 0 0 0 0 0 0 0 ...
##  $ PREVMI      : num [1:3263] 0 0 0 0 0 0 0 0 0 0 ...
##  $ PREVSTRK    : num [1:3263] 0 0 0 0 0 0 0 0 0 0 ...
##  $ PREVHYP     : num [1:3263] 0 0 1 1 0 1 1 0 1 1 ...
##  $ TIME        : num [1:3263] 4628 4344 4285 4351 4289 ...
##  $ PERIOD      : num [1:3263] 3 3 3 3 3 3 3 3 3 3 ...
##  $ HDLC        : num [1:3263] 31 54 NA 46 34 44 48 60 53 58 ...
##  $ LDLC        : num [1:3263] 178 141 NA 135 286 236 163 217 106 206 ...
##  $ DEATH       : num [1:3263] 0 0 0 0 0 0 0 0 1 1 ...
##  $ ANGINA      : num [1:3263] 0 0 0 0 0 0 0 0 0 0 ...
##  $ HOSPMI      : num [1:3263] 1 0 0 0 0 0 0 0 0 0 ...
##  $ MI_FCHD     : num [1:3263] 1 0 0 1 0 0 0 0 0 0 ...
##  $ ANYCHD      : num [1:3263] 1 0 0 1 0 0 0 0 0 0 ...
##  $ STROKE      : num [1:3263] 0 0 0 0 0 0 0 0 0 0 ...
##  $ CVD         : num [1:3263] 1 0 0 1 0 0 0 0 0 0 ...
##  $ HYPERTEN    : num [1:3263] 0 0 1 1 1 1 1 0 1 1 ...
##  $ TIMEAP      : num [1:3263] 8766 8766 8766 8766 8766 ...
##  $ TIMEMI      : num [1:3263] 6438 8766 8766 8766 8766 ...
##  $ TIMEMIFC    : num [1:3263] 6438 8766 8766 5719 8766 ...
##  $ TIMECHD     : num [1:3263] 6438 8766 8766 5719 8766 ...
##  $ TIMESTRK    : num [1:3263] 8766 8766 8766 8766 8766 ...
##  $ TIMECVD     : num [1:3263] 6438 8766 8766 5719 8766 ...
##  $ TIMEDTH     : num [1:3263] 8766 8766 8766 8766 8766 ...
##  $ TIMEHYP     : num [1:3263] 8766 8766 4285 0 8679 ...
##  $ LN_GLUCOSE  : num [1:3263] 4.52 4.26 NA 4.39 4.47 ...
##  $ BMI_CATEGORY: chr [1:3263] NA "Overweight" "Normal" "Obesity 1" ...

Exercise 10

write.csv(frmgham_restricted, "frmgham_restricted.csv", row.names = FALSE)

Part 2

I believe that it is both – we need more training in data analysis as well as we need to stop misusing hypothesis tests and p-values. Data and statistical analysis can seem daunting and challenging to many people, so they may not invest the time in formally learning how to correctly complete analyses. Additionally, in many academic programs there is not as great of emphasize on learning data analysis. In both my undergraduate and graduate programs, I had one statistics course. As Dr. Peng suggests as data is made more available for all sorts of topics, we need people to be better equipped to critically analyze it. By have more classes that teach how to properly utilize data and to have teachers that are well versed in the true meaning of statistically terms people will be able to utilize these terms and tools correctly.

Per Greenland and colleagues, “the P value simply indicates the degree to which the data conform to the pattern predicted by the test hypothesis and all the other assumptions used in the test (the underlying statistical model). A small P values means that the results observed are more unusual from the predicted pattern, whereas a larger P value means it is less unusual. The 95% confidence interval is the range between two numbers that the true effect lies.