1: Structure & Type

head(df)
##   ndrm.ch drm.ch    sex age      race height weight actn3.r577x    bmi
## 1      40     40 Female  27 Caucasian   65.0    199          CC 33.112
## 2      25      0   Male  36 Caucasian   71.7    189          CT 25.845
## 3      40      0 Female  24 Caucasian   65.0    134          CT 22.296
## 4     125      0 Female  40 Caucasian   68.0    171          CT 25.998
## 5      40     20 Female  32 Caucasian   61.0    118          CC 22.293
## 6      75      0 Female  24  Hispanic   62.2    120          CT 21.805
tail(df)
##     ndrm.ch drm.ch    sex age      race height weight actn3.r577x    bmi
## 590    52.9   12.5   Male  24     Asian   67.0  157.0          CC 24.587
## 591    62.5   28.6   Male  24     Asian   71.5  163.0          CC 22.415
## 592    87.5   12.5 Female  22 Caucasian   65.5  136.0          CT 22.285
## 593   100.0   12.5 Female  21     Asian   59.0   99.5          CT 20.094
## 594    43.8   14.3 Female  31 Caucasian   64.0  134.0          CT 22.999
## 595    43.8   14.3 Female  30 Caucasian   64.0  134.0          CC 22.999
str(df)
## 'data.frame':    595 obs. of  9 variables:
##  $ ndrm.ch    : num  40 25 40 125 40 75 100 57.1 33.3 20 ...
##  $ drm.ch     : num  40 0 0 0 20 0 0 -14.3 0 0 ...
##  $ sex        : chr  "Female" "Male" "Female" "Female" ...
##  $ age        : int  27 36 24 40 32 24 30 28 27 30 ...
##  $ race       : chr  "Caucasian" "Caucasian" "Caucasian" "Caucasian" ...
##  $ height     : num  65 71.7 65 68 61 62.2 65 68 68.2 62.2 ...
##  $ weight     : num  199 189 134 171 118 120 134 162 189 120 ...
##  $ actn3.r577x: chr  "CC" "CT" "CT" "CT" ...
##  $ bmi        : num  33.1 25.8 22.3 26 22.3 ...

2: Descriptive Statistics

For height and age: 1. Mean

mean_height<-sum(df$height)/length(df$height)
print(paste("The mean for height is:",mean_height))
## [1] "The mean for height is: 66.8314285714286"
mean_height<-mean(df$height)
print(paste("The mean for height with the function is:",mean_height))
## [1] "The mean for height with the function is: 66.8314285714286"
mean_age<-sum(df$age)/length(df$age)
print(paste("The mean for age is:",mean_age))
## [1] "The mean for age is: 24.4016806722689"
mean_age<-mean(df$age)
print(paste("The mean for age with the function is:",mean_age))
## [1] "The mean for age with the function is: 24.4016806722689"
  1. Median
median_height<-median(df$height)
median_age<-median(df$age)

print(paste("The median for height is:",median_height))
## [1] "The median for height is: 67"
print(paste("The median for height is:",median_age))
## [1] "The median for height is: 22"
  1. Mode
a<-table(df$height)
names(a)[which.max(a)]
## [1] "65"
a<-table(df$age)
names(a)[which.max(a)]
## [1] "19"
  1. Standard Deviation
mean_h<-mean(df$height)
sub<-df$height-mean_h
sqr<-sub^2
variance<-sum(sqr)/(length(sqr)-1)
stde<-sqrt(variance)
print(stde)
## [1] 3.573363
print(var(df$height))
## [1] 12.76893
print(sd(df$height))
## [1] 3.573363
print(paste("The variance for height is", variance))
## [1] "The variance for height is 12.7689264069264"
print(paste("The standard deviation for height is",stde))
## [1] "The standard deviation for height is 3.57336345855364"
var_age<-var(df$age)
sd_age<-sd(df$age)
print(paste("The variance for age is", var_age))
## [1] "The variance for age is 33.7996604702487"
print(paste("The standard deviation for age is",sd_age))
## [1] "The standard deviation for age is 5.8137475409798"
ggplot(df,aes(height))+
  geom_boxplot()

ggplot(df,aes(age))+
  geom_boxplot()

quantile(df$height)
##    0%   25%   50%   75%  100% 
## 57.00 64.25 67.00 69.00 77.00
IQR(df$height)
## [1] 4.75
ggplot(df,aes(height))+
  geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.

ggplot(df,aes(age))+
  geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.

counts<-table(df$actn3.r577x)
perc<-prop.table(counts)*100
dfperc<-as.data.frame(perc)
ggplot(dfperc,aes(x=Var1,y=Freq))+
  geom_bar(stat="identity")

cor(df$height,df$age)
## [1] 0.03604407
addmargins(prop.table(table(df$race,df$actn3.r577x)))
##             
##                       CC          CT          TT         Sum
##   African Am 0.026890756 0.010084034 0.008403361 0.045378151
##   Asian      0.035294118 0.030252101 0.026890756 0.092436975
##   Caucasian  0.210084034 0.363025210 0.211764706 0.784873950
##   Hispanic   0.006722689 0.016806723 0.015126050 0.038655462
##   Other      0.011764706 0.018487395 0.008403361 0.038655462
##   Sum        0.290756303 0.438655462 0.270588235 1.000000000