简体   繁体   English

如何拟合回归线以在R中绘图?

[英]How to fit regression line to plot in R?

So I have this plot that looks like this: 所以我有这样的情节看起来像这样:

在此处输入图片说明

Both the x and y axis are log, how do I fit a least squares regression line to this? x和y轴均为对数,如何拟合最小二乘回归线呢? This is what I used to plot the graph: plot(log(counts),log="x",type="p") 这是我用来绘制图形的内容:plot(log(counts),log =“ x”,type =“ p”)

counts contains the number of observations of each x... 计数包含每个x的观测数...

The least squares regression for log(counts) on log(x) is simply: log(x)上log(counts)的最小二乘回归简单地是:

lm(log(counts) ~ log(x))

If you want to plot it: 如果要绘制它:

plot(log(counts) ~ log(x))
abline(reg=lm(log(counts) ~ log(x)))

This may not be the most statistically appropriate model for your data, but that's a question for another site.... 这可能不是最适合您数据的统计模型,但这是另一个站点的问题。

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

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