简体   繁体   English

估计回归线的方程

[英]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 .我知道我需要找到的答案是118.91-0.905x (这在答案键中)但我拥有的代码给了我答案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:这就是我在 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.数据以多个 (x, y) 坐标点的形式提供。 It is assumed that the equation formula is in the form of:假设方程公式为:

y = mx + b

with slope m and y-intercept b .斜率m和 y 截距b

The lm function in R uses a formula which utilizes the ~ operator. R 中的lm function 使用使用~运算符的公式。

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. y ~ model 形式的表达式被解释为响应 y 由 model 符号指定的线性预测器建模的规范。

See more info on formulas here .此处查看有关公式的更多信息。

In that case, if you want response, y (porosity), modeled by predictor, x (weight), you would have:在这种情况下,如果您想要响应y (孔隙率),由预测变量x (重量)建模,您将拥有:

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

where data[,2] is the second column of data, y , and data[,1] is the first column, x .其中data[,2]是第二列数据y ,而data[,1]是第一列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.截距b为 118.9,斜率mx系数)为 -0.9。 The equation thus is: y = -0.9x + 118.9.因此等式是:y = -0.9x + 118.9。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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