[R] Intercept in model formulae.

Jesus Frias Jesus.Frias at dit.ie
Wed Sep 4 16:08:05 CEST 2002


Hi David,

	Linear models with breakpoints can be quite tricky. There is a whole
chapter (9) of "Nonlinear Regression" from Seber and Wild dedicated to it.

	One brute option you could use is optim or nls to estimate the parameters
in your model.

>y.t<-y+rnorm(0,sd=0.2) # problems of a nonlinear estimation algorithm with
artifical data):

>
temp.nls<-nls(y.t~x*a*(x<=10)+x*b*(x>10)+c*(x>10),start=list(a=1,b=0.5,c=5))
> temp.nls
Nonlinear regression model
  model:  y.t ~ x * a * (x <= 10) + x * b * (x > 10) + c * (x > 10)
   data:  parent.frame
        a         b         c
0.9891968 0.5200410 4.7873328
 residual sum-of-squares:  0.9848274



best regards,

IOsu

Lecturer Food Chemical Analysis
Dublin Institute of Technology
School of Food Science and Environmental Health
Cathal Bruha St., Dublin 1

-----Original Message-----
From: owner-r-help at stat.math.ethz.ch
[mailto:owner-r-help at stat.math.ethz.ch]On Behalf Of David Orme
Sent: 04 September 2002 10:54
To: r-help at stat.math.ethz.ch
Subject: [R] Intercept in model formulae.


Hi,

I'm trying to create a linear model for a dataset that has a breakpoint e.g.

# dummy dataset
x <- 1:20
y <- c(1:10,seq(10.5,15,0.5))
plot(x,y)

I've modelled this using the following formula:

temp <- lm(y ~ x*(x<=10)+x*(x>10)) # where 10 is the breakpoint

I want to be able to omit the intercept (i.e. force the line through
zero) from the first of these segments (x<=10) so that I'm only
estimating one intercept and two slopes. I've tried including -1 in
the formula, folllowing the lm(y ~ x -1) syntax  to omit the
intercept from lm(y ~x) but the linear model still returns an
estimate of the intercept of the first segment. I can't work out what
the syntax for the formula should be. Is it possible in one step or
do I have to fit the two lines as separate models on subsets of the
data?

Any suggestions?

Thanks in advance,

David Orme


>  R.version
          _
platform ppc-apple-macos
arch     ppc
os       MacOS
system   ppc, MacOS
status
major    1
minor    5.0
year     2002
month    04
day      29
language R
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._

--
This message has been scanned for viruses by the DIT
Computer Centre MailScanner Service , and is
believed to be clean.


-- 
This message has been scanned for viruses by the DIT 
Computer Centre MailScanner Service , and is
believed to be clean.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list