[R] How using the weights argument in nls2?

Ivan Allaman ivanalaman at yahoo.com.br
Thu Sep 2 17:09:25 CEST 2010


Good morning gentlemen!

How using a weighted model in nls2? Values with the nls are logical since
values with nls2 are not. I believe that this discrepancy is due to I did
not include the weights argument in nls2.

Here's an example:

MOISTURE <- c(28.41640,  28.47340,  29.05821,  28.52201,  30.92055, 
31.07901,  31.35840, 31.69617,  32.07168,  31.87296,  31.35525,  32.66118, 
33.23385,  32.72256,
32.57929,  32.12674,  52.35225,  52.77275,  64.90770,  64.90770,  85.23800,
84.43300,  68.96560,  68.41395,  70.82880,  71.18400,  96.13240,  96.07920,
95.35160,  94.71660,  87.59190,  88.63250,  89.78760,  90.17820, 88.46160,
87.10860, 94.86660,  94.51830,  75.79000,  76.98780, 144.70950, 143.88950,
111.58620, 112.71510, 120.85300, 121.43100, 116.34840, 114.87420, 195.35040,
191.36040, 265.35220, 267.25450, 227.13700, 228.78000, 238.37120, 242.70700,
299.54890, 291.04110, 220.09920, 219.82650, 236.79150, 243.70710, 208.79880,
208.12260, 417.21420, 429.59480, 360.91080, 371.66400, 357.72520, 360.53640,
383.82600, 383.82600, 434.02700, 432.57500, 440.56260, 438.32340, 468.69600,
469.82140, 497.93680, 497.17010)

YEARS <-  rep(c(86,109, 132, 158, 184, 220, 254, 276, 310,
337),c(8,8,8,8,8,8,8,8,8,8))

VARIANCE <- c(2.0879048 ,   2.0879048,    2.0879048,    2.0879048,   
2.0879048,
 2.0879048,    2.0879048,    2.0879048,    0.3442724,    0.3442724,
0.3442724,    0.3442724,    0.3442724,    0.3442724,   0.3442724,
0.3442724,  151.9481710,  151.9481710,  151.9481710,  151.9481710,
151.9481710,  151.9481710,  151.9481710,  151.9481710,  115.3208995,
115.3208995,  115.3208995,  115.3208995,  115.3208995,  115.3208995,
115.3208995,  115.3208995,   51.9965027,   51.9965027,   51.9965027,
51.9965027,   51.9965027,   51.9965027,  51.9965027,   51.9965027,
180.0496045, 180.0496045,  180.0496045,  180.0496045,  180.0496045,
180.0496045,  180.0496045,  180.0496045,  791.3223240,  791.3223240,
791.3223240,  791.3223240,  791.3223240,  791.3223240,  791.3223240,
791.3223240, 1280.0179973, 1280.0179973, 1280.0179973, 1280.0179973,
1280.0179973, 1280.0179973, 1280.0179973, 1280.0179973,  728.9582154,
728.9582154,  728.9582154,  728.9582154,  728.9582154,  728.9582154,
728.9582154,  728.9582154,  752.4591144,  752.4591144,  752.4591144,
752.4591144,  752.4591144,  752.4591144,  752.4591144,  752.4591144)

test <- data.frame(YEARS,MOISTURE,VARIANCE)

mod.nls <- nls(MOISTURE ~ A/(1+B*exp(-k*YEARS)),
	data = test, 
	weights = 1/VARIANCE,
	start = list(A=1500, B=200, k=0.03345),
	control=list(maxiter = 500),
	trace=TRUE)
summary(mod.nls)

Following the example of pdf!

st1 <- expand.grid(A = seq(0, 2000, len = 10),
B = seq(0, 500, len = 10), k = seq(-1, 10, len = 10))
st1

mod.nls2 <-nls2(MOISTURE ~ A/(1+B*exp(-k*YEARS)),
	data = test, 
	start = st1,
        algorithm="brute-force")
mod.nls2

I appreciate everyone's attention.
-- 
View this message in context: http://r.789695.n4.nabble.com/How-using-the-weights-argument-in-nls2-tp2524328p2524328.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list