I am trying to fit a non linear function to a given set of data (x and y in code snippet), the function is defined as
f(x) = a/((sin((x-b)/2))^4)
x <- c(0, 5, -5, 10, -10, 15, -15, 20, -20, 25, -25, 30, -30)
y <- c(4.21, 3.73, 2.08, 1.1, 0.61, 0.42, 0.13, 0.1, 0.04, 0.036667, 0.016667, 0.007778, 0.007778)
plot(x,y, log="y")
This is how the initial graph on which I should fit before mentioned function looks like.
But when I try to fit using nls and plot the curve, the graph does not look quite right
f <- function(x,a,b) { a/((sin((x-b)/2))^4) }
fitmodel <- nls (y ~ f(x,a,b), start=list(a=1,b=1))
lines(x, predict(fitmodel))
This is what I see:
I am pretty sure I am doing something wrong here and will appreciate any help from you.