Questions tagged [optim]

32 questions
0
votes
0 answers

R optim not running all iterations. Results change if I call it multiple times

I am using optim to solve an optimization problem. It is a standard minimization of L2 norm, so it is positive, well behaved. However, when using optim, I run into some issues. First I call > lambda2 $par [1] 4.6105840762 0.1268444008…
0
votes
0 answers

how to do maximum likelihood estimation using optim in r?

This is my data about insurance claim claim frequency 0 370412 1 46545 2 3935 3 317 4 28 5 3 I want to get the estimate value and also the parameters value using MLE This is the loglikelihood function that I…
Izzah
  • 1
  • 1
0
votes
0 answers

Optim gives lower bound value consistently

I am trying to estimate the MLE value for the gamma_estimate parameter in R using the Optim() function, with lower bound of 1 and upper bound of 1.9. However, when using the "Brent" and "L-BFGS-B" methods, I am consistently getting the lower bound…
hollyjolly
  • 115
  • 11
0
votes
1 answer

About Constrained Mixed Effects Models

Currently I want to fit a mixed effects model with positive or negative constraints on the parameters. For parameter estimation using Joint Modeling, we use nlme package, which is required by the JM package. In the lme function of the nlme package,…
unk
  • 1
  • 1
0
votes
0 answers

optim function: how to restrict number of decimal places?

I am using the optim function in R to analyze how people percieve distributions. My usual code looks like this: val.FR<-optim(par=0, fn=Frequency.Regression, method=c("Brent"), lower = 0, upper = 1) It seems like optim is increasing the parameter…
Jonas
  • 1
0
votes
0 answers

Dealing with non-finite value supplied by optim error

I am attempting to write code for a one-parameter logistic model in R. I have a large df of country-year observations from 1946 to 2021. Here is the code I have written thus far: # read data data <- read.csv("powers.csv") # write a function for 1PL…
w5698
  • 159
  • 7
0
votes
0 answers

Apply optim() function to each row then cbind result for corresponding row to new or existing data frame

EDIT: I'm going to EDIT this post to streamline my question to hopefully make it clearer. -- CalebPicker I'm trying to use apply() or a for...loop to optimize a custom function on each row, and for each completed optimization, I want the output…
0
votes
0 answers

Converting Optim (and it's Objective Faction) to Rcpp

I have a section of code (see below) drawn from a larger model I am working on. This seems to be the bottle neck and I can see optim has been an issue for many others in the past. I know nothing about C++ and I can see this has been a recommended…
Zac
  • 45
  • 5
0
votes
0 answers

Using optim to estimate 3-parameters log-normal by MLE

I need your help. I am having problems to estimate the parameters of the following data in R using optim. I am always getting a error message of the the following type: Warning: NaNs producedError in optim(par = c(0, 1, -2), nll, method =…
0
votes
0 answers

Find the Maximum with R

I want to find the maximum in one function. I'll start with one input variable in the function, but the goal is at least 4 variables. The function is continuous (but for some variables like first variable) if you give it a decimal it will get the…
0
votes
0 answers

Trying to use optim to find estimates but getting error "attempt to apply non-function"

I'm trying to figure out the negative log likelihood function to get the maximum likelihood and the optim to get estimates. the first line runs fine but when i try and run the second I get the error: Error in dnorm(data$height, mean = x[1](1 -…
0
votes
0 answers

when I change the initial values in optim, the output $par also changes

Below is pdf and i want to find the mles of parameters, howerver when I change the initial values in optim command, the output values of parameters also changes. If anyone can solve the…
0
votes
0 answers

Better optimizer for constrained multinomial likelihood

Using R, I wish to estimate a vector of parameters a_i (of arbitrary length, i.e. i = 1,...,s) with a multinomial likelihood using a corresponding vector of observations n_i totaling a sample size of N=sum_i (n_i). The probabilities p_i of the…
user12734
  • 101
  • 3
0
votes
0 answers

Maximum Likelihood Estimation- Replicating from R to Python

I am trying to replicate the below R code to estimate parameters using Maximum Likelihood method in Python. I want to obtain the same results using both the codes, but my estimated values are different, I am not sure if both the codes are optimising…
Akshaya
  • 11
0
votes
0 answers

How to adjust the step sizes for the finite-difference approximation to the gradient in lbfgsb3c()?

I set a loss function, but the parameters I want to optimize are not so sensitive to the loss function, so it often happens that the result from loss function does not change. Causes a very slow convergence. Therefore I want to adjust the step sizes…
yiboliu
  • 33
  • 5