Re: [R] Rolling regressions with sample extended one period at a time

2012-03-19 Thread pie'
hey, 

thnks a lot. I got exactly what I wanted.

--
View this message in context: 
http://r.789695.n4.nabble.com/Rolling-regressions-with-sample-extended-one-period-at-a-time-tp4470316p4485815.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Rolling regressions with sample extended one period at a time

2012-03-16 Thread pie'
hey, 


thanks for the hint. I too figured I'd have to write a for-loop. I have the
problem now of how to extract the single element of the fitted values
vector. For example, run 1 of the regression generates 80 fitted values, run
2 generates 81 fitted values, run 3 produces 82 fitted values and so on. I
need to extract the 80th, 81st, 82nd (all the last values generated at every
run) value into a separate vector. I know that lm (and glm) provides a
specific function for extracting  the predicted values but I don't know how
to use it inside a loop. Can you suggest anything?


P.

--
View this message in context: 
http://r.789695.n4.nabble.com/Rolling-regressions-with-sample-extended-one-period-at-a-time-tp4470316p4478016.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Rolling regressions with sample extended one period at a time

2012-03-16 Thread R. Michael Weylandt
You can use predict() just as you would anywhere else:

for(i in 80:100){
predict(lm(y ~ x, data = dats[1:i, ]), newdata = ???)
}

Michael

On Fri, Mar 16, 2012 at 8:12 AM, pie' tcpie...@yahoo.it wrote:
 hey,


 thanks for the hint. I too figured I'd have to write a for-loop. I have the
 problem now of how to extract the single element of the fitted values
 vector. For example, run 1 of the regression generates 80 fitted values, run
 2 generates 81 fitted values, run 3 produces 82 fitted values and so on. I
 need to extract the 80th, 81st, 82nd (all the last values generated at every
 run) value into a separate vector. I know that lm (and glm) provides a
 specific function for extracting  the predicted values but I don't know how
 to use it inside a loop. Can you suggest anything?


 P.

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Rolling-regressions-with-sample-extended-one-period-at-a-time-tp4470316p4478016.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.

__
R-help@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.


Re: [R] Rolling regressions with sample extended one period at a time

2012-03-16 Thread Peter Ehlers

If the OP just wants the last fitted value, use fitted():

dats - data.frame(x = 1:100, y = rnorm(100))

num.runs - 21
fitvec - numeric(num.runs)

for(i in seq_len(num.runs)){
  fits - fitted(lm(y ~ x, data = dats[1:(80+i-1), ]))
  fitvec[i] - tail(fits, 1)
}

Peter Ehlers

On 2012-03-16 14:05, R. Michael Weylandt wrote:

You can use predict() just as you would anywhere else:

for(i in 80:100){
 predict(lm(y ~ x, data = dats[1:i, ]), newdata = ???)
}

Michael

On Fri, Mar 16, 2012 at 8:12 AM, pie'tcpie...@yahoo.it  wrote:

hey,


thanks for the hint. I too figured I'd have to write a for-loop. I have the
problem now of how to extract the single element of the fitted values
vector. For example, run 1 of the regression generates 80 fitted values, run
2 generates 81 fitted values, run 3 produces 82 fitted values and so on. I
need to extract the 80th, 81st, 82nd (all the last values generated at every
run) value into a separate vector. I know that lm (and glm) provides a
specific function for extracting  the predicted values but I don't know how
to use it inside a loop. Can you suggest anything?


P.

--
View this message in context: 
http://r.789695.n4.nabble.com/Rolling-regressions-with-sample-extended-one-period-at-a-time-tp4470316p4478016.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


__
R-help@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.


__
R-help@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.


Re: [R] Rolling regressions with sample extended one period at a time

2012-03-14 Thread pie'
Hi,

I took a look at the documentation concerning rollapply and it doesnt seem
to be the command I need. Just to be more clear, on an initial sample of 80
observations I want to perform a probit regression and save the fitted
probabilities in a vector. Subsequently another probit is run on the sample
1-81 with relative save of the fitted probabilities. And so again for the
sample 1-82, 1-83, 1-84 etc... through the end of the sample. Does rollapply
allow me to do this?

P.

--
View this message in context: 
http://r.789695.n4.nabble.com/Rolling-regressions-with-sample-extended-one-period-at-a-time-tp4470316p4471995.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Rolling regressions with sample extended one period at a time

2012-03-14 Thread R. Michael Weylandt
My apologies: I was thinking of rolling more in the sense of
sliding than creeping. I'm not aware of anything suited for that,
but it's not hard to roll your own with something like

dats - data.frame(x = 1:100, y = rnorm(100))

for(i in 80:100){
lm(y ~ x, data = dats[1:i, ])
}

Michael


On Wed, Mar 14, 2012 at 10:38 AM, pie' tcpie...@yahoo.it wrote:
 Hi,

 I took a look at the documentation concerning rollapply and it doesnt seem
 to be the command I need. Just to be more clear, on an initial sample of 80
 observations I want to perform a probit regression and save the fitted
 probabilities in a vector. Subsequently another probit is run on the sample
 1-81 with relative save of the fitted probabilities. And so again for the
 sample 1-82, 1-83, 1-84 etc... through the end of the sample. Does rollapply
 allow me to do this?

 P.

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Rolling-regressions-with-sample-extended-one-period-at-a-time-tp4470316p4471995.html
 Sent from the R help mailing list archive at Nabble.com.
        [[alternative HTML version deleted]]

 __
 R-help@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.

__
R-help@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.


[R] Rolling regressions with sample extended one period at a time

2012-03-13 Thread pie'
Hi,

I would like suggestions as to how to perform rolling regressions with the
window extended one period at a time. That is, an initial sample period is
passed to estimation and that very sample is then extended one period at a
time through the remaining sample. Is there a specific package?

Thnks.

P.

--
View this message in context: 
http://r.789695.n4.nabble.com/Rolling-regressions-with-sample-extended-one-period-at-a-time-tp4470316p4470316.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Rolling regressions with sample extended one period at a time

2012-03-13 Thread R. Michael Weylandt
Perhaps zoo::rollapply from the zoo package can get you started.

Michael

On Tue, Mar 13, 2012 at 4:49 PM, pie' tcpie...@yahoo.it wrote:
 Hi,

 I would like suggestions as to how to perform rolling regressions with the
 window extended one period at a time. That is, an initial sample period is
 passed to estimation and that very sample is then extended one period at a
 time through the remaining sample. Is there a specific package?

 Thnks.

 P.

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Rolling-regressions-with-sample-extended-one-period-at-a-time-tp4470316p4470316.html
 Sent from the R help mailing list archive at Nabble.com.
        [[alternative HTML version deleted]]

 __
 R-help@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.

__
R-help@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.