Many power laws with poweRlaw

I tried using the poweRlaw package to build several powerlaw head restraints. It seems to work for a single curve. But I could not build several charts on one chart. Ref: Is there a way in this package? [Posts I'm a newbie]

set.seed(1) x1 <- ceiling(rlnorm(1000, 4)) x2 <- ceiling(rlnorm(1000, 2)) library(poweRlaw) pl_d = pl_data$new(x1) plot(pl_d) #Now fit the powerlaw m = displ$new(pl_d) #Estimate the cut-off #estimate_xmin(m) aaa <- estimate_xmin(m) aaa <- as.data.frame(aaa) aaa <- aaa[2,1] x_min <- min(table(x)) m$setXmin(aaa); m$mle() #Plot the data and the PL line #plot(m) lines(m, col=2) # next POWER LAW graph #Plot the data pl_d = pl_data$new(x2) points(pl_d) #Now fit the powerlaw m = displ$new(pl_d) #Estimate the cut-off #estimate_xmin(m) aaa <- estimate_xmin(m) aaa <- as.data.frame(aaa) aaa <- aaa[2,1] x_min <- min(table(x)) m$setXmin(aaa); m$mle() #Plot the data and the PL line #points(m) lines(m, col=3) 
+4
source share
1 answer

You can use the lines command to add some of the most suitable force laws. So using your data:

 set.seed(1) x1 = ceiling(rlnorm(1000, 4)) 

we download the package and create a discrete power law object:

 m = displ$new(x1) 

Then build the data

 plot(m) 

Then we set xmin and alpha for each power law and add it to the graph using lines :

 m$setXmin(100) p_100 = estimate_pars(m) m$setPars(p_100) lines(m, col=2, lwd=2) ##Line 2 m$setXmin(202) p_200 = estimate_pars(m) m$setPars(p_200) lines(m, col=3, lwd=2) 

enter image description here


If you want to have multiple data sets on the same chart, the easiest way is to build one data set, but save the data as a data frame. For example, generate some data sets:

 set.seed(1) x1 = ceiling(rlnorm(1000, 4)) x2 = ceiling(rlnorm(1000, 5)) 

Set the laws of power

 m1 = displ$new(x1) m1$setXmin(estimate_xmin(m1)) m2 = displ$new(x2) m2$setXmin(estimate_xmin(m2)) 

Set dataset 2 but save data as pts2

 pts2 = plot(m2) 

Schedule and add lines as usual:

 plot(m1) points(pts2$x, pts2$y, col=3) lines(m1, col=2) lines(m2, col=4) 

To obtain:

enter image description here

+3
source

All Articles