I am doing an assignment right now where I am given the dataset (seen below) and am asked to obtain the equation of the estimated regression line.
I know the answer that I need to find is 118.91-0.905x
(this is in the answer key) but the code that I have is giving me the answer 130.85-1.076x
. I am not sure what I have wrong in my code. I have looked over it multiple times and do not see anything wrong. I have also double checked that my data is correct and it seems right to me. This is what I have done in R-Studio:
> data = read.csv("P17.csv", header = TRUE)
> data
x y
1 99.0 28.8
2 101.1 27.9
3 102.7 27.0
4 103.0 25.2
5 105.4 22.8
6 107.0 21.5
7 108.7 20.9
8 110.8 19.6
9 112.1 17.1
10 112.4 18.9
11 113.6 16.0
12 113.8 16.7
13 115.1 13.0
14 115.4 13.6
15 120.0 10.8
> plot(data[,1],data[,2],main="Concrete Specimen", xlab="Unit Weight (pcf)",ylab="Porosity (%)",pch=19)
> cor(data[,1], data[,2])
[1] -0.9868573
> data.lm=lm(data[,1]~data[,2])
> data.lm
Call:
lm(formula = data[, 1] ~ data[, 2])
Coefficients:
(Intercept) data[, 2]
130.854 -1.076
And here is the data that I am using:
x,y
99.0,28.8
101.1,27.9
102.7,27.0
103.0,25.2
105.4,22.8
107.0,21.5
108.7,20.9
110.8,19.6
112.1,17.1
112.4,18.9
113.6,16.0
113.8,16.7
115.1,13.0
115.4,13.6
120.0,10.8