# [R-sig-ME] question about NAs in nlsList

Sally A. Roman saroman at vims.edu
Wed Jan 27 15:51:18 CET 2016

```Hi - I am working through Mixed Effect Models in S & SPlus and Nonlinear Regression with R to learn how to model nonlinear mixed effects models.  I am looking to model fish selectivity with a mixed effect model based on previous selectivity analysis I have already completed following Arthur Millar's work using the SELECT method (https://www.stat.auckland.ac.nz/~millar/selectware/R/trawls/).

I have used the nlsList function in  the nlme package to get parameter estimates by group, StationID, for three different subsets of data.  The subsetted data are based on total catch: 50 total animals, 100 total animals and 200 total animals between the two gear types by StationID.  StationID is a tow where the two gears where towed in a pair.  For learning purposes, I randomly selected 10 StationIDs from each dataset to work with.  The maximum number of StationIDs is 463 depending on the dataset.

For each dataset, the nlsList function does not converge for all StationIDs.  The number of nonconverging models decreases with increased total catch.  For the dataset with 200 or more animals, only one model did not converge.  I have modified the control function in an effort to improve convergence.

For example:

nls200<-nlsList(prop~select_fun(q1,q2,a,b,p,Length),start=start_vec,
data=new.data_200,control=nls.control(maxiter=500,tol=1e-4,minFactor=1/5000,
printEval=T))

select_fun<-function(q1,q2,a,b,p,Length){
expo=exp(a+b*Length)
r=expo/(1+expo)
phi=q1*p*r/(q1*p*r+q2*(1-p))
}

a, b, and p are parameters estimated.  q1 and q2 are subsampling fractions. Length is the length class and prop is the proportion of animals at each length class caught in one gear to the total catch in both gears.

Then I am passing the nlsList model output  to nlme.

For example:
nls200.2<-nlme(nls200,random=p~1,control=nlmeControl(maxIter=50,
minScale=0.001,tolerance=1e-5,niterEM=25,msVerbose=T))

My question is how does nlme treat the NAs from the individual models?  The nlme.nlsList help page states:

na.action
a function that indicates what should happen when the data contain NAs. The default action (na.fail) causes nlme to print an error message and terminate if there are any incomplete observations.

I have changed the na.action to na.omit and na.exclude and the model returned the same parameter estimates for all three cases.  I also believe this na.action is in reference to the data used in the model (data=new.data) not the parameter estimates.

Mixed Effects Models in S & SPlus has an example in Chp 6 with one individual model that does not converge, but does not indicate how it is treated when passed to nlme.

Thanks for any insight.

If this email is a repeat sorry, I thought I emailed it to the list members yesterday, but sent it to  'r-sig-mixed-models-bounces at r-project.org' instead of
r-sig-mixed-models at r-project.org.

Sally Roman
Fisheries Specialist
Virginia Institute of Marine Science

Phone: 804-684-7165
Fax: 804-684-7161