Does Strength Law in Excel Work Better Than R?

I am trying to simulate some data. I was more fortunate with Excel than with R, but the Excel solution will not scale, so I need to understand how to do this in R.

Excel will display a trend line for the data, and the power curve gives a reasonable y = 0.6462x ^ -0.542.

When I put the same data in R and try to model it with a continuous power law in a package poweRlaw, I get something like y = 0.14901x^-3.03671. The interception is too small, and the alpha is too large.

# 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

The image shows how models built from 14-day data with Excel and R conpl () are mapped to activities up to day 60

Is there a way to use lmor glmto perform a power curve that gives reasonable interception and alpha?

+4
source share
2 answers

poweRlaw, R base 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)

enter image description here

+6

, Excel - Excel , , x y .

@eipi10 :

dat = transform(dat, logx = log(x), logy = log(y))
mod = lm(logy ~ logx, data = dat)

## intercept
exp(coef(mod)[1])
# (Intercept) 
#   0.6461621 

## power
coef(mod)[2]
#       logx 
# -0.5424412 

, ,

      y = a * x ^ b
 log(y) = log(a) + b * log(x)

, log(a) b .

. , NLS, - MLE, y. (, -, Excel) , , log-normal - . ( eipi , .)

+8

Source: https://habr.com/ru/post/1623006/


All Articles