fantasylime
fantasylime

Reputation: 41

Multi-peak Gaussian fit in R with small number of sample

I have only five data set to predict two bimodal Gaussian fit like this one.

x = c(51,92,220, 280, 333)
y = c(40,80,20,60,40)

Here's an example of the plot and loess line using ggplot.

enter image description here

I want to get an equation through Gaussian curve fitting.

So, I use nls() function like this.

fit <- nls(y ~ (C1 * exp(-(x-mean1)**2/(2 * sigma1**2)) +
                    C2 * exp(-(x-mean2)**2/(2 * sigma2**2))),
           start=list(C1=20, mean1=100, sigma1=0.1,
                      C2=20, mean2=270, sigma2=0.1), algorithm="port")

however, it didn't work, show 'singular gradient matrix at initial parameter estimates' error.

I know it was caused by a wrong initial values, but I can't find a solution. Is there any good way? or can't I fit the curve fitting because I only have a small sample?

Upvotes: 0

Views: 556

Answers (1)

Robert Davy
Robert Davy

Reputation: 910

You have 6 unknown parameters but only 5 data points. Somewhat like fitting a straight line to a single data point, there are an infinite no. of parameter choices that will fit your data.

Upvotes: 1

Related Questions