Thomas
Thomas

Reputation: 491

Two-parameter square root model regression R

I need to perform a regression model from my data x and y. The model is y = b * ((x-0) * (1-exp(d*(x-100))). I need to obtain the b and d constants. I have done it before (a while ago), but for some reason, I have sweat it out. I have looked here for multiple hours to get my answer but without luck. I have tried:

m1 <-nls(b((data$x-0)*(1-exp(d*(data$x-100)))), data = data, start = list(b = 1, d = 0.1) but I get could not find function "b" and "d"

Upvotes: 0

Views: 189

Answers (1)

StupidWolf
StupidWolf

Reputation: 46908

In R , you needa have a "*" to multiply a variable by something else for example :

set.seed(222)
data = data.frame(x=runif(100,100,110))
b = 0.7
d = 0.1
data$y = with(data,b * x * (1-exp(d*(x-100))))+ rnorm(100,5,1)

m1 <-nls(y ~ b*x*(1-exp(d*(x-100))), 
data = data, start = list(b = 1, d = 1))

        Nonlinear regression model
  model: y ~ b * x * (1 - exp(d * (x - 100)))
   data: data
     b      d 
0.4334 0.1311 
 residual sum-of-squares: 481.9

We can plot it:

f = function(x,b,d){ b*x*(1-exp(d*(x-100))) }
plot(data)
linspace = seq(100,110,by=0.5)
lines(linspace,f(linspace,coefficients(m1)["b"],coefficients(m1)["d"]),col="blue")

enter image description here

Upvotes: 1

Related Questions