简体   繁体   中英

Equation of the estimated regression line

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

The question in this assignment is to find the equation of the estimated regression line. Data are provided as multiple (x, y) coordinate points. It is assumed that the equation formula is in the form of:

y = mx + b

with slope m and y-intercept b .

The lm function in R uses a formula which utilizes the ~ operator.

The ~ operator is basic in the formation of such models. An expression of the form y ~ model is interpreted as a specification that the response y is modeled by a linear predictor specified symbolically by model.

See more info on formulas here .

In that case, if you want response, y (porosity), modeled by predictor, x (weight), you would have:

lm(data[,2] ~ data[,1])

where data[,2] is the second column of data, y , and data[,1] is the first column, x .

This will give you:

Call:
lm(formula = data[, 2] ~ data[, 1])

Coefficients:
(Intercept)    data[, 1]  
    118.910       -0.905  

The intercept b is 118.9 and slope m ( x coefficient) is -0.9. The equation thus is: y = -0.9x + 118.9.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM