Displaying 20 results from an estimated 6000 matches similar to: "lag variable addition to data frame question"
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 <-
2012 Mar 19
1
Lag based on Date objects with non-consecutive values
Hello all,
I need to figure out a way to lag a variable in by a number of days
without using the zoo package. I need to use a remote R connection
that doesn't have the zoo package installed and is unwilling to do so.
So that is, I want a function where I can specify the number of days
to lag a variable against a Date formatted column. That is relatively
easy to do. The problem arises when I
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
2008 Aug 11
3
Peoblem with nls and try
Hello,
I can`t figure out how can increase the velocity of the fitting data by nls.
I have a long data .csv
I want to read evry time the first colunm to the other colunm and analisy with thata tools
setwd("C:/dati")
a<-read.table("Normalizzazione.csv", sep=",", dec=".", header=F)
for (i in 1:dim(a[[2]]]) {
#preparazione dati da analizzare
2008 May 22
1
How to account for autoregressive terms?
Hi,
how to estimate a the following model in R:
y(t)=beta0+beta1*x1(t)+beta2*x2(t)+...+beta5*x5(t)+beta6*y(t-1)+beta7*y(t-2)+beta8*y(t-3)
1) using "lm" :
dates <- as.Date(data.df[,1])
selection<-which(dates>=as.Date("1986-1-1") & dates<=as.Date("2007-12-31"))
dep <- ts(data.df[selection,c("dep")])
indep.ret1
2012 Feb 03
1
A question on Unit Root Test using "urca" toolbox
Hello,
I have a question on unit root test with urca toolbox.
First, to run a unit root test with lags selected by BIC, I type:
> CPILD4UR<-ur.df(x1$CPILD4[5:nr1], type ="drift", lags=12, selectlags ="BIC")
> summary(CPILD4UR)
The results indicate that the optimal lags selected by BIC is 4.
Then I run the same unit root test with drift and 4 lags:
2012 Dec 03
2
How to rename the columns of as.table
Hello guys .. I would like to have some help about as.table .
I made a table with the autocorrelations of the returns whit 10 lags and i
get this :
autocorrelazione2 <- as.table(c((cor(r2[-1151,],lag(r2))),(cor(r2[-
c(1151,1150),],lag(r2, k=2))),(cor(r2[- c(1151,1150,1149),],lag(r2,
k=3))),(cor(r2[- c(1151,1150,1149,1148),],lag(r2, k=4))),(cor(r2[-
c(1151,1150,1149,1148,1147),],lag(r2,
2008 Jan 31
1
Feature request: about lag(), which.min() and cat().
Hello
I'm only user of R and have many little knowledge in programming but I
permit to send you some whishes/suggestions for R.
which.min
like which(), which.min() should also include an argument arr.ind. Note
that one can have it with which(a==min(a), arr.ind=TRUE) but if there is
a reason to build a special function which.min, why not add also this
nice argument?
lag()
If one wants to
2018 Mar 25
3
Take average of previous weeks
Dear all,
I have weekly data by city (variable citycode). I would like to take the
average of the previous two, three, four weeks (without the current week)
of the variable called value.
This is what I have tried to compute the average of the two previous weeks;
df = df %>%
mutate(value.lag1 = lag(value, n = 1)) %>%
mutate(value .2.previous = rollapply(data = value.lag1,
2008 Jul 06
1
Different Autocorrelation using R and other softwares
Dear All,
Would like to ask the inconsistency in the autocorrelation from R with
SPSS/Minitab. I have tried a dataset x with 20 data (1-20) and ask R to give
the autocorrelation of different lags using the command < acf(x,
lag.max=100, type = "correlation"), However while SPSS and Minitab give the
same answers (0.85 for lag1), R gives 0.3688 which is much smaller.
Obviously, the
2008 Jan 17
1
acf lag1 value
Hi R,
I have doubt.
>x= c(4,5,6,3,2,4,5)
>acf(x,plot=F,lag.max=1)
Autocorrelations of series 'x', by lag
0 1
1.000 0.182
But if I actually calculate the autocorrelation at lag1 I get,
>cor(x[-1],x[-length(x)])
[1] 0.1921538
Even in excel I get 0.1921538 value. So, I want to know what the 'acf'
function is calculating here....
2009 Apr 09
1
arima on defined lags
Dear all,
The standard call to ARIMA in the base package such as
arima(y,c(5,0,0),include.mean=FALSE)
gives a full 5th order lag polynomial model with for example coeffs
Coefficients:
ar1 ar2 ar3 ar4 ar5
0.4715 0.067 -0.1772 0.0256 -0.2550
s.e. 0.1421 0.158 0.1569 0.1602 0.1469
Is it possible (I doubt it but am
2018 Mar 25
0
Take average of previous weeks
I am sure that this sort of thing has been asked and answered before,
so in case my suggestions don't work for you, just search the archives
a bit more.
I am also sure that it can be handled directly by numerous functions
in numerous packages, e.g. via time series methods or by calculating
running means of suitably shifted series.
However, as it seems to be a straightforward task, I'll
2018 Mar 26
1
Take average of previous weeks
Dear Bert,
Thank you very much.This works. I was wondering if the fact that I want to
create new variables (sorry for not stating that fact) makes any
difference? Thank you again.
Sincerely,
Milu
On Sun, Mar 25, 2018 at 10:05 PM, Bert Gunter <bgunter.4567 at gmail.com>
wrote:
> I am sure that this sort of thing has been asked and answered before,
> so in case my suggestions
2013 Apr 26
1
Regression coefficients
Hi all,
I have run a ridge regression as follows:
reg=lm.ridge(final$l~final$lag1+final$lag2+final$g+final$g+final$u,
lambda=seq(0,10,0.01))
Then I enter :
select(reg) and it returns: modified HKB estimator is 19.3409
modified L-W estimator is 36.18617
smallest value of GCV at 10
I think it means that it is
2002 Jun 20
1
Possible bug with glm.nb and starting values (PR#1695)
Full_Name: Ben Cooper
Version: 1.5.0
OS: linux
Submission from: (NULL) (134.174.187.90)
The help page for glm.nb (in MASS package) says that it takes "Any other
arguments for the glm() function except family"
One such argument is start "starting values for the parameters in the linear
predictor."
However, when called with starting values glm.nb returns:
Error in
2013 Apr 27
1
Selecting ridge regression coefficients for minimum GCV
Hi all,
I have run a ridge regression as follows:
reg=lm.ridge(final$l~final$lag1+final$lag2+final$g+final$u,
lambda=seq(0,10,0.01))
Then I enter :
select(reg) and it returns: modified HKB estimator is 19.3409
modified L-W estimator is 36.18617
smallest value of GCV at 10
I think it means that it is advisable to
2007 Jul 12
2
lead
Hi,
is there any function in R that shifts elements of a vector to the
opposite direction of what Lag() of the Hmisc package does? (something
like, Lag(x, shift = -1) )
Thanks
Zava
--------------------------------------------------------
This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}
2009 May 20
1
stationarity tests
How can I make sure the residual signal, after subtracting the trend extracted through some technique, is actually trend-free ?
I would greatly appreciate any suggestion about some Stationarity tests.
I'd like to make sure I have got the difference between ACF and PACF right.
In the following I am citing some definitions. I would appreciate your thoughts.
ACF(k) estimates the correlation
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,