[R] Threshhold Models in gnlm

Eliot McIntire emcintire at forestry.umt.edu
Wed Jan 26 00:01:58 CET 2005


Hello,

I am interested in fitting a generalized nonlinear regression (gnlr) model  
with negative binomial errors.

I have found Jim Lindsay's package that will do gnlr, but I have having  
trouble with the particular model I am interested in fitting.

It is a threshhold model, where below a certain value of one of the  
parameters being fitted, the model changes.

Here is a sample:

Cones: is counts of number of cones on each tree
dt: is the residual energy of that tree (basically how many stored  
reserves that tree has)
The model is this: if dt is above some threshhold (c), then the number of  
cones will be a function of b and a and c, if dt is below that threshhold  
(c), then the number of cones will simply be b

# Does not work
   gnlr.T1 = gnlr(Cones, distribution="negative binomial",
         mu= ~ b + (dt >=c) * a * ( dt - c ),
         pmu= list(b=6.86, a=1.64, c=-3), pshape=0)  #, a = 1.5, c = -3)

I fit the same model using nls (obviously without the negative binomial  
errors), and it works fine.
# Does work
   nls.T1 = nls(Cones ~ b + (dt >=c) * a * ( dt - c ),
            start=list(b=20, c=3.1, a=2),
            control = nls.control(tol=0.001, minFactor=1e-020))

Does anybody know how to do this?  Perhaps using if statements in a  
function statement?

The data are below.

Thank you,
Eliot

#data
Cones = c(0,8,50,6,1,0,160,6,44,33,21,0,0,85,0,25,105,0,
56,2,72,13,3,14,0,1,0,51,2,41,37,7,0,0,32,0,
15,47,0,31,0,34,10,9,6,0,0,0,37,2,15,9,5,0,
2,17,0,0,14,0,61,0,27,31,23,29,0,0,0,27,3,119,
8,2,0,0,86,0,3,18,0,50,0,62,15,5,23,0,4,0,
29,1,16,7,2,0,1,28,0,0,5,0,9,0,27,26,11,44,
2,5,0,75,4,33,14,7,0,2,49,0,11,35,0,17,1,26,
9,3,54,0,0,0,44,2,24,31,7,0,0,29,0,0,73,0,
51,0,31,15,2,35,0,11,0,22,0,39,3,4,0,0,41,0,
11,23,0,105,0,3,16,9,22,1,12,0,53,1,5,3,3,0,
0,40,0,4,23,0,0,0,65,5,2,6,0,0,0,55,3,26,
13,2,0,0,32,0,1,18,0,41,0)

dt = c(-50.237,-17.241,7.756,-9.247,17.749,49.746,
82.743,-44.261,-17.264,-28.268,-28.271,-16.274,16.722,
49.719,-2.285,30.712,38.709,-33.295,-0.298,-23.302,
7.695,-5.828,-9.101,-1.418,-3.834,8.596,20.816,35.112,
0.01,15.011,-8.43,-27.856,-17.75,-1.026,15.497,-0.029,
16.546,18.361,-11.723,5.228,-8.76,8.34,-1.193,-3.456,
-4.63,-2.736,5.205,13.172,21.257,-7.357,-0.832,-7.344,
-8.068,-5.238,1.948,7.07,-2.198,6.817,17.736,15.932,29.048,
-17.867,-2.762,9.729,-5.244,-11.358,-22.671,-4.238,14.883,
34.932,29.377,48.799,-47.257,-32.246,-11.604,10.52,32.168,
-32.614,-11.782,5.707,7.855,27.657,-2.883,16.239,1.918,
-2.359,3.036,-9.903,-0.183,5.193,14.244,-5.988,1.469,
-6.42,-5.687,-0.391,6.351,11.647,-10.362,-4.535,1.261,
1.92,7.376,3.634,8.698,-1.171,-4.799,6.073,-16.571,
2.254,17.531,37.315,-18.277,-3.332,-17.946,-14.212,
-4.237,11.923,25.387,-8.708,5.778,8.971,-12.236,1.094,
-3.02,8.44,-3.727,3.031,15.64,-22.902,-7.596,7.558,22.454,
-7.072,5.143,-4.727,-21.505,-14.087,0.39,15.316,2.162,
19.401,38.466,-14.101,7.45,-20.829,3.111,2.435,-0.731,
9.002,-14.355,-2.79,-2.291,8.986,-2.214,8.369,-19.982,
-11.986,-4.465,7.368,20.032,-6.837,9.398,17.321,15.297,
37.977,-42.582,-16.325,-0.741,-2.164,2.845,-5.706,6.191,
6.545,18.313,-23.571,-14.022,-8.946,-2.247,4.089,12.807,
21.207,-10.322,-1.388,4.372,-8.341,2.285,13.265,24.619,
-9.316,-6.736,-0.483,2.383,11.803,21.715,32.755,-9.863,
0.17,-12.836,-13.572,-4.425,5.919,15.819,-6.363,3.732,
13.005,5.14,15.17,-15.871)



-- 
Eliot McIntire
NSERC Post Doctoral Fellow
Department of Ecosystems and Conservation Science
College of Forestry and Conservation
University of Montana, Missoula, MT 59812
406-243-5239
fax: 406-243-4557
emcintire at forestry.umt.edu




More information about the R-help mailing list