Re: [R] Help with maximum likelihood estimation
Bricks fly fine with sufficient thrust, but you have lff with a mu argument that never gets used, so the negative log-likelihood is constant and mle() cannot minimize it. You need to read up on the definition of (log-) likelihood and write a proper one for your problem. -pd > On 26 Jun 2019, at 14:01 , avadhoot velankar > wrote: > > I am analyzing animal movement pattern using levy flight pattern and want > to fit power function to observed data and estimate exponent using Maximum > Likelihood Estimation. > > I am using > > lff<-function(mu){1-1/mean(log(x))} > library(stats4) > mle(lff, start = list(mu = 1)) > > where x is the observed data. > > I am getting following error > > Error in solve.default(oout$hessian) : > Lapack routine dgesv: system is exactly singular: U[1,1] = 0 > > This is first time i am writing function and I am as good at algebra > as brick is good at flying. > > Thank you in advance for your help. > > -- > *Avadhoot D. Velankar* > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help with maximum likelihood estimation
I am analyzing animal movement pattern using levy flight pattern and want to fit power function to observed data and estimate exponent using Maximum Likelihood Estimation. I am using lff<-function(mu){1-1/mean(log(x))} library(stats4) mle(lff, start = list(mu = 1)) where x is the observed data. I am getting following error Error in solve.default(oout$hessian) : Lapack routine dgesv: system is exactly singular: U[1,1] = 0 This is first time i am writing function and I am as good at algebra as brick is good at flying. Thank you in advance for your help. -- *Avadhoot D. Velankar* [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help in maximum likelihood estimation
Le 28/03/2016 22:19, heba eldeeb via R-help a écrit : Dear AllI'm trying to find the maximum likelihood estimator of a certain distribution using nlm command but I receive an error as: non-finite value supplied by 'nlm' can't figure out what is wrong in my function Any help? Thank you in advance Hi, Whitout rproducible example, it will be impossible to help you efficiently. See https://www.r-project.org/posting-guide.html Anyway, this error means that your function returns NA or error for some combination of parameters. Marc __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help in maximum likelihood estimation
Dear AllI'm trying to find the maximum likelihood estimator of a certain distribution using nlm command but I receive an error as: non-finite value supplied by 'nlm' can't figure out what is wrong in my function Any help? Thank you in advance [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help in maximum likelihood
Standard error = sqrt(diag(solve(opt$hessian))) Ravi From: Alaa Sindi [mailto:alaasi...@icloud.com] Sent: Wednesday, March 02, 2016 3:22 PM To: Ravi VaradhanCc: r-help@r-project.org Subject: Re: help in maximum likelihood Thank you very much prof. Ravi, That was very helpful. Is there a way to get the t and p value for the coefficients? Thanks Alaa On Mar 2, 2016, at 10:05 AM, Ravi Varadhan > wrote: There is nothing wrong with the optimization. It is a warning message. However, this is a good example to show that one should not simply dismiss a warning before understanding what it means. The MLE parameters are also large, indicating that there is something funky about the model or the data or both. In your case, there is one major problem with the data: for the highest dose (value of x), you have all subjects responding, i.e. y = n. Even for the next lower dose, there is almost complete response. Where do these data come from? Are they real or fake (simulated) data? Also, take a look at the eigenvalues of the hessian at the solution. You will see that there is some ill-conditioning, as the eigenvalues are widely separated. x <- c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610, 1.8839) y <- c( 6, 13, 18, 28, 52, 53, 61, 60) n <- c(59, 60, 62, 56, 63, 59, 62, 60) # note: there is no need to have the choose(n, y) term in the likelihood fn <- function(p) sum( - (y*(p[1]+p[2]*x) - n*log(1+exp(p[1]+p[2]*x))) ) out <- nlm(fn, p = c(-50,20), hessian = TRUE) out eigen(out$hessian) Hope this is helpful, Ravi Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg) Associate Professor, Department of Oncology Division of Biostatistics & Bionformatics Sidney Kimmel Comprehensive Cancer Center Johns Hopkins University 550 N. Broadway, Suite -E Baltimore, MD 21205 410-502-2619 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help in maximum likelihood
Thank you very much prof. Ravi, That was very helpful. Is there a way to get the t and p value for the coefficients? Thanks Alaa > On Mar 2, 2016, at 10:05 AM, Ravi Varadhanwrote: > > There is nothing wrong with the optimization. It is a warning message. > However, this is a good example to show that one should not simply dismiss a > warning before understanding what it means. The MLE parameters are also > large, indicating that there is something funky about the model or the data > or both. In your case, there is one major problem with the data: for the > highest dose (value of x), you have all subjects responding, i.e. y = n. > Even for the next lower dose, there is almost complete response. Where do > these data come from? Are they real or fake (simulated) data? > > Also, take a look at the eigenvalues of the hessian at the solution. You > will see that there is some ill-conditioning, as the eigenvalues are widely > separated. > > x <- c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610, 1.8839) > y <- c( 6, 13, 18, 28, 52, 53, 61, 60) > n <- c(59, 60, 62, 56, 63, 59, 62, 60) > > # note: there is no need to have the choose(n, y) term in the likelihood > fn <- function(p) > sum( - (y*(p[1]+p[2]*x) - n*log(1+exp(p[1]+p[2]*x))) ) > > out <- nlm(fn, p = c(-50,20), hessian = TRUE) > > out > > eigen(out$hessian) > > > Hope this is helpful, > Ravi > > > > Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg) > Associate Professor, Department of Oncology > Division of Biostatistics & Bionformatics > Sidney Kimmel Comprehensive Cancer Center > Johns Hopkins University > 550 N. Broadway, Suite -E > Baltimore, MD 21205 > 410-502-2619 > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help in maximum likelihood
There is nothing wrong with the optimization. It is a warning message. However, this is a good example to show that one should not simply dismiss a warning before understanding what it means. The MLE parameters are also large, indicating that there is something funky about the model or the data or both. In your case, there is one major problem with the data: for the highest dose (value of x), you have all subjects responding, i.e. y = n. Even for the next lower dose, there is almost complete response. Where do these data come from? Are they real or fake (simulated) data? Also, take a look at the eigenvalues of the hessian at the solution. You will see that there is some ill-conditioning, as the eigenvalues are widely separated. x <- c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610, 1.8839) y <- c( 6, 13, 18, 28, 52, 53, 61, 60) n <- c(59, 60, 62, 56, 63, 59, 62, 60) # note: there is no need to have the choose(n, y) term in the likelihood fn <- function(p) sum( - (y*(p[1]+p[2]*x) - n*log(1+exp(p[1]+p[2]*x))) ) out <- nlm(fn, p = c(-50,20), hessian = TRUE) out eigen(out$hessian) Hope this is helpful, Ravi Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg) Associate Professor, Department of Oncology Division of Biostatistics & Bionformatics Sidney Kimmel Comprehensive Cancer Center Johns Hopkins University 550 N. Broadway, Suite -E Baltimore, MD 21205 410-502-2619 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help in maximum likelihood
It's useful to add "print.level=2" inside your call to find that there's essentially nothing wrong. Rvmmin doesn't give the msg and numDeriv gives a similar (BUT NOT EXACTLY THE SAME!) hessian estimate. It's almost always worthwhile turning on the diagnostic printing when doing optimization, even if you throw away the output pretty well right away, because it can often suggest whether the results are reasonable or rubbish. JN On 16-03-01 03:09 PM, Alaa Sindi wrote: > > Hi all, > > what is wrong with this code? I am trying to estimate the model parameters by > maximizing the likelihood function and I am getting this warning > > > Warning message: > In nlm(fn, p = c(-50, 20), hessian = TRUE) : > NA/Inf replaced by maximum positive value > > > > > x <- c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610, 1.8839) > y <- c( 6, 13, 18, 28, 52, 53, 61, 60) > n <- c(59, 60, 62, 56, 63, 59, 62, 60) > fn <- function(p) > sum( - (y*(p[1]+p[2]*x) - n*log(1+exp(p[1]+p[2]*x)) > + log(choose(n, y)) )) > out <- nlm(fn, p = c(-50,20), hessian = TRUE) > > > Thanks > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help in maximum likelihood
Hi all, what is wrong with this code? I am trying to estimate the model parameters by maximizing the likelihood function and I am getting this warning Warning message: In nlm(fn, p = c(-50, 20), hessian = TRUE) : NA/Inf replaced by maximum positive value x <- c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610, 1.8839) y <- c( 6, 13, 18, 28, 52, 53, 61, 60) n <- c(59, 60, 62, 56, 63, 59, 62, 60) fn <- function(p) sum( - (y*(p[1]+p[2]*x) - n*log(1+exp(p[1]+p[2]*x)) + log(choose(n, y)) )) out <- nlm(fn, p = c(-50,20), hessian = TRUE) Thanks __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.