-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinregression.Rmd
74 lines (56 loc) · 1.82 KB
/
linregression.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
title: "Linear Regression"
author: "FMU Biology Department"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Analysis
This documents includes code for creating a data object in R, creating an informative plot, and running a linear regression. A description of the data can be found in the "Correlation" tutorial.
```{r fullcode, eval=TRUE}
#Create data frame
dat3 = data.frame(sodium = c(95,104,88,97,102,89,104,105,111,88,
98,102,96,105,107,105,96,90,110,98),
elec = c(190,200,192,202,196,195,200,202,206,180,
205,199,193,205,208,210,204,197,206,200))
#Print data frame
dat3
#Summary statistics
#Average and standard deviation of sodium
mean(dat3$sodium)
sd(dat3$sodium)
#Average and standard deviation of elec
mean(dat3$elec)
sd(dat3$elec)
#Create scatterplot
plot(dat3$elec~dat3$sodium,
ylab = "Electrical output (watts)", xlab = "Sodium concentration (mEq/L)")
#Perform a linear regression analysis
mod1=lm(dat3$elec ~ dat3$sodium)
summary(mod1)
```
\pagebreak
### Full code block
```{r fullcode2, eval=FALSE}
#Create data frame
dat3 = data.frame(sodium = c(95,104,88,97,102,89,104,105,111,88,
98,102,96,105,107,105,96,90,110,98),
elec = c(190,200,192,202,196,195,200,202,206,180,
205,199,193,205,208,210,204,197,206,200))
#Print data frame
dat3
#Summary statistics
#Average and standard deviation of sodium
mean(dat3$sodium)
sd(dat3$sodium)
#Average and standard deviation of elec
mean(dat3$elec)
sd(dat3$elec)
#Create scatterplot
plot(dat3$elec~dat3$sodium,
ylab = "Electrical output (watts)", xlab = "Sodium concentration (mEq/L)")
#Perform a linear regression analysis
mod1=lm(dat3$elec ~ dat3$sodium)
summary(mod1)
```