Search code examples
rcurve-fittingdata-fitting

Non-linear fit in R


I have a set of data:

x<- c(0.00100000, 0.08977778, 0.17855556, 0.26733333, 0.35611111, 0.44488889, 0.53366667, 0.62244444, 0.71122222)
y <- c(0.094982692, 0.074529874, 0.051782003, 0.026081288, -0.003576486, -0.038845028, -0.082764061, -0.141998524, -0.141998524)

and I wanted to fit a logarithmic curve to the data (y = c*naturalLog(x + k) + d). I tried nls in R ( which was as useful as tits on a fish). I also tried to fit exponential, with no sucess (fit was very bad). My question is, can you see a logarithmic or exponential correlation in the data? My end goal is to find the correlation coefficients, so I can transform y and make the correlation linear.

Any help would be appreciated.


Solution

  • You've said that you used this code:

    m <- nls(1-x ~ a * log(y + b) , data = df, start = list(a = 1, b = 1), nls.control(maxiter = 500)) 
    

    Instead of x (death rate), I used 1-x (birth rate).

    Normally we use y as the response, not x. Also be careful that birth_rate = 1 - death_rate is not generally true, rather survival rate is 1 minus death rate.