Error while executing method nls in R - 'arg' must be NULL or a character vector

4

When I use the

n0 <- nls(Y~expo.der(x, A, B, C), data=dados_Indice, start=start, na.omit(NA), trace = TRUE) 

expo.der is the name of the created function that defines the formula used in the regression, I changed it to MM

MM <- deriv3(~(A*x/(B+x))+C,c("A", "B", "C"),function(x, A, B, C) NULL)

On the start values I'm using

             (A)0.9707976, (B)14.50896 e (C) 0.02920242

As previously requested output to > dput (head (index_data, 20)) is

structure(list(Y = c(0.504968267320704, 0.580320008623638, 0.591987263077176, 
0.507128952150783, 0.471443542762971, 0.487690808524229, 0.550025947056627, 
0.517020993324232, 0.649271477040753, 0.543409645706519, 0.476085216626585, 
0.420887866612052, 0.587785676649722, 0.546330880659742, 0.598972408502253, 
0.60582105500102, 0.537834815210853, 0.535468008413421, 0.532758019489451, 
0.471561274553937), x = c(20, 20, 20, 20, 20, 20, 20, 20, 20, 
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20)), .Names = c("Y", 
"x"), row.names = c(NA, 20L), class = "data.frame")

The algorithm returns an error because it exceeds the maximum number of iterations. Querying some alternatives, the recommended solution was to include the nls.control command as an attribute of the nls method, so the result was the command below

n0 <- nls(Y~MM(x, A, B, C), data=dados_Indice, start=start, control=nls.control(maxiter = 200, tol = 1e-05, minFactor = (1/2)^30), trace = TRUE, na.omit(NA))

However, after these changes, when you run the above command, it returns the following error:

Error in match.arg(algorithm) : 'arg' must be NULL or a character vector

Why is this error displayed? And what can I do to bypass it by running the nls function, according to the established control?

    
asked by anonymous 18.09.2018 / 19:27

1 answer

2

On your last code call:

n0 <- nls(Y~MM(x, A, B, C), data = dados_Indice, start = start, 
          control = nls.control(maxiter = 200, tol = 1e-05, minFactor = (1/2)^30), 
          trace = TRUE, na.omit(NA))

The na.omit(NA) argument is being passed to the algorithm parameter. That is, your code is equivalent to running:

n0 <- nls(Y~MM(x, A, B, C), data = dados_Indice, start = start, 
          control = nls.control(maxiter = 200, tol = 1e-05, minFactor = (1/2)^30), 
          trace = TRUE, algorithm = na.omit(NA))

On the other hand the function documentation says:

algorithm
character string specifying the algorithm to use. The default algorithm is a Gauss-Newton algorithm. Other possible values are "plinear" for the Golub-Pereyra algorithm for partially linear least-squares models and "port" for the 'nl2sol' algorithm from the Port library - see the references. Can be abbreviated.

That is, this argument must be a string - not a logical(0) as is the case with na.omit(NA) .

Finally, to correct the problem, just remove the na.omit(NA) of the function call:

n0 <- nls(Y~MM(x, A, B, C), data = dados_Indice, start = start, 
          control = nls.control(maxiter = 200, tol = 1e-05, minFactor = (1/2)^30), 
          trace = TRUE)
    
19.09.2018 / 00:13