[R] Using lag

Nestor Arguea narguea at ihmc.us
Mon Aug 18 17:28:23 CEST 2008


Robin,

You can use Lag (upper case "L") from package Hmisc.

Nestor Arguea
On Aug 18, 2008, at 8:40 AM, Williams, Robin wrote:

> Dear all,
>  I am having difficulties using the seemingly-simple function lag.
>  I have a dataframe with several weather variables (maxitemp,
> windspeed, rainfall etc), and the response variable (admissions). The
> dataset is fairly large (1530 observations). I simply want to model  
> the
> response against a lag of a couple of the explanatory variables, say
> maxitemp and rainfall. I would like to look at lagtimes of 4 days,  
> i.e.
> 4 observations. My dataframe is called allengland.
>  I thought I would be able to do something like:
> model1 <- lm(admissions~lag(maxitemp,4),data=allengland)
>  but when I compare this to a lag of 0 I have exactly the same output,
> so I am clearly doing something wrong.
>  Could someone please point me in the right direction? The example in
> the help for lag is not very detailed for what I need to do.
> Thanks in advance,
>
> Robin Williams
> Met Office summer intern - Health Forecasting
> robin.williams at metoffice.gov.uk
>
>
>
> 	[[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.
>
>

-------------------------------------------------------
Nestor M. Arguea, Chair
Associate Professor, Economics
Department of Marketing and Economics
University of West Florida
Pensacola, FL 32514
Phone: 850-474-3071
Fax: 850-474-3069
e-mail: narguea at uwf.edu



More information about the R-help mailing list