[R] FW: Multivariate Normal and loops
R. Michael Weylandt
michael.weylandt at gmail.com
Sun Jun 17 16:14:41 CEST 2012
It's requested to cc the list on our back-and-forths so that i) you
can get help faster (I was moving all yesterday and it's a Hallmark
holiday in the US today) since others may respond; ii) others can
benefit by reading the archives.
On Sun, Jun 17, 2012 at 4:34 AM, Giulia Motta <letamotta at hotmail.com> wrote:
>
>
> the problem is that i want to do something like
> http://www.eco.uc3m.es/~jgonzalo/teaching/PhDTimeSeries/gonzalojec94.pdf in
> page 13
> with theta= 0.5, sigma = 0.5, a1=0 a2=-1 beta= 1
> and so i have to give a name (ewt, ezt) at the erratic component of my
> multivariate normal
> ________________________________
> From: letamotta at hotmail.com
> To:
> Subject: RE: [R] Multivariate Normal and loops
> Date: Sun, 17 Jun 2012 09:03:25 +0000
>
>
> I'm very grateful to you!
> But i'm wondering how i can do this, creating a matrix in which i can
> numerate every element?
> I don't know if i'm clear (probably not).
> Thank you very much
>
Unfortunately, I'm not totally clear as to what you are looking for
here. You can add row and column names (labels) with code like
rownames(A) <- c("a","cat","dog")
and then subscript appropriately:
A["cat",]
will pull out all columns (the empty index after the comma) in the row
labelled "cat". This is all documented in the manual I suggested to
you.
If there's something else you mean, try being a little clearer (using
examples from other programming languages if you know them is always
good) and we'll see what we can do.
Best,
Michael
>
>> From: michael.weylandt at gmail.com
>> Date: Fri, 15 Jun 2012 10:34:05 -0500
>> Subject: Re: [R] Multivariate Normal and loops
>> To: letamotta at hotmail.com
>> CC: r-help at r-project.org
>>
>> I don't think you need loops at all actually :-) [The main thing to
>> working with R vs. C is "vectorization" -- embrace it now and life
>> will be much better]
>>
>> You could do something like this:
>>
>> library(MASS) # Provides a multivariate normal distribution
>>
>> mvrnorm(100, c(1,5), matrix(c(2,1,1,2), ncol = 2))
>>
>> This gives you 100 samples of a multivariate normal with mean vector
>> (1,5) and covariance matrix
>>
>> (2, 1,
>> 1, 2)
>>
>> Feel free to tweak as necessary and type ?mvrnorm to see more
>> documentation.
>>
>> Hopefully this gets you started.
>>
>> For more on vectorization, see the "Introduction to R" that comes with
>> R. You can get it by typing help.start() at your command prompt.
>>
>> Hope this helps,
>> Michael
>>
>> On Fri, Jun 15, 2012 at 9:26 AM, Cassie <letamotta at hotmail.com> wrote:
>> > Hi,
>> > i'm not english and i'm not very familiar to R, and i'm asking if you
>> > can
>> > help me.
>> > I'm wondering how to create a multivariate normal an then repeat this
>> > for a
>> > sample of T=1000, and the save this result.
>> > Thank you very much for your helping
>> >
>> > --
>> > View this message in context:
>> > http://r.789695.n4.nabble.com/Multivariate-Normal-and-loops-tp4633504.html
>> > Sent from the R help mailing list archive at Nabble.com.
>> >
>> > ______________________________________________
>> > R-help at 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.
More information about the R-help
mailing list