[R] NA's in segmented

T.D.Rudolph prairie.picker at gmail.com
Sat Oct 4 00:44:08 CEST 2008


I am trying to fit a very simple broken stick model using the package
"segmented" but I have hit a roadblock. 

> str(data)
'data.frame':   18 obs. of  2 variables:
 $ Bin   : num  0.25 0.75 1.25 1.75 2.25 2.75 3.25 3.75 4.25 4.75 ...
 $ LnFREQ: num  5.06 4.23 3.50 3.47 2.83 ...
 
I fit the lm easily:
> fit.lm<-lm(LnFREQ~Bin, data=id07)

But I keep getting an error message:
> fit.seg<-segmented(fit.glm, seg.Z=~Bin, psi=6)
Error in cbind(XREG, U, V) : 
  number of rows of matrices must match (see arg 2)
 
I think the problem is due to NA's in the Bin data, but there doesn't seem
to be an "na.action" for segmented ().  What is the best way to get around
this problem?  I would like to keep all Bin values in the output for
continuity.  Data below....
 
Tyler

> data
    Bin    LnFREQ
1  0.25 5.0562458
2  0.75 4.2341065
3  1.25 3.4965076
4  1.75 3.4657359
5  2.25 2.8332133
6  2.75 2.9444390
7  3.25 2.4849066
8  3.75 1.3862944
9  4.25 1.7917595
10 4.75 1.3862944
11 5.25 0.6931472
12 5.75 1.0986123
13 6.25 0.0000000
14 6.75 0.0000000
15 7.25        NA
16 7.75 0.0000000
17 8.25 0.0000000
18 8.75        NA
 
> summary(fit.glm)
Call:
glm(formula = LnFREQ ~ Bin, data = id07, na.action = na.omit)
Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-0.74139  -0.22999   0.01065   0.21245   0.72684  
Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  4.50646    0.21088   21.37 4.37e-12 ***
Bin         -0.63434    0.04467  -14.20 1.05e-09 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
(Dispersion parameter for gaussian family taken to be 0.1844898)
    Null deviance: 39.7785  on 15  degrees of freedom
Residual deviance:  2.5829  on 14  degrees of freedom
  (2 observations deleted due to missingness)
AIC: 22.227
Number of Fisher Scoring iterations: 2
-- 
View this message in context: http://www.nabble.com/NA%27s-in-segmented-tp19806985p19806985.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list