[R] Predicting from an nls model

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jun 12 15:00:51 CEST 2008


To predict from Weight~alpha*Length^beta you need to specify Length, not 
Weight.  It is most likely finding Length from your workspace.

On Thu, 12 Jun 2008, Ranney, Steven wrote:

> I keep running up against the same error when I try to plot a line from a nls model.  The data is fisheries length/weight data.  Code follows:
>
> require(graphics)
> pow = nls(Weight~alpha*Length^beta, data=wae,
>      start=list(alpha=0.0000001, beta=3.0), trace=TRUE)
> predict(pow)
> plot(Weight~Length, data = wae, pch=19,
>     xlab="Length (mm)", ylab="Weight (g)",
>     xlim = c(150,1000), ylim = c(0, 10050))
> mod = seq(150, 1000)
> lines(mod, predict(pow, list(Weight = mod)))
>
> The error I get after I submit the final line is:
>
> Error in xy.coords(x, y) : 'x' and 'y' lengths differ
>
> Like my last post, I'm certain there's something simple I'm overlooking.  I've been able to get this to work on other data sets, but _how_ I've been able to get this to work, I'm unsure.
>
> Thanks for your help,
>
> SR
>
> Steven H. Ranney
> Graduate Research Assistant (Ph.D)
> USGS Montana Cooperative Fishery Research Unit
> Montana State University
> PO Box 173460
> Bozeman, MT 59717-3460
>
> phone: (406) 994-6643
> fax:   (406) 994-7479
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list