From P.Dalgaard at biostat.ku.dk  Wed Feb 25 14:41:34 2009
From: P.Dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Wed, 25 Feb 2009 14:41:34 +0100
Subject: [Rd] [R] length 1 offset in glm (& lm)
In-Reply-To: <alpine.OSX.1.00.0902251316340.70608@tystie.local>
References: <49A53E1B.4090004@warwick.ac.uk>	<alpine.OSX.1.00.0902251252010.70608@tystie.local>	<20090225141510.vzf0j0passoso4sw@imp.inserm.fr>
	<alpine.OSX.1.00.0902251316340.70608@tystie.local>
Message-ID: <49A54A8E.3000904@biostat.ku.dk>

Prof Brian Ripley wrote:
> On Wed, 25 Feb 2009, Kenneth Knoblauch wrote:
> 
>> Hi
>>
>> Quoting Prof Brian Ripley <ripley at stats.ox.ac.uk>:
>>
>>> On Wed, 25 Feb 2009, Heather Turner wrote:
>>>
>>>> This post about length 1 offsets on R help seems to have been ignored
>>>> (sorry deleted original email - is there a way to continue thread in
>>>> this case?)
>>>>
>>>> https://stat.ethz.ch/pipermail/r-help/2009-February/189352.html
>>>
>>> So let's be clear: this was the 'offset' argument' and not the offset()
>>> function as you refer to below.
>>
>> It occurs for both
> 
> Yes (I knew). but no one (AFAICS) said the function allows length-1
> arguments: Heather is raising the possibility that it should as new
> functionality, I believe.

Makes sense to have them consistent though, and we we do advertise that
recycling works for the argument. Looks like this could be fixed at the
level of model.frame.default, but the sticky bit is where to get the
repeat count in case the formula is something like "~-1". I don't quite
fathom the current rules:

> model.frame(~-1,offset=1)
  (offset)
1        1
> model.frame(~-1,offset=1,data=aq)
  (offset)
1        1
> model.frame(Ozone~-1,offset=1,data=aq)
Error in model.frame.default(Ozone ~ -1, offset = 1, data = aq) :
  variable lengths differ (found for '(offset)')
> model.frame(Ozone~-1,data=aq)
  Ozone
1    41
2    36
3    12
4    18
6    28
> model.frame(~-1,data=aq)
data frame with 0 columns and 6 rows

> foo <- 2:3
> model.frame(~foo-1,data=aq)
   foo
1    2
2    3
3 <NA>
4 <NA>
5 <NA>
6 <NA>
Warning message:
In format.data.frame(x, digits = digits, na.encode = FALSE) :
  corrupt data frame: columns will be truncated or padded with NAs
> foo <- 2
> model.frame(~foo-1,data=aq)
  foo
1   2




-- 
   O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



[Rd] [R] length 1 offset in glm (& lm)
Peter Dalgaard