This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
Age <- c(18, 23, 25, 35, 65, 54, 34, 56, 72, 19, 23, 42, 18, 39, 37)
Age
## [1] 18 23 25 35 65 54 34 56 72 19 23 42 18 39 37
MaxHR <- c(202, 186, 187, 180, 156, 169, 174, 172, 153, 199, 193, 174, 198, 183, 178)
MaxHR
## [1] 202 186 187 180 156 169 174 172 153 199 193 174 198 183 178
Age.MaxHR.df <- data.frame(Age = Age, MaxHeartRate = MaxHR)
Age.MaxHR.df
## Age MaxHeartRate
## 1 18 202
## 2 23 186
## 3 25 187
## 4 35 180
## 5 65 156
## 6 54 169
## 7 34 174
## 8 56 172
## 9 72 153
## 10 19 199
## 11 23 193
## 12 42 174
## 13 18 198
## 14 39 183
## 15 37 178
lm(MaxHR ~ Age, data=Age.MaxHR.df )
##
## Call:
## lm(formula = MaxHR ~ Age, data = Age.MaxHR.df)
##
## Coefficients:
## (Intercept) Age
## 210.0485 -0.7977
summary(lm(MaxHR ~ Age, data=Age.MaxHR.df ))
##
## Call:
## lm(formula = MaxHR ~ Age, data = Age.MaxHR.df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.9258 -2.5383 0.3879 3.1867 6.6242
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 210.04846 2.86694 73.27 < 2e-16 ***
## Age -0.79773 0.06996 -11.40 3.85e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.578 on 13 degrees of freedom
## Multiple R-squared: 0.9091, Adjusted R-squared: 0.9021
## F-statistic: 130 on 1 and 13 DF, p-value: 3.848e-08
library(ggplot2)
ggplot(Age.MaxHR.df, aes(x=Age, y=MaxHeartRate)) + geom_point(aes(color = MaxHeartRate))+theme_bw()
lm.r<- (lm(MaxHR ~ Age, data=Age.MaxHR.df ))
layout(matrix(1:4,2,2))
plot(lm.r)
summary(lm.r)
##
## Call:
## lm(formula = MaxHR ~ Age, data = Age.MaxHR.df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.9258 -2.5383 0.3879 3.1867 6.6242
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 210.04846 2.86694 73.27 < 2e-16 ***
## Age -0.79773 0.06996 -11.40 3.85e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.578 on 13 degrees of freedom
## Multiple R-squared: 0.9091, Adjusted R-squared: 0.9021
## F-statistic: 130 on 1 and 13 DF, p-value: 3.848e-08
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.