简体   繁体   English

从应该在图形上的位置(最佳拟合线)计算值

[英]Calculating value from where it should sit on a graph (line of best fit)

I have the following sample dataset - 我有以下示例数据集-

|     a     |    f    |
|-----------|---------|
| £75.00    |  43,200 |
| £500.00   |  36,700 |
| £450.00   |  53,400 |
| £450.00   |  25,700 |
| £250.00   |  12,900 |
| £1,600.00 | 136,000 |
| £600.00   |  72,900 |
| £500.00   |  13,000 |
| £500.00   |  49,600 |
| £500.00   |  43,600 |
| £1,000.00 | 104,000 |

And I've used google graphs to create a line of best fit for it 而且我已经使用谷歌图创建最适合它的线

在此处输入图片说明

It has analysed the 'trend line' as 0.762 . 它已将“趋势线”分析为0.762

I simply want to create a function that I can use to calculate A, when given F. I just want a number returned. 我只是想创建一个函数,当给定F时可以用来计算A。我只想返回一个数字。

const calc = f => what_A_should_be_given_F

What might be a good approach for this? 有什么好的方法呢?

Thanks for any help, Ollie 感谢您的帮助,奥利


EDIT: The slope is 83.81246554 , and the y-intercept is 633.9917215 . EDIT:斜率是83.81246554和y截距是633.9917215

You can do it like this. 您可以这样做。

If you have y = mx + b and need to get x you need to modify your equation to x = (y - b) / m 如果您有y = mx + b并且需要得到x ,则需要将方程式修改为x = (y - b) / m

 const arr = [43200, 36700, 53400, 25700, 12900, 136000, 72900, 13000, 49600, 43600, 104000]; const m = 83.81246554; const b = 633.991172215; const calc = f => (f - b) / m; for (let i = 0; i < arr.length; i++) { console.log(`${arr[i]} => ${calc(arr[i])}`); } 

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

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