Use function mle2() in bbmle package (R) to get parameters for exponential and power law distributions


Ling Zhang

Here is part of mydata:

The raw data is very large, so I uploaded part of 20 rows.

x <- [7.6,2.2,1.1,4.7,8.6,7.5,7.5,29.9,5.0,3.0,2.4,1.5,14.9,3.9,3.7,3.2,5.0,1.7,2.9,2.3]

Here is the function description

  1. ol:y=A*x^-(u)
  2. index:y=B*exp^(-βx)

uNow, I want to get power law and exponential distribution using MLE (maximum likelihood method) .β

#set likelihood function of power law
pl <- function(u){-n*log(u-1)-n*(u-1)*log(min(x))+u*sum(log(x))}

#set likelihood function of exponential distribution
ex <- function(β){-n*log(β)+β*sum(x)}

Are these functions correct?

Use mle2() to get parameters:

#get the parameter u of power law
s1 <- mle2(pl,start = list(u=2),data = list(x))
summary(s1)
#get the parameter lamda of exponential distribution
s2 <- mle2(ex,start = list(β=2),data = list(x))
summary(s2)

Now here are two questions:

  1. How to determine which one is the best fit for the model

    Using confint() to get 95% confidence, how to get Rsquared and AIC (Akaike weigths) for both models?

  2. How can I plot the fit on top of the original data after getting which one is the best fit for the data?

I am using R.3.2.2 in Windows 7.

Ben Bolker

Almost as expected. You haven't specified the conditional distribution of your data, so I'll assume "normality". (Given that, you can also use nls()- least squares is a normal, maximum-likelihood estimate of a coherent response), although mle2that gives more room for using optimizers, etc. )

I'll use the formula interface, which is handy if your model isn't too complicated.

ol

