我有一个应该遵循幂律分布的数据。
x = distance
y = %
我想创建一个模型并将拟合线添加到我的图中。
由于作者使用 R 方;我假设他们应用了线性模型,因为 R^2不适用于非线性模型。http://blog.minitab.com/blog/adventures-in-statistics-2/why-is-there-no-r-squared-for-nonlinear-regression
但是,我不知道如何将我的线“弯曲”到点;如何将公式添加y ~ a*x^(-b)
到我的模型中。
我的问题是:
y ~ a*x^(-b)
used by author is linear?lm, glm, nls
, etc. ?I generated the dummy data, including the applied power law formula from the plot above:
set.seed(42)
scatt<-runif(10)
x<-seq(1, 1000, 100)
b = 1.8411
a = 133093
y = a*x^(-b) + scatt # add some variability in my dependent variable
plot(y ~ x)
and tried to create a glm
model.
# formula for non-linear model
m<-m.glm<-glm(y ~ x^2, data = dat) #
# add predicted line to plot
lines(x,predict(m),col="red",lty=2,lwd=3)
This is my first time to model, so I am really confused and I don't know where to start... thank you for any suggestion or directions, I really appreciate it...
I personally think this question a dupe of this: `nls` fails to estimate parameters of my model but I would be cold-blooded if I close it (as OP put a bounty). Anyway, bounty question can not be closed.
So the best I could think of, is to post a community wiki answer (I don't want to get this bounty).
当您想要拟合这种形式的模型时y ~ a*x^(-b)
,通常会受益log
于在两侧进行变换并拟合线性模型log(y) ~ log(x)
。
fit <- lm(log(y) ~ log(x))
正如您已经知道如何使用curve
绘制回归曲线并对此感到满意,我现在将展示如何绘制回归曲线。
有些人称之为对数回归。以下是我对此类回归的一些其他链接:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句