Re: [R] power law

From: Gabor Csardi <csardi_at_rmki.kfki.hu>
Date: Tue 21 Feb 2006 - 20:59:22 EST

See the methods here:
http://arxiv.org/abs/cond-mat/0412004
You can simply use the formula given here for continuous data.

Discrete data is a bit more tricky, this is the function I'm using:

# -------------------------------------------------
power.law.fit <- function(x, xmin=NULL, start=2, ...) {

  if (length(x) == 0) {
    error("zero length vector")
  }
  if (length(x) == 1) {
    error("vector should be at least of length two")   }

  require(stats4)                     

  if (is.null(xmin)) { xmin <- min(x) }                         

  n <- length(x)
  x <- x[ x >= xmin]
  if (length(x) != n) {
    warning("too small values eliminated from vector")     n <- length(x)
  }                                           

  mlogl <- function(alpha) {

     C <- 1/sum( (xmin:10000)^-alpha )
     -n*log(C)+alpha*sum(log(x))
  }
	      

  alpha <- mle(mlogl, start=list(alpha=start), ...)                 

  alpha
}

# -------------------------------------------------

The function (with is manual page) is also included in the igraph package, see http://cneurocvs.rmki.kfki.hu/igraph

Hope this helps,
Gabor

On Wed, Feb 15, 2006 at 08:07:50AM -0500, Glazko, Galina wrote:
> Dear list,
>
>
>
> Does anyone know how to fit the power law distribution?
>
> I have the empirical distribution and would like to check whether it fits
>
> power law (with the power estimated from the data).
>
>
>
> Any hints are appreciated
>
>
>
> Best regards
>
> Galina
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

-- 
Csardi Gabor <csardi@rmki.kfki.hu>    MTA RMKI, ELTE TTK

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Feb 21 21:03:55 2006

This archive was generated by hypermail 2.1.8 : Wed 22 Feb 2006 - 09:27:43 EST