0
$\begingroup$

I have created a data set to understand better an equation and apply it to predict behavior.

The equation is y = 10/(1+k*⌊((x/t)^s)⌋).

To create the data set and see if it is working properly, I did the following:

# creating the floor function f(x)
f = function(x) {
  10/(1+1.5*(floor((x/2.5)^0.7)))
}

# specifying the domain of f(x)
x = seq(0, 100, length.out = 50) # x contains 50 points between 0 and 100

library(ggplot2)
# creating a data frame that contains x and f(x)
dat = data.frame(x = x, y = f(x))
p = ggplot(dat, aes(x = x, y = y)) + 
  geom_step() # geom_step creates a stairs plot
p

# adding points to the plot
p + geom_point()

I got this result, which is what I expect from it

Then, I wanted to check a regression analysis over this data set using the following function:

#See the regression

# imports library
library(minpack.lm)

start_values <- c(k=1, s=0.3, t=2)
fit <- nls(dat$y ~ 10/(1+k*(floor((dat$x/t)^s))),
           data = dat,
           algorithm = "port",
        start = start_values,
        control = nls.control(maxiter = 1000))
summary(fit)

But I get the following error:

Error in nlsModel(formula, mf, start, wts, upper, scaleOffset = scOff, : singular gradient matrix at initial parameter estimates

What should I do to avoid it? or which analysis should I perform then? I'm not an expert on stats.

Thanks for your help!

$\endgroup$

1 Answer 1

0
$\begingroup$

The problem is that the package you are using (minpack.lm) implements a version of the Levenberg-Marquardt algorithm, which requires gradients. Your function f is nondifferentiable at the values of $x$ where the vertical steps occur.

Possible workarounds include looking for a least-squares algorithm that works with nondifferentiable / nonconvex objective functions, or perhaps settling for a heuristic that produces a "reasonable" but not optimal fit.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.