Displaying 20 results from an estimated 9000 matches similar to: "Lag vector of dates by vector of days"
2010 Jul 21
1
The opposite of "lag"
Hello!
I have a data frame A (below) with a grouping factor (group). I take
my DV and create the new, lagged DV by applying the function lag.it
(below). It works fine.
A <- data.frame(year=rep(c(1980:1984),3), group=
factor(sort(rep(1:3,5))), DV=c(rnorm(15)))
lag.it <- function(x) {
DV <- ts(x$DV, start = x$year[1])
idx <- seq(length = length(DV))
DVs <- cbind(DV, lag(DV,
2004 Oct 29
2
lag variable addition to data frame question
Hi,
I was wondering if there is a more efficient way of handling the following method of creating a lagged value in a data frame without using the recursive
'for(i in 1:n)' loop and without using as.ts
#Steps to creating a lag variable in a data frame 'my.dat.fr'
# with 275 columns, 2400 rows of numbers and factors . The #variable x is a factor of #with five different levels
the
2012 Jan 17
2
Using Aggregate() with FUN arguments, which require more than one input variables
Dear all,
I am trying to apply the aggregate() function to calculate correlations for
subsets of a dataframe. My argument x is supposed to consist of 2 numerical
vectors, which represent x and y for the cor() function.
The following error results when calling the aggregate function: Error in
FUN(X[[1L]], ...) : supply both 'x' and 'y' or a matrix-like 'x'. I think
the
2006 Nov 09
5
Voxee lag problems ?
Anyone having problems with voxee since last few days or is it just me ? In
peek hours i get LAGGED when i do a iax2 show peers or even 1000 ms latency
. Most of time it is 20 ms or so but when i start sending traffic to them
latency increases to 1000 ms or even LAGGED ( also shows high in peak time
even when no high latency ). No problems with any other provider . Anyone
else having same problem
2006 Mar 02
1
CCF and Lag questions
I am new to R and new to time series modeling.
I have a set of variables (var1, var2, var3, var4, var5) for which I have
historical yearly data.
I am trying to use this data to produce a prediction of var1, 3 years into
the future.
I have a few basic questions:
1) I am able to read in my data, and convert it to a time series format
using 'ts.'
data_ts <- ts(data, start = 1988, end =
2005 Mar 05
4
How to use "lag"?
Is it possible to fit a lagged regression, "y[t]=b0+b1*x[t-1]+e",
using the function "lag"? If so, how? If not, of what use is the
function "lag"? I get the same answer from y~x as y~lag(x), whether
using lm or arima. I found it using y~c(NA, x[-length(x)])). Consider
the following:
> set.seed(1)
> x <- rep(c(rep(0, 4), 9), len=9)
> y <-
2012 Jan 10
1
Lag() and lag()
lag is a very confusing function
i try to plot lag(x,-h) and y , the results are the same figures for all the
h lags.
then i saw online people use lag(x,-h) as xreg in arima
that won't work in my eyes if lag function is consistent, isnce it returns
the same value for all the lags
i don't know in which occasion people will use this function
besides I suppose Lag(x,h) is the same as
2012 Jul 25
3
lagged variables
hi guys,
i have some trouble in creating lagged variables to use as external
regressors.
i'm trying to use lag(x) but it gives me as result the same time series (x),
adding this part at the end:
attr(,"tsp")
[1] 0 2323 1
where do i wrong?are there other functions to be used?
thanks
sara
--
View this message in context:
2005 Oct 31
1
how to optimise cross-correlation plot to study time lag between time-series?
Dear R-help,
How could a cross-correlation plot be optimized such that the relationship
between seasonal time-series can be studied?
We are working with strong seasonal time-series and derived a
cross-correlation plot to study the relationship between time-series. The
seasonal variation however strongly influences the cross-correlation plot
and the plot seems to be ?rather? symmetrical (max
2004 Mar 08
1
Am failing on making lagged residual after regression
Folks,
I'm most confused in trying to do something that (I thought) out to be
mainstream and straightforward R. :-) Could you please help?
I am doing an ordinary linear regression. My goal is: After a
regression, to make residuals, and make a new variable which is the
lagged residuals (lagged by 1). I will use this variable in a 2nd
stage regression (for an error-correcting model).
This
2012 Nov 15
3
Can you have a by variable in Lag function as in SAS
Hello,
I want to use lag on a time variable but I have to take date into
consideration ie I don't want days to overlap ie:
I don't want my first time of today to match my last time of yeterday.
In SAS I would use :
data x;
set y;
by date tim;
previous=lag(tim);
if first.date then
do;
previous=.;
end;
run;
How can I do something similar in R? I can't find
2007 Dec 13
1
creating lagged variables
Hi all.
I'm looking for robust ways of building lagged variables in a dataset
with multiple individuals.
Consider a dataset with variables like the following:
##
set.seed(123)
d <- data.frame(id = rep(1:2, each=3), time=rep(1:3, 2), value=rnorm(6))
##
>d
id time value
1 1 1 -0.56047565
2 1 2 -0.23017749
3 1 3 1.55870831
4 2 1 0.07050839
5 2 2 0.12928774
6
2018 Aug 23
7
conflicted: an alternative conflict resolution strategy
Hi all,
I?d love to get your feedback on the conflicted package, which provides an
alternative strategy for resolving ambiugous function names (i.e. when
multiple packages provide identically named functions). conflicted 0.1.0
is already on CRAN, but I?m currently preparing a revision
(<https://github.com/r-lib/conflicted>), and looking for feedback.
As you are no doubt aware, R?s default
2003 May 29
2
Newbie trying to Lag Variables in a regression
Perhaps I am making this too hard, but how does one regress y(t) on a
constant, x(t-1) and y(t-1)? I've tried the manuals and until I get
Dalgaard's book (just ordered on Amazon), I am stuck!
Thanks to all in advance for your patience and consideration.
2012 Oct 11
2
ccf(x,y) vs. cor() of x and lagged values of y
Hi
I'm computing the correlation between two time-series x_t and y_t-1
(time-series lagged using the lag(y,-1) function) using the cor() function
and the returned value is different from the value of ccf() function at the
same lag. Any ideas why this is so?
Thanks in advance for any hints.
Mihnea
[[alternative HTML version deleted]]
2011 Nov 30
2
forecasting linear regression from lagged variable
I'm currently working with some time series data with the xts package, and
would like to generate a forecast 12 periods into the future. There are
limited observations, so I am unable to use an ARIMA model for the forecast.
Here's the regression setup, after converting everything from zoo objects to
vectors.
hire.total.lag1 <- lag(hire.total, lag=-1, na.pad=TRUE)
lm.model <-
2011 Aug 04
2
Efficient way of creating a shifted (lagged) variable?
Hello!
I have a data set:
set.seed(123)
y<-data.frame(week=seq(as.Date("2010-01-03"), as.Date("2011-01-31"),by="week"))
y$var1<-c(1,2,3,round(rnorm(54),1))
y$var2<-c(10,20,30,round(rnorm(54),1))
# All I need is to create lagged variables for var1 and var2. I looked
around a bit and found several ways of doing it. They all seem quite
complicated - while in
2005 Aug 13
1
How to make a lagged variable in panel data?
Suppose we observe N individuals, for each of which we have a
time-series. How do we correctly create a lagged value of the
time-series variable?
As an example, suppose I create:
A <- data.frame(year=rep(c(1980:1984),3),
person= factor(sort(rep(1:3,5))),
wage=c(rnorm(15)))
> A
year person wage
1 1980 1 0.17923212
2 1981
2005 Oct 15
2
regression using a lagged dependent variable as explanatory variable
Hi,
I would like to regress y (dependent variable) on x (independent variable) and y(-1).
I have create the y(-1) variable in this way: ly<-lag(y, -1)
Now if I do the following regression lm (y ~ x + ly) the results I obtain are not correct.
Can someone tell me the code to use in R in order to perform a regression using as explanatory variable a lagged dependent variable?
My best regards,
2008 Aug 18
2
Using lag
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