How to do nonlinear regression in R using the nls function?

0

How to fit a curve to the points given by the following data,

    y <- c(23,16,9,6,4.5,3.8,2.8,2.0,1.6,1.3,1.1,0.93,0.82,0.65,0.65,0.20)
    x <- c(-0.32,0.30,0.24,0.18,-.15,-.11,-.01,0.15,0.30,0.44,0.58,0.68,0.81,
       1.15,1.40,1.62)
usando a função nls() no r. Observei que os dados acima descrevem bem aos dados observados. Tentei fazer desta forma:
   theta0 <- (sum(log(y)*x))/(sum(x^2))
   theta0
   theta0 <- 0.8225334
   ff <- function(x,theta){exp(-theta*x)}
   (f_theta0 <- ff(x=x,theta=theta0))
   (r_theta0 <- y - f_theta0)
   F. <- function(x,theta){-x*exp(-theta*x)}
   (F_theta0=F.(x=x,theta=theta0))
   (theta_1 = theta0+solve(t(F_theta0)%*%F_theta0)%*%F_theta0%*%r_theta0)
   modelo <- nls(y~exp(-theta*x),start=c(theta=0.8225334),trace=T)

   plot(y~x)
   curve(exp(-9.580776*x),1.62,-0.32,add=T,col="blue")

However, I could not get a satisfactory result for the curve. Can someone help me? Thanks.

    
asked by anonymous 20.03.2018 / 20:24

0 answers