mle2(y~dnorm(mean=A*x^(-mu),sd=exp(logsd),
     start=list(A=...,mu=...,logsd=...),
     ## no need for list() if mydata is already data.frame
     data=mydata)   

exponentially

  mle2(y~dnorm(mean=B*exp(-beta*x),sd=exp(logsd),
     start=list(B=...,beta=...,logsd=...),
     data=mydata)  

The elements in ... startare any reasonable starting values. Given your data above, these methods should work reasonably well on a subset of the data. However, they may not work well with 10 million observations. I would consider using

glm(y~x,family=gaussian(link="log"),data=mydata)

Fit an exponential curve and

glm(y~log(x),family=gaussian(link="log"),data=mydata)

Fit a power law curve.

Related


Error running MLE2 function (BBMLE)

tension mle2()I get the following error when running a function from a package bbmlein R : Some parameters are on the boundary: Hessian-based variance-covariance calculations may be unreliable I'm trying to understand if this is due to a problem with my data o

Error running MLE2 function (BBMLE)

tension mle2()I get the following error when running a function from a package bbmlein R : Some parameters are on the boundary: Hessian-based variance-covariance calculations may be unreliable I'm trying to understand if this is due to a problem with my data o

Error running MLE2 function (BBMLE)

tension mle2()I get the following error when running a function from a package bbmlein R : Some parameters are on the boundary: Hessian-based variance-covariance calculations may be unreliable I'm trying to understand if this is due to a problem with my data o

Error running MLE2 function (BBMLE)

tension mle2()I get the following error when running a function from a package bbmlein R : Some parameters are on the boundary: Hessian-based variance-covariance calculations may be unreliable I'm trying to understand if this is due to a problem with my data o

Error running MLE2 function (BBMLE)

tension mle2()I get the following error when running a function from a package bbmlein R : Some parameters are on the boundary: Hessian-based variance-covariance calculations may be unreliable I'm trying to understand if this is due to a problem with my data o

Error running MLE2 function (BBMLE)

tension mle2()I get the following error when running a function from a package bbmlein R : Some parameters are on the boundary: Hessian-based variance-covariance calculations may be unreliable I'm trying to understand if this is due to a problem with my data o

Use bbmle with vector arguments: mle2 (already run with optim)

Brix bbmle:mle2I'm having some trouble using the function when trying to do a regression . To illustrate my problem, I came up with a toy example. We define negative log-likelihood for a Poisson distribution (or any custom distribution): LL <- function(beta, z

Use bbmle with vector arguments: mle2 (already run with optim)

Brix bbmle:mle2I'm having some trouble using the function when trying to do a regression . To illustrate my problem, I came up with a toy example. We define negative log-likelihood for a Poisson distribution (or any custom distribution): LL <- function(beta, z

Use bbmle with vector arguments: mle2 (already run with optim)

Brix bbmle:mle2I'm having some trouble using the function when trying to do a regression . To illustrate my problem, I came up with a toy example. We define negative log-likelihood for a Poisson distribution (or any custom distribution): LL <- function(beta, z

Use bbmle with vector arguments: mle2 (already run with optim)

Brix bbmle:mle2I'm having some trouble using the function when trying to do a regression . To illustrate my problem, I came up with a toy example. We define negative log-likelihood for a Poisson distribution (or any custom distribution): LL <- function(beta, z

Use bbmle with vector arguments: mle2 (already run with optim)

Brix bbmle:mle2I'm having some trouble using the function when trying to do a regression . To illustrate my problem, I came up with a toy example. We define negative log-likelihood for a Poisson distribution (or any custom distribution): LL <- function(beta, z

Use the mle2 function

username I want to find the parameters of MLE epsilonand muin a pattern like this: $$ X \ sim \ frac {1} {mu1} e ^ {-x / mu1} + \ frac {1} {mu2} e ^ [-x / mu2} $$ I'm trying to do this using a mle2function from a package bbmlelike this: library(Renext) library

Use the mle2 function

username I want to find the parameters of MLE epsilonand muin a pattern like this: $$ X \ sim \ frac {1} {mu1} e ^ {-x / mu1} + \ frac {1} {mu2} e ^ [-x / mu2} $$ I'm trying to do this using a mle2function from a package bbmlelike this: library(Renext) library

Use the mle2 function

username I want to find the parameters of MLE epsilonand muin a pattern like this: $$ X \ sim \ frac {1} {mu1} e ^ {-x / mu1} + \ frac {1} {mu2} e ^ [-x / mu2} $$ I'm trying to do this using a mle2function from a package bbmlelike this: library(Renext) library

Use the mle2 function

username I want to find the parameters of MLE epsilonand muin a pattern like this: $$ X \ sim \ frac {1} {mu1} e ^ {-x / mu1} + \ frac {1} {mu2} e ^ [-x / mu2} $$ I'm trying to do this using a mle2function from a package bbmlelike this: library(Renext) library

Use the mle2 function

username I want to find the parameters of MLE epsilonand muin a pattern like this: $$ X \ sim \ frac {1} {mu1} e ^ {-x / mu1} + \ frac {1} {mu2} e ^ [-x / mu2} $$ I'm trying to do this using a mle2function from a package bbmlelike this: library(Renext) library

Use the mle2 function

username I want to find the parameters of MLE epsilonand muin a pattern like this: $$ X \ sim \ frac {1} {mu1} e ^ {-x / mu1} + \ frac {1} {mu2} e ^ [-x / mu2} $$ I'm trying to do this using a mle2function from a package bbmlelike this: library(Renext) library

Problems implementing MLE estimation in the bbmle package (for R)

will I am trying to validate the MLEs for $\alpha$ , $\beta$ and $\lambda$ obtained for the Logistic-Lomax distribution by Zubair et al. in their paper titled A Study of Logistic-Lomax Distribution when using Dataset 1 . The paper uses the following code to do

Fitting a power-law function to data in R

L55 I am trying to fit a power law function to my data using the step-by-step approach here https://www.statology.org/power-regression-in-r/ but i am not clear about the error ```Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/I

Solving Power-Law Distributions in Python

Bully Willie Plaza My data is very similar to the distribution . I would like to use Python to approximate data by solving two equations of the form:power law yis the y-axis data. In Python it would be data[i]. x will be i + 1. So we get two equations with two

Solving Power-Law Distributions in Python

Bully Willie Plaza My data is very similar to the distribution . I would like to use Python to approximate data by solving two equations of the form:power law yis the y-axis data. In Python it would be data[i]. x will be i + 1. So we get two equations with two

Min-max optimization of power-law parameters in R

Zebra Propulsion Laboratory Suppose the dataset is drawn from a power law distribution when the value is greater than $x_{min}$. I want to estimate $\alpha$ and $x_{min}$ for a power law distribution in R. According to http://arxiv.org/abs/0706.1062 : $ \ hat

How to use rug function for exponential distribution in R?

Rimi I'm just getting started with R, sorry if my question is very basic. I want to plot time intervals (distribution is exponential) on the x-axis with a tick mark at the end of each interval. If I have a string of times say (0.2, 0.8, 0.9 , 1.0) then the tic

Create random graphs with "same" power-law degree distributions

username I have an undirected graph (Protein-Protein Interaction Network, PPi) for which I know that its degree distribution approximates a power-law distribution. I want to create 1,000 random graphs to replicate the number of nodes, edges and "similar" power

R: different results with glm and mle2 packages in R

Jasmine Helen So I want to use GLM to find the estimated parameters and compare them with the mle2 package. Here is my GLM code d <- read.delim("http://dnett.github.io/S510/Disease.txt") d$disease=factor(d$disease) d$ses=factor(d$ses) d$sector=factor(d$sector