[R] Specify a correct formula in R for Piecewise Linear Functions?

vmuggeo at dssm.unipa.it vmuggeo at dssm.unipa.it
Wed Jan 2 12:45:58 CET 2008


> On Tue, 1 Jan 2008, zhijie zhang wrote:
>
>> Dear all,
>>  I have two variables, y and x. It seems that the relationship between
>> them
>> is Piecewise Linear Functions. The cutpoint is 20.

Have a look to the package segmented if you don't know exactly the
breakpoint and you are interested in estimating it,

all the best,
vito

That is, when x<20,
>> there
>> is a linear relationship between y and x; while x>=20, there is another
>> different linear relationship between them.
>> How can i specify their relationships in R correctly?
>> # glm(y~I(x<20)+I(x>=20),family = binomial, data = point)  something
>> like
>> this?
>
> Try this:
>
>> library(splines)
>> fit <- glm( y ~ bs( x, deg=1, knots=20 ), family=binomial)
>
> HTH,
>
> Chuck
>
>
>> Thanks a lot.
>>
>> --
>> With Kind Regards,
>>
>> oooO:::::::::
>> (..):::::::::
>> :\.(:::Oooo::
>> ::\_)::(..)::
>> :::::::)./:::
>> ::::::(_/::::
>> :::::::::::::
>> [***********************************************************************]
>> Zhi Jie,Zhang ,PHD
>> Tel:+86-21-54237149
>> Dept. of Epidemiology,School of Public Health,Fudan University
>> Address:No. 138 Yi Xue Yuan Road,Shanghai,China
>> Postcode:200032
>> Email:epistat at gmail.com
>> Website: www.statABC.com
>> [***********************************************************************]
>> oooO:::::::::
>> (..):::::::::
>> :\.(:::Oooo::
>> ::\_)::(..)::
>> :::::::)./:::
>> ::::::(_/::::
>> :::::::::::::
>>
>> 	[[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> Charles C. Berry                            (858) 534-2098
>                                              Dept of Family/Preventive
> Medicine
> E mailto:cberry at tajo.ucsd.edu	            UC San Diego
> http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>




More information about the R-help mailing list