On Fri, 11 Jun 2010, Christos Argyropoulos wrote:
>
> Goodmorning,
>
> This is a documentation related question about the B-spline function in R.
> In the help file it is stated that:
>
> "df degrees of freedom; one can specify df rather than knots; bs()
then
> chooses df-degree-1 knots at suitable quantiles of x (which will ignore
> missing values)."
Not in R 2.11.1 where help("bs") says:
df degrees of freedom; one can specify df rather than knots; bs()
then chooses df-degree (minus one if there is an intercept)
knots at suitable quantiles of x (which will ignore missing
values).
>
> So if one were to specify a spline with 6 degrees of freedom (and no
intercept) then a basis with 6-3-1 =2 internal knots should be created. However
this is not what happens:
>
>> library(splines)
>> s1<-bs(women$height, df = 6,deg=3)
>> s2<-bs(women$height, df = 6,deg=2)
>>
>> attributes(s1)$knots
> 25% 50% 75%
> 61.5 65.0 68.5
>> attributes(s2)$knots
> 20% 40% 60% 80%
> 60.8 63.6 66.4 69.2
>>
>
> i.e. basis is created with an extra knot i.e. bs() chooses df-degree
internal knots
>
> The documentation of "ns" states that: " .... ns() then
chooses df - 1 -
> intercept knots ..." suggesting that the spline functions create the
> basis with df-degree internal knots if no intercept is specified but
> df-degree-1 internal knots if the caller explicitly asks for an
> intercept.
If you knew that 1 - TRUE == 0, then you know that is what it says.
>
>> s1<-bs(women$height, df = 6,deg=3,intercept=T)
>> s2<-bs(women$height, df = 6,deg=2,intercept=T)
>>
>> attributes(s1)$knots
> 33.33333% 66.66667%
> 62.66667 67.33333
>> attributes(s2)$knots
> 25% 50% 75%
> 61.5 65.0 68.5
>
>
> Is it possible to change the documentation of these functions to reflect
> their actual behaviour. For example something like the following: "df
> degrees of freedom; one can specify df rather than knots; bs() then
> chooses df-degree-1 knots at suitable quantiles of x (which will ignore
> missing values) if the intercept argument is TRUE and df-degree if
> intercept=FALSE."
R-devel is where you post stuff like this, but be sure to refer to current
versions to avoid being flamed for non-compliance with posting guidelines.
HTH,
Chuck
>
>
> Christos Argyropoulos
>
> _________________________________________________________________
> Hotmail: Trusted email with Microsoft?s powerful SPAM protection.
>
> ______________________________________________
> 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