MLE and Bayesian estimation using R of a new probability distribution

How can we get the MLE of parameters of a new probability distribution using R.
How can we generate data using a new distribution using R.
Is there any expert of MCMC techniques....
I need help

I'm not sure what you mean by a "new" probability distribution. Basically, you define a function for the likelihood and then call a function such as optim() to maximize it. There are also packages for mle that you can find with a google search.

There are a variety of functions built in to generate random numbers. For example, rnorm() generates normal random numbers.

What are you thinking about with regard to MCMC techniques?

Thank you sir for your kind response.
Infact I have developed a new generalized exponential distribution with two parameters. As it is a new one there is no built in package in R to find mle of parameters. Secondly I have to estimate the parameters of my distribution using MCMC techniques or any other alternative techniques...

There would be a lot involved in MCMC, so I would start with MLE.

Write a function that takes in data and the two parameters and returns the likelihood (or the log-likelihood). You could then use optim() to maximize this. But since you only have two parameters you might just try a grid search to find the maximum.

This is the code to generate data by inverse function

a = 1

b = 0.5

c = 2

n = 30

x = c()

F = function(x)


InvF1 = function(t) uniroot(function(x) F(x) - t, c(0,10000))$root

u = runif(n, 0, 1)

for (i in 1:n) {




But is not working for given CDF

Error is below

Error in uniroot(function(x) F(x) - t, c(0, 10000)) :

f.lower = f(lower) is NA

Secondly I require R code for MLE estimates of the parameters.
Can provide the pdf

What is the pdf? And what are reasonable ranges for the parameters of the distribution?

The range of both the parameters i.e alpha and lambda and variable x is Zoro to infinity

Can you send me your email address and what's app number if possible please...

Here's some code that doesn't quite work, but should get you started. Might have some typos.

# maximum likelihood for a double exponential 

logLike <- function(x,alpha,lambda){
  sum(-lambda*x - log(lambda*x^2*(1-alpha)) +
    log((alpha*lambda*x + 1)*exp(lambda*(1-alpha)*x - lambda*x - 1)))

# define data x around here
x <- runif(100) # just pretending

maxAlpha <- 100 # change these if unreasonable or if maximum likelihood
maxLambda <- 100 # ends up at limit
nPoints <-  100 # number of points in each direction
alpha <- seq(from=0, to= maxAlpha, length.out = nPoints) 
lambda <- seq(from=0, to= maxLambda, length.out = nPoints) 

el <- matrix(NA, nrow = length(alpha), ncol = length(lambda))

for (iAlpha in 1:length(alpha))
  for(iLambda in 1: length(lambda))
    el[iAlpha, iLambda] <- logLike(x,alpha[iAlpha],lambda[iLambda])

inds <- arrayInd(which.max(el), dim(el))

cat("mle values are: alpha=",alpha[inds[1]]," and lambda = ",lambda[inds[2]])

I think the idea of the RStudio Community is to have public discussions where everyone can benefit.

Thank you very much sir
I will try it tonight

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.