1

I am trying to fit a normal curve to a series of x,y coordinates found in an R dataframe. My goal is to find the best-fitting normal curve an record the mean and sd. I am trying to replicate the results from a paper, so it needs to be done using the BFGS algorithm with the mle2 function:

https://www.rdocumentation.org/packages/bbmle/versions/1.0.23.1/topics/mle2

sample data:


x <- seq(0, 10, by = .1)

y <- dnorm(x, mean = 5, sd = 1.5)

df <- cbind(as.data.frame(x), as.data.frame(y))



My understanding is I need to enter in the function for a normal distribution and then optimize the parameters:


bell_curve <- function(amp, mean, sd) {

  y = amp*(1/(sd*(sqrt(2*pi))))*(exp((-1.0/2.0)*(((x-mean)/sd)**2)))

}

I am getting confused on how to actually construct the mle2() command. In the past I have only used it to optimize two parameters over one data series, and I am not sure how to include both the x and the y data. I have messed around with it for a few days and searched the forums but I cannot find any answers that I can relate to my problem.

I have tried:


results <- mle2(bell_curve, start = c(amp=8, mean=5, sd = 2.5), method = 'BFGS', data = df)

but I get:


 Error in mle2(bell_curve, start = c(amp = 8, mean = 5, sd = 2.5), method = "BFGS",  : 

  some named arguments in 'start' are not arguments to the specified log-likelihood function

I am pretty lost in this depth of statistical analysis, any help would be appreciated.

Thanks

  • 1
    This reads like a programming question rather than a statistical one. There are statistical issues concerning what the x and y coordinates mean, how they are measured, and your theories about how and why they might deviate from the hypothetical Gaussian form: but you need to tell us those things before we can be of much help. For the software side of things you might find closely related threads here on CV to be helpful, including https://stats.stackexchange.com/questions/70870, https://stats.stackexchange.com/questions/43000, and even https://stats.stackexchange.com/questions/11546. – whuber May 08 '20 at 15:01

0 Answers0