R nls: setting a curve for data

I am having trouble finding the right curve for my data. If someone more knowledgeable than me has an idea / solution for a more suitable curve, I would be very grateful.

Data: The goal is to predict x from y

dat <- data.frame(x = c(15,25,50,100,150,200,300,400,500,700,850,1000,1500), y = c(43,45.16,47.41,53.74,59.66,65.19,76.4,86.12,92.97, 103.15,106.34,108.21,113) ) 

Here is how far I came:

 model <- nls(x ~ a * exp( (log(2) / b ) * y), data = dat, start = list(a = 1, b = 15 ), trace = T) 

This is not very convenient:

 dat$pred <- predict(model, list(y = dat$y)) plot( dat$y, dat$x, type = 'o', lty = 2) points( dat$y, dat$pred, type = 'o', col = 'red') 

fit plot

Thanks F

+2
source share
1 answer

The prediction x of y of the 5th degree polynomial is not so parsimonius, but seems to correspond:

 fm <- lm(x ~ poly(y, 5), dat) plot(x ~ y, dat) lines(fitted(fm) ~ y, dat) 

(continued after the schedule)

screenshot

You can also consider the drc package UCRS.5b model:

 library(drc) fm <- drm(x ~ y, data = dat, fct = UCRS.5b()) plot(fm) 

screenshot

Note. I originally assumed that you want to predict y from x and wrote the answer below.

The cube looks pretty good:

 plot(y ~ x, dat) fm <- lm(y ~ poly(x, 3), dat) lines(fitted(fm) ~ x, dat) 

(continued after the schedule)

screenshot

Logic with 4 parameters also looks good:

 library(drc) fm <- drm(y ~ x, data = dat, fct = LL.4()) plot(fm) 

screenshot

+5
source

Source: https://habr.com/ru/post/1259887/


All Articles