[R] For loop - how to assign "i" when it is not an element of an index?

2008-10-20 Thread Scotty Nelson

Hello,

I'm trying to build a for loop, where I estimate a series of models with
different sets of (time series) data.
However my for loop doesn't recognize the "i" 

# code
window.1=anomalies.CAK[(positions(anomalies.CAK)>=timeDate("1/1/1971") &
positions(anomalies.CAK)<=timeDate("6/30/1991") )]

window.14=anomalies.CAK[(positions(anomalies.CAK)>=timeDate("1/1/1984") &
positions(anomalies.CAK)<=timeDate("6/30/2004") ),]

for (i in 1:14){
ar1mods[1] = lm ( formula = window.i~ ar(1) )
}
# end code ###

Problem: Object "window.i" not found 

Anybody have a quick tip on what I'm doing wrong?

-- 
View this message in context: 
http://www.nabble.com/For-loop---how-to-assign-%22i%22-when-it-is-not-an-element-of-an-index--tp20083917p20083917.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] nlm return wrong function value - garch fitting

2008-10-14 Thread Scotty Nelson

I am using nlm to maximize a likelihood function.  When I call the likelihood
function (garchLLH) via nlm however, nlm returns the wrong value of the
function.  

When I test the likelihood function manually I get the correct answer.  I'm
probably doing something really stupid, maybe someone can point it out for
me.  

###this is the function i am trying to minimize 
garchLLH <- function(y,xdata, parm) {

len<-length(parm)
yhat<-as.vector(t(parm[1:(len-3)]%*%t(xdata)))
###compute likelihood
omega<-parm[len-2]; alpha<-parm[len-1]; beta<-parm[len]
z<-(y-yhat)^2; Mean=mean(z);  z is the squared error
h<-vector(length=length(y) )
logLL<-vector(length=length(y) )
h[1] <- omega + alpha*Mean + beta*Mean;
logLL[1]<- 0.5 * ( log (2*pi) + log (h[1] ) + z[1] / h[1] ) #negative of the
LL
for (i in (2:length(y)) ) {
h[i] <- omega + alpha*z[i-1] + beta*h[i-1]
#logLL[i]<- -0.5 * ( log (2*pi) + log (h[i] ) + z[i] / h[i] ) 
logLL[i]<- -0.5 * ( log (h[i] ) + z[i] / h[i] )
}
llh=-sum(logLL);
llh

}
##ok if i call this function with my initial parameters, i get the
right likelihood value 
> parm
[1] -0.01642679  0.17234848  0.22053851  0.

> garchLLH(y, xdata, parm)
[1] -596.1819

 now when i call nlm and look at the first iteration, it is telling me
that the value of the function is 0.7370451   

> fit=nlm(f=garchLLH, y,xdata, p=parm, print.level=2)
iteration = 0
Step:
[1] 0 0 0 0
Parameter:
[1] -0.01642679  0.17234848  0.22053851  0.
Function Value
[1] 0.7370451 <- what's up with that  it should be -596.1819
Gradient:
[1] -0.03006041  0.14911503  0.10740682 -0.04930265



[[elided Hotmail spam]]
Thanks,
Scotty




-- 
View this message in context: 
http://www.nabble.com/nlm-return-wrong-function-value---garch-fitting-tp19980876p19980876.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] lag function doesn't work - what am i doing wrong?

2008-10-10 Thread Scotty Nelson

thanks.  i'll try zoo or xts.  ts is a p.i.t.a.


