[R] Time Series

2009-10-02 Thread Kon Knafelman

Hi,

Im trying to perform a time series analysis on financial data. Im going on the 
assumption that it follows the random walk, and therefore am fitting an ARIMA 
process via the following code fit-arima(exchange,order=c(0,1,0)), and then 
analysing the tsdiag.

Is there a more efficient way of doing this? or can i get R to automatically 
give the most efficient p,d,q values for the model itself?

Thanks a lot, any point in the right direction would be greatly appreciated.


  
_


[[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] matrix exponential

2009-09-30 Thread Kon Knafelman

Hi Guys,

 

Im trying to find the exponential of a matrix.

 

Can someone please help me do this?

 

Thanks a lot
  
_
View photos of singles in your area Click Here

=1lage=18uage=55cl=14sl=0dist=50po=1do=2trackingid=1046138r2s=1_t=773166090_r=WLM_EndText
[[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] time series and ACF

2009-09-29 Thread Kon Knafelman

Hey guys,

im sort of a beginner with R, but here's what i need to do.

i need to perform a time series analysis on a set of financial data that i've 
been given. im trying to look at the ACF and PACF and fit it to a particular 
model (i think its the ARIMA model because i've read that financial data 
resembles the random walk, where the ARIMA model fits). is this correct?

if my data is called numbers

ts.plot(numbers)
acf(numbers,30,type='partial')

now, i want to difference at a particular number of lags, and i thought to use 
this code:

dnumbers - diff(numbers, 10)
ts.plot(dnumbers)
acf(dnumbers)
acf(dnumbers, 30,type='partial')

but i get error messages after ts.plot(dnumbers):

Error in matrix(rep.int(tx, k), ncol = k) : 
  invalid 'nrow' value (too large or NA)

and after acf(dnumbers):

Error in plot.acf(acf.out, ...) : x$lag must have at least 1 column

Am i going about doing this the right way? i want to have a look at 
differencing and hope to fit the model from this.

Can someone help me with what is wrong with my code, and any suggestions would 
be soo helpful..

Thanks a lot to everyone,

Kon




  
_
POP access for Hotmail is here! Click here to find out more

[[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] FW: time series and ACF

2009-09-29 Thread Kon Knafelman





Hey guys,

im sort of a beginner with R, but here's what i need to do.

i need to perform a time series analysis on a set of financial data that i've 
been given. im trying to look at the ACF and PACF and fit it to a particular 
model (i think its the ARIMA model because i've read that financial data 
resembles the random walk, where the ARIMA model fits). is this correct?

if my data is called numbers

ts.plot(numbers)
acf(numbers,30,type='partial')

now, i want to difference at a particular number of lags, and i thought to use 
this code:

dnumbers - diff(numbers, 10)
ts.plot(dnumbers)
acf(dnumbers)
acf(dnumbers, 30,type='partial')

but i get error messages after ts.plot(dnumbers):

Error in matrix(rep.int(tx, k), ncol = k) : 
  invalid 'nrow' value (too large or NA)

and after acf(dnumbers):

Error in plot.acf(acf.out, ...) : x$lag must have at least 1 column

Am i going about doing this the right way? i want to have a look at 
differencing and hope to fit the model from this.

Can someone help me with what is wrong with my code, and any suggestions would 
be soo helpful..

Thanks a lot to everyone,

Kon







Click here to find out more POP access for Hotmail is here! 
  
_
POP access for Hotmail is here! Click here to find out more

[[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] Inverse

2009-05-21 Thread Kon Knafelman

Hi Guys,

i think this is a relatively simple question.

I have coded the following polynomial function

y= function(x) x^3-2*x^2+1

I need to find the inverse of this, but the code i am using now isnt returning 
what i want it to.

What is the general code for finding an inverse function?

Thanks guys 

_
View photos of singles in your area Click Here

au%2Fsearch%2Fsearch%2Easpx%3Fexec%3Dgo%26tp%3Dq%26gc%3D2%26tr%3D1%26lage%3D18%26uage%3D55%26cl%3D14%26sl%3D0%26dist%3D50%26po%3D1%26do%3D2%26trackingid%3D1046138%26r2s%3D1_t=773166090_r=Hotmail_Endtext_m=EXT
[[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] evaluate polynomial

2009-05-20 Thread Kon Knafelman

Hey guys, sorry im drawing a mental blank.

 

i have coded the function:

 

y - function(x) 6*x^4-(1*x^2)^3

 

How do i evaluate this function for a given x?

 

i know this is a ridiculous question, but thanks anyway

_
[[elided Hotmail spam]]

[[elided Hotmail spam]]
=Domain_tagline_m=EXT
[[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] Simulation

2009-05-18 Thread Kon Knafelman

Hi peter,

Quite an insight you have there hehe. i am continuing on from the orignal 
problem of creating a simulation.

Im now trying to find (n−1)S2/σ2, and fit it to a chi squared dist with 5 
degrees of freedom.
 
im having trouble with the coding for this. i think for the second part of that 
i need to use the fitdist function, but to get it to where i am able to do 
that, im not sure what to do.
 
THis is what i have been trying to do so far, but it hasn't returned me 
anything good
sum((x-mean(x))^2)/(length(x)-1)
i am really confused, can someone please help?
 
Cheers

 Date: Thu, 14 May 2009 12:05:30 +0100
 From: b.rowling...@lancaster.ac.uk
 To: peterflomconsult...@mindspring.com
 CC: waclaw.marcin.kusnierc...@idi.ntnu.no; r-help@r-project.org
 Subject: Re: [R] Simulation
 
  As a beginner, I agree  the for loop is much clearer to me.
 
 
  [Warning: Contains mostly philosophy]
 
 To me, the world and how I interact with it is procedural. When I want
 to break six eggs I do 'get six eggs, repeat break egg until all
 eggs broken'. I don't apply an instance of the break egg function over
 a range of eggs. My world is not functional (just like me, some might
 say...). Neither do I send a 'break yourself' message to each egg - my
 world is not object-oriented.
 
 That does not mean that these paradigms are not good ways of writing
 computer programs - they are brilliant ways of writing computer
 programs. But they build on procedural concepts, and we don't teach
 children to run before they can walk.
 
  So when someone says 'how do I do this a thousand times?' on R-help,
 I'll assume their knowledge level is that of a beginner, and try to
 map the solution to their world view.
 
  Computer scientists will write their beautiful manuscripts, but how
 many people who come to R because they want to do a t-test or fit a
 GLM will read them? That's the R-help audience now.
 
 Barry
 
 __
 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.

_
[[elided Hotmail spam]]

[[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] sample variance from simulation

2009-05-18 Thread Kon Knafelman

Hi,

 g=list()
 for(i in 1:1000){z[[i]]=rnorm(15,0,1)}

I've attempted a similar problem based on the above method. Now, if i want to 
find the sample variance, do i go about it like this?

 for (i in 1:1000)vars[[i]] = sum(z[[i]])
 vars[[i]] 

the overall sigma squared will just be 1, because the distribution is standard 
normal. Is this correct?

if so, then to find (n−1)S^2/σ^2,

i will need s=999*sum(vars[[i]]))/1?

Is this correct, or am i getting lost along the way?

Thank you
 Date: Wed, 13 May 2009 16:45:22 +0100
 From: b.rowling...@lancaster.ac.uk
 To: csa...@rmki.kfki.hu
 CC: r-help@r-project.org
 Subject: Re: [R] Simulation
 
 On Wed, May 13, 2009 at 4:26 PM, Gábor Csárdi csa...@rmki.kfki.hu wrote:
  On Wed, May 13, 2009 at 5:13 PM, Debbie Zhang debbie0...@hotmail.com 
  wrote:
 
 
  Dear R users,
 
  Can anyone please tell me how to generate a large number of samples in R, 
  given certain distribution and size.
 
  For example, if I want to generate 1000 samples of size n=100, with a 
  N(0,1) distribution, how should I proceed?
 
  (Since I dont want to do rnorm(100,0,1) in R for 1000 times)
 
  Why not? It took 0.05 seconds on my 5 years old laptop.
 
  Second-guessing the user, I think she maybe doesn't want to type in
 'rnorm(100,0,1)' 1000 times...
 
  Soln - for loop:
 
   z=list()
   for(i in 1:1000){z[[i]]=rnorm(100,0,1)}
 
 now inspect the individual bits:
 
   hist(z[[1]])
   hist(z[[545]])
 
 If that's the problem, then I suggest she reads an introduction to R...
 
 Barry
 
 __
 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.

_
Looking to change your car this year? Find car news, reviews and more
http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fsecure%2Dau%2Eimrworldwide%2Ecom%2Fcgi%2Dbin%2Fa%2Fci%5F450304%2Fet%5F2%2Fcg%5F801459%2Fpi%5F1004813%2Fai%5F859641_t=762955845_r=tig_OCT07_m=EXT
[[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] fitting distribution

2009-05-18 Thread Kon Knafelman

Hey Guys,

i have the sample variances for 1000 samples, and i want to fit it to a 
chi-squared distribution.

after making a loop for the simulation initially, i have the following code to 
compute the variances
samples = replicate(n, rnorm(m, 0, 1), simplify=FALSE)
variances = sapply(samples, var)
summary(variances)
can someone please help me fit this to a chi-squared distribution with n 
degrees of freedom.
Thanks a lot 

_
[[elided Hotmail spam]]

[[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] Simulation Help

2009-05-17 Thread Kon Knafelman

Hey Guys, 

i need 1000 samples of size 15, for distributions of Exp(1) and Norm(0,1). here 
is what i have done so far.For the exponential
z-list()
for(i in 1:1000){z[[i]]=rexp(15,1)}

For the Normal
y-list()

for(i in 1:1000){y[[i]]=rnorm(15,0,1)}


Is this correct?

after this i need to compute the statistic (n-1)S2/ ó2 , produce a probability 
histogram for this result, and superimpose the distribution over chi-squared 
with 14 degrees of freedom.

My thoughts on how to proceed is that after the statistic is calculated, i use 
the fistdist function? Only thing is, i am not sure how to compute the 
(n-1)S2/ ó2

If anyone could help me out that would be much appreciated.

Thanks Guys

_
[[elided Hotmail spam]]

[[elided Hotmail spam]]
=Domain_tagline_m=EXT
[[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] Gamma

2009-05-16 Thread Kon Knafelman

Hey,

I am having trouble graphing the following function

√2Γ(n/2)/[√n − 1Γ((n − 1)/2 for the values of n between 2 and 50.

i know that Γ(n) = (n-1)!, which in R is factorial(n-1)

When i type that into R, using y - function(n).
and
then plot(y,2,50), it doesnt give me anything meaningful, in fact, it
comes up with a message saying something like in gamma(n+1) ploted or
something along those lines.

Can anyone please help?

thank you

_
Looking to move somewhere new this winter? Let ninemsn property help
http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Edomain%2Ecom%2Eau%2F%3Fs%5Fcid%3DFDMedia%3ANineMSN%5FHotmail%5FTagline_t=774152450_r=Domain_tagline_m=EXT
[[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] Gamma function

2009-05-16 Thread Kon Knafelman

Hi Guy,

I am having trouble graphing the following function

√2Γ(n/2)/[√n − 1Γ((n − 1)/2 for the values of n between 2 and 50.

i know that Γ(n) = (n-1)!, which in R is factorial(n-1)

When i type that into R, using y - function(n).
and then plot(y,2,50), it doesnt give me anything meaningful, in fact, it comes 
up with a message saying something like in gamma(n+1) ploted or something 
along those lines.

Can anyone please help?

thanks you

_
Looking to change your car this year? Find car news, reviews and more
http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fsecure%2Dau%2Eimrworldwide%2Ecom%2Fcgi%2Dbin%2Fa%2Fci%5F450304%2Fet%5F2%2Fcg%5F801459%2Fpi%5F1004813%2Fai%5F859641_t=762955845_r=tig_OCT07_m=EXT
[[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] Newton's method for finding roots

2009-05-16 Thread Kon Knafelman

Hey guys, i have a relatively simple problem.

I need to use netwon's method to find the root of a polynomial, lets say 
x^3-2x-1

i start off with

p - function(x) x^3-2*x-1

My method, which im sure is very amateur, is to type another function, which is 
the derivative of p, and after picking an initial value to start off with, i 
follow the steps of newton's method manually, but i dont think that is what the 
question is asking.

I've done some research on wikipedia, but i cant seem to find any code that 
will help me.

Can someone help?

Thanks a lot

_



[[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] Simulation

2009-05-15 Thread Kon Knafelman

hey guys, i've been following this discussion about the simulation, and being a 
beginner myself, im really unsure of the best method.

 

I hve the same problem as the initial one, except i need 1000 samples of size 
15, and my distribution is Exp(1). I've adjusted some of the loop formulas for 
my n=15, but im unsure how to proceed in the quickest way.

 

Can someone please help?

 

Much appreciated :)
 
 From: r.tur...@auckland.ac.nz
 Date: Thu, 14 May 2009 10:26:38 +1200
 To: c...@witthoft.com
 CC: r-help@r-project.org
 Subject: Re: [R] Simulation
 
 
 On 14/05/2009, at 10:04 AM, Carl Witthoft wrote:
 
  So far nobody seems to have warned the OP about seeding.
 
  Presumably Debbie wants 1000 different sets of samples, but as we all
  know there are ways to get the same sequence (initial seed) every 
  time.
  If there's a starting seed for one of the generate a single giant
  matrix methods proposed, the whole matrix will be the same for a 
  given
  seed.
  If rnorm is called 1000 times (hopefully w/ different random (oops)
  seeds), the entire set of samples will be different.
 
  and so on.
 
 I really don't get this. The OP wanted 1000 independent samples,
 each of size 100. Whether she does
 
 set.seed(42)
 M - matrix(rnorm(100*1000),nrow=1000) # Each row is a sample.
 
 or
 
 L - list()
 set.seed(42)
 for(i in 1:1000) L[[i]] - rnorm(100) # Each list entry is a sample.
 
 she gets this, i.e. the desired result. Setting a seed serves to make
 the results reproducible. This works via either approach. Making 
 results
 reproducible in this manner is advisable, but seed-setting is nothing 
 that the OP
 needs to be *warned* about.
 
 cheers,
 
 Rolf Turner
 
 ##
 Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
 
 __
 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.

_



[[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] Simulation

2009-05-15 Thread Kon Knafelman

hey guys, i've been following this discussion about the simulation, and being a 
beginner myself, im really unsure of the best method.
 
 
 
I hve the same problem as the initial one, except i need 1000 samples of size 
15, and my distribution is Exp(1). I've adjusted some of the loop formulas for 
my n=15, but im unsure how to proceed in the quickest way.
 
 
 
Can someone please help?

_
[[elided Hotmail spam]]

[[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] (no subject)

2009-05-12 Thread Kon Knafelman

Hi,

I have a question about derivatives of functions.

if i have the following function,

f - function(x) x^3-2*x^2+3*x-5

i need a simple function for the derivative of this with respect to 'x', so 
that i can then sub in values to the the derivative function, and use Newtons 
method of finding a root for this.

Please help.

Regards,

Kon Knafelman

_



[[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] newtons method

2009-05-12 Thread Kon Knafelman

Hi,

Does anyone know how to code newton's method for finding the roots of 
polynomial functions? im not sure whether i need to do this manually, or just 
code something with a loop to stop when it gets to the desired result

thanks guys!

_
Looking to move somewhere new this winter? Let ninemsn property help

[[elided Hotmail spam]]
=Domain_tagline_m=EXT
[[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.