Read in the data

Let’s read in the data with the following commands:

library(readxl)

download.file("http://ryanwomack.com/data/PharmaDemo.xls", "mydata.xls")

mydata<-read_excel("mydata.xls")

names(mydata)
##  [1] "Age"                "Gender"             "Weight"            
##  [4] "IV_APAP"            "Epidural"           "Opi_N_T"           
##  [7] "Average_Pain_Score" "Tot_Opi"            "Tramadol"          
## [10] "TOT_LOS_H"          "Painkiller"
attach(mydata)

Describe the Data

Then we will get some summary statistics on the Age and Weight variables:

summary(Age)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    43.0    60.0    66.0    66.2    74.0    89.0
summary(Weight)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   44.55   74.09   90.46   90.87  103.70  166.00

Now plot the data:

Regression

summary(lm(Age~Weight))
## 
## Call:
## lm(formula = Age ~ Weight)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -24.626  -5.943   1.047   6.411  19.980 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 83.00577    2.89586  28.664  < 2e-16 ***
## Weight      -0.18489    0.03108  -5.949 1.21e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.056 on 198 degrees of freedom
## Multiple R-squared:  0.1516, Adjusted R-squared:  0.1473 
## F-statistic: 35.39 on 1 and 198 DF,  p-value: 1.205e-08
ggplot(mydata, aes(Weight, Age))+ geom_point()+ stat_smooth()

All done!