Displaying 20 results from an estimated 6000 matches similar to: "Using nlm or optim"
2010 Jun 03
3
Nested ANOVA with covariate using Type III sums of squares
Hello,
I have been trying to get an ANOVA table for a linear model containing a
single nested factor, two fixed factors and a covariate:
carbonmean<-lm(C.Mean~ Mean.richness + Diversity + Zoop + Diversity/Phyto +
Zoop*Diversity/Phyto)
where, *Mean.richness* is a covariate*, Zoop* is a categorical variable (the
species), *Diversity* is a categorical variable (Low or High), and
2012 Jul 05
3
Maximum Likelihood Estimation Poisson distribution mle {stats4}
Hi everyone!
I am using the mle {stats4} to estimate the parameters of distributions by
MLE method. I have a problem with the examples they provided with the
mle{stats4} html files. Please check the example and my question below!
*Here is the mle html help file *
http://stat.ethz.ch/R-manual/R-devel/library/stats4/html/mle.html
http://stat.ethz.ch/R-manual/R-devel/library/stats4/html/mle.html
2009 Jul 01
2
Difficulty in calculating MLE through NLM
Hi R-friends,
Attached is the SAS XPORT file that I have imported into R using following code
library(foreign)
mydata<-read.xport("C:\\ctf.xpt")
print(mydata)
I am trying to maximize logL in order to find Maximum Likelihood Estimate (MLE) of 5 parameters (alpha1, beta1, alpha2, beta2, p) using NLM function in R as follows.
# Defining Log likelihood - In the function it is noted as
2012 Nov 25
5
bbmle "Warning: optimization did not converge"
I am using the Ben bolker's R package "bbmle" to estimate the parameters of a
binomial mixture distribution via Maximum Likelihood Method. For some data
sets, I got the following warning messages:
*Warning: optimization did not converge (code 1: )
There were 50 or more warnings (use warnings() to see the first 50)*
Also, warnings() results the following:
*In 0:(n - x) : numerical
2008 May 23
1
maximizing the gamma likelihood
for learning purposes and also to help someone, i used roger peng's
document to get the mle's of the gamma where the gamma is defined as
f(y_i) = (1/gammafunction(shape)) * (scale^shape) * (y_i^(shape-1)) *
exp(-scale*y_i)
( i'm defining the scale as lambda rather than 1/lambda. various books
define it differently ).
i found the likelihood to be n*shape*log(scale) +
2019 Apr 24
1
Bug in "stats4" package - "confint" method
Dear R developers,
I noticed a bug in the stats4 package, specifically in the confint method applied to ?mle? objects.
In particular, when some ?fixed? parameters define the log likelihood, these parameters are stored within the mle object but they are not used by the ?confint" method, which retrieves their value from the global environment (whenever they still exist).
Sample code:
>
2010 Jun 15
1
Error in nlm : non-finite value supplied by 'nlm'
Hello,
I am trying to compute MLE for non-Gaussian AR(1). The error term follows a difference poisson distribution. This distribution has one parameter (vector[2]).
So in total I want to estimate two parameters: the AR(1) paramter (vector[1]) and the distribution parameter.
My function is the negative loglikelihood derived from a mixing operator.
f=function(vector)
2011 Oct 17
1
simultaneously maximizing two independent log likelihood functions using mle2
Hello,
I have a log likelihood function that I was able to optimize using
mle2. I have two years of the data used to fit the function and I would
like to fit both years simultaneously to test if the model parameter
estimates differ between years, using likelihood ratio tests and AIC.
Can anyone give advice on how to do this?
My likelihood functions are long so I'll use the tadpole
2012 Oct 05
2
problem with convergence in mle2/optim function
Hello R Help,
I am trying solve an MLE convergence problem: I would like to estimate
four parameters, p1, p2, mu1, mu2, which relate to the probabilities,
P1, P2, P3, of a multinomial (trinomial) distribution. I am using the
mle2() function and feeding it a time series dataset composed of four
columns: time point, number of successes in category 1, number of
successes in category 2, and
2007 Jan 10
2
problems with optim, "for"-loops and machine precision
Dear R experts,
I have been encountering problems with the "optim" routine using "for"
loops. I am determining the optimal parameters of several nested models by
minimizing the negative Log-Likelihood (NLL) of a dataset.
The aim is to find the model which best describes the data. To this end, I
am simulating artificial data sets based on the model with the least number
2006 Aug 09
1
scaling constant in optim("L-BFGS-B")
Hi all,
I am trying to find estimates for 7 parameters of a model which should fit
real data. I have a function for the negative log likelihood (NLL) of the
data. With optim(method="L-BFGS-B",lower=0) I am now minimizing the NLL to
find the best fitting parameters.
My problem is that the algorithm does not converge for certain data sets. I
have read that one should scale the fn
2005 Jun 29
2
MLE with optim
Hello,
I tried to fit a lognormal distribution by using optim. But sadly the output
seems to be incorrect.
Who can tell me where the "bug" is?
test = rlnorm(100,5,3)
logL = function(parm, x,...) -sum(log(dlnorm(x,parm,...)))
start = list(meanlog=5, sdlog=3)
optim(start,logL,x=test)$par
Carsten.
[[alternative HTML version deleted]]
2005 May 31
1
Solved: linear regression example using MLE using optim()
Thanks to Gabor for setting me right. My code is as follows. I found
it useful for learning optim(), and you might find it similarly
useful. I will be most grateful if you can guide me on how to do this
better. Should one be using optim() or stats4::mle?
set.seed(101) # For replicability
# Setup problem
X <- cbind(1, runif(100))
theta.true <- c(2,3,1)
y <- X
2012 Nov 30
2
NA return to NLM routine
Hello,
I am trying to understand a small quirk I came across in R. The
following code results in an error:
k <- c(2, 1, 1, 5, 5)
f <- c(1, 1, 1, 3, 2)
loglikelihood <- function(theta,k,f){
if( theta<1 && theta>0 )
return(-1*sum(log(choose(k,f))+f*log(theta)+(k-f)*log(1-theta)))
return(NA)
}
nlm(loglikelihood ,0.5, k, f )
Running this code results in:
Error
2008 Aug 12
2
Maximum likelihood estimation
Hello,
I am struggling for some time now to estimate AR(1) process for commodity price time series. I did it in STATA but cannot get a result in R.
The equation I want to estimate is: p(t)=a+b*p(t-1)+error
Using STATA I get 0.92 for a, and 0.73 for b.
Code that I use in R is:
p<-matrix(data$p) # price at time t
lp<-cbind(1,data$lp) # price at time t-1
2006 Aug 26
1
problems with loop
Dear all,
I am trying to evaluate the optimisation behaviour of a function. Originally
I have optimised a model with real data and got a set of parameters. Now I
am creating simulated data sets based on these estimates. With these
simulations I am estimating the parameters again to see how variable the
estimation is. To this end I have written a loop which should generate a new
simulated data
2008 Jun 16
1
Error in maximum likelihood estimation.
Dear UseRs,
I wrote the following function to use MLE.
---------------------------------------------
mlog <- function(theta, nx = 1, nz = 1, dt){
beta <- matrix(theta[1:(nx+1)], ncol = 1)
delta <- matrix(theta[(nx+2):(nx+nz+1)], ncol = 1)
sigma2 <- theta[nx+nz+2]
gamma <- theta[nx+nz+3]
y <- as.matrix(dt[, 1], ncol = 1)
x <- as.matrix(data.frame(1,
1999 Dec 09
1
nlm() problem or MLE problem?
I am trying to do a MLE fit of the weibull to some data, which I attach.
fitweibull<-function()
{
rt<-scan("r/rt/data2/triam1.dat")
rt<-sort(rt)
plot(rt,ppoints(rt))
a<-9
b<-.27
fn<-function(p) -sum( log(dweibull(rt,p[1],p[2])) )
cat("starting -log like=",fn(c(a,b)),"\n")
out<-nlm(fn,p=c(a,b), hessian=TRUE)
2010 Dec 16
1
Optim function with meta parameters
Hi guys.
I have a dataset with 4 columns. In the first and second column I have the
same qualitative variable referred to different teams of people. There are
10 teams in total and they compete against each other to perform a certain
task whose result is stored in the third column for the team recorded in the
first column, and in the fourth column for the team in the second column.
For example,
2005 Feb 24
2
a question about function eval()
Hi,
I have a question about the usage of eval(). Wonder if any experienced user can help me out of it.
I use eval() in the following function:
semireg.pwl <- function(coef.s=rnorm(1),coef.a=rnorm(1),knots.pos=knots.x,knots.ini.val=knots.val){
knotn <- length(knots.pos)
def.par.env <- sys.frame(1)
print(def.par.env)
print(environment(coef.s))
tg <- eval( (parse(text=