作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试对一些数据进行建模。我在 Excel 上的运气比 R 好,但 Excel 解决方案无法扩展,所以我需要弄清楚如何在 R 中做到这一点。
Excel 会将趋势线映射到数据,而幂曲线会产生合理的 y = 0.6462x^-0.542。
当我将相同的数据放入 R 并尝试使用 poweRlaw
包中的连续幂律对其进行建模时,我得到类似 y = 0.14901x^-3.03671
的信息。截距太小,而 alpha 太大。
# 14 days of % of users retained
y = c(0.61431 , 0.42585 , 0.35427 , 0.33893 , 0.28853 , 0.26004 , 0.2352 , 0.20087 , 0.17969 , 0.1848 , 0.17311 , 0.17092 , 0.15777 , 0.14901)
y.pl = conpl$new(y)
y.pl_est = estimate_xmin(c_pl)
y.pl_est
# $KS
# 0.1068587
#
# $xmin
# 0.14901
#
# $pars
# 3.03673
#
# $ntail
# 14
lm
或
glm
来做一个功率曲线,给出合理的截距和 alpha?
最佳答案
我没有使用过 poweRlaw
包,但 R 的基础 nls
(非线性最小二乘法)函数给出的结果类似于你使用 Excel 得到的结果。如果有区别,在检查我的代码是否有错误后,我的第一个想法是“对 Excel 来说更糟”:)。
# Data
dat = data.frame(x=1:14,
y = c(0.61431 , 0.42585 , 0.35427 , 0.33893 , 0.28853 , 0.26004 , 0.2352 , 0.20087 , 0.17969 , 0.1848 , 0.17311 , 0.17092 , 0.15777 , 0.14901))
# Model
m1 = nls(y ~ a*x^b, list(a=1,b=1), data=dat)
summary(m1)
Formula: y ~ a * x^b
Parameters:
Estimate Std. Error t value Pr(>|t|)
a 0.62104 0.01307 47.51 4.94e-15 ***
b -0.51460 0.01525 -33.74 2.92e-13 ***
# Plot nls model
curve(coef(m1)[1]*x^coef(m1)[2], from=1, to=14)
# Add curve for Excel model in red
curve(0.6462*x^(-0.542), from=1, to=14, col="red", lty=2, add=TRUE)
# Add data points
points(dat$x, dat$y)
关于r - Excel 中的幂律比 R 好用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34623121/
我有一个带有 id、x 和 y 坐标的顶点 vector ,我想为我的顶点生成一个幂律图。 Boost 库图提供幂律 plod_iterator() 但我如何用我的顶点生成它。任何人都可以帮忙吗? 最
我是一名优秀的程序员,十分优秀!