Error while executing nls in R - 'Arg' must be NULL or a Character vector

Asked

Viewed 65 times

4

When I use the command

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 regression, changed to MM

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

About the start values I’m using

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

As previously requested the output for > dput(head(data_Indice, 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 by exceeding the maximum number of iterations. Looking at some alternatives, the recommended solution was to include the command nls.control as an attribute of the method nls, the result, therefore, 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, executing the above command returns the following error:

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

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

  • 3
    1. na.omit(NA) does not make much sense, omit the only value passed to the function, see help("na.omit"). 2) Without a data set it is difficult to say why the error, please edit the question with the output of dput(head(dados_Indice, 20)) and the values of start. 3) In which package can we find the function expo.der? If it does not come from an external package, once again edit the question with your code, please.

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 argument na.omit(NA) is being passed to the parameter algorithm. 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 documentation of the function says that:

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 - and 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)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.