[R] lines() warning message

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Jul 4 00:34:17 CEST 2008


Ranney, Steven wrote:
> Hmm.  After checking my data, both the Spawner and Mtempcv columns are of equal lengths.  While I could be wrong, recycling doesn't seem to be the issue.  
>   
Notice that you have two "Spawner": One in the data, and one in newdata. 
These are probably not of the same length.

> As a relatively new user of R, I tried to adjust the newdata= issue by adding Mtempcv to the newdata= call (i.e., predict(mod2, list(Spawner=mod2a, Mtempcv=mod2a)).  This eliminated the "longer object length is not a multiple..." warning message, but the plot produces only a flat line at 0 on the y axis.
>   
Well, it would, if mod2a is much larger than the Mtempcv from your data, 
and the coefficient is negative. How about predict(mod2, 
newdata=data.frame(Spawner=mod2a, Mtempcv=0.3)) ?
>
> -----Original Message-----
> From: Peter Dalgaard [mailto:p.dalgaard at biostat.ku.dk]
> Sent: Thu 7/3/2008 3:07 PM
> To: Ranney, Steven
> Cc: r-help at r-project.org
> Subject: Re: [R] lines() warning message
>  
> Ranney, Steven wrote:
>   
>> I have data that looks like
>>
>> Year,Recruit,Spawner,Mtempcv
>> 1958,4532,775,0.24125
>> 1959,22996,2310,0.16319
>> 1960,628,2990,0.46056
>> 1961,879,1400,0.33028
>> 1962,14747,1130,0.22618
>> 1963,13205,790,0.20596
>> 1964,31793,1195,0.19229
>> 1965,10621,981,0.20363
>> 1966,22271,870,0.3452
>> 1967,8736,1104,0.27511
>> 1968,8761,883,0.10884
>> 1969,18885,1421,0.17799
>> 1970,10098,1198,0.2106
>> 1971,3394,760,0.22098
>> 1972,1697,1354,0.39461
>> 1973,25159,1308,0.19696
>> [truncated]
>>
>> with program
>>
>> #Ricker Curve
>> mod2=nls(Recruit~(Spawner*exp((delta+echo*Spawner)+(foxtrot*Mtempcv))), data=box48,
>>     start=list(delta=4, echo=0, foxtrot=-7), trace=TRUE)
>> plot(Recruit~Spawner, data=box48, pch=19)
>> mod2a=seq(369, 3000)
>> lines(mod2a, predict(mod2, list(Spawner=mod2a)), col="red", lty=2)
>>
>> R has no problem finding a solution to the nls() model (only 7 iterations are needed), but when I try to plot the line on the requested plot, I get the warning message "Warning message:
>> In (delta + echo * Spawner) + (foxtrot * Mtempcv) :
>>   longer object length is not a multiple of shorter object length."
>>
>> R tries to plot the line, but it appears as just a mess of vertical lines that get more dense where (I would imagine) the actual line is to go.  Any ideas what may be causing this issue?
>>
>>   
>>     
> Hmm,,, The predict() call looks dodgy. The model depends on Spawner AND 
> Mtempcv, but you're only giving the former in the newdata= part. So a 
> good guess that one of them is recycled to the length of the other.
>
>   


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-help mailing list