Gabor Grothendieck wrote:
> 
> lag1resid is a time series, try
> 
> str(residsq)
> str(lag1residsq)
> 
> The problem is that when you subscript lag1resid you
> don't get a time series out from that.  See ?window.ts
> or try the zoo or xts packages where subscripting of time
> series works.
> 
> On Fri, Oct 10, 2008 at 1:27 PM, Scotty Nelson <[EMAIL PROTECTED]>
> wrote:
>>
>> I am trying to lag a time series.  My data is in a matrix, but I coerce
>> it
>> into a ts object.
>> But when I lag it and then look at the result, nothing has changed.  What
>> am
>> I doing wrong?
>>
>> residsq<-resid^2
>> residsq<-as.ts(residsq)
>> lag1residsq<-lag(residsq,-1)
>>
>>> residsq[1:5]
>>  1   2   3   4   5
>> 87.759  329882.188 5325849.333   31512.334   70865.228
>>>  lag1residsq[1:5]
>>  1   2   3   4   5
>> 87.759  329882.188 5325849.333   31512.334   70865.228
>>>
>>
>> PS: I tried to lag the series manually using rbind(0, residsq), but the
>> result ended up returning me [ 0, residsq(1), 0, residsq(2), 0, ]
>> WTF  how do you stack 1 element onto another in R?
>> --
>> View this message in context:
>> http://www.nabble.com/lag-function-doesn%27t-work---what-am-i-doing-wrong--tp19922651p19922651.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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/lag-function-doesn%27t-work---what-am-i-doing-wrong--tp19922651p19923295.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] lag function doesn't work - what am i doing wrong?

2008-10-10 Thread Scotty Nelson

I am trying to lag a time series.  My data is in a matrix, but I coerce it
into a ts object.
But when I lag it and then look at the result, nothing has changed.  What am
I doing wrong?

residsq<-resid^2
residsq<-as.ts(residsq)
lag1residsq<-lag(residsq,-1)

> residsq[1:5]
  1   2   3   4   5 
 87.759  329882.188 5325849.333   31512.334   70865.228 
>  lag1residsq[1:5]
  1   2   3   4   5 
 87.759  329882.188 5325849.333   31512.334   70865.228 
> 

PS: I tried to lag the series manually using rbind(0, residsq), but the
result ended up returning me [ 0, residsq(1), 0, residsq(2), 0, ]
WTF  how do you stack 1 element onto another in R?
-- 
View this message in context: 
http://www.nabble.com/lag-function-doesn%27t-work---what-am-i-doing-wrong--tp19922651p19922651.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] qqline function doesn't plot

2008-08-05 Thread Scotty Nelson

Thanks!
-- 
View this message in context: 
http://www.nabble.com/qqline-function-doesn%27t-plot-tp18827175p18842548.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] qqline function doesn't plot

2008-08-05 Thread Scotty Nelson

I have a data vector x.  When I try 

qqline(x)

I get the following error:

Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : 
  plot.new has not been called yet

And a blank plot appears.

Can anybody help?  What am I doing wrong?

Thanks,
Scotty



_

 Contest

[[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] Including exogenous X-variables in ARFIMA models

2008-08-04 Thread Scotty Nelson

Does anybody know if there is a way to include exogenous X-variables in an 
ARFIMA model?
It appears the ARFIMA function in fracdiff does not support this.

Supposing there is nothing already written, and I wanted to modify the existing 
arfima function, how would I go about this?
Would I need to modify the fracdiff() binaries and compile them on my machine?  
I'm running WindowsI think I'm screwed = (

-- Scotty

_
Get more from your digital life.  Find out how.

[[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] Installing Packages in Windows Vista -- YES I tried Run as Administrator

2008-05-01 Thread Scotty Nelson

I'm having trouble installing packages in Windows Vista.  It's driving me
nuts.
I read all the threads and I have tried the following:

1) Right click on R and Run as Administrator
2) Turn off User Account Control
3) Toss machine across room (OK haven't tried this one yet, but I'm close)

Here is the R error messages I am getting

--- Please select a CRAN mirror for use in this session ---
trying URL
'http://cran.stat.ucla.edu/bin/windows/contrib/2.6/boot_1.2-32.zip'
Content type 'application/zip' length 51 bytes (759 Kb)
opened URL
downloaded 32 Kb

Error in gzfile(file, "r") : unable to open connection
In addition: Warning messages:
1: In download.file(url, destfile, method, mode = "wb") :
  downloaded length 33219 != reported length 51
2: In zip.unpack(pkg, tmpDir) : error 1 in extracting from zip file
3: In gzfile(file, "r") :
  cannot open compressed file 'boot/DESCRIPTION', probable reason 'No such
file or directory'

Can anybody help?  My presentation is in 14 hours and right now I'm thin on
results.

THANK YOU THANK YOU THANK YOU!

-- Scotty
-- 
View this message in context: 
http://www.nabble.com/Installing-Packages-in-Windows-VistaYES-I-tried-Run-as-Administrator-tp16993043p16993043.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.