> x <- runif(10)
> y <- runif(10)
> cov(cbind(x,y))
x y
x 0.1205034 0.02642830
y 0.0264283 0.09945432
I understand wanting to calculate covariance matrices.
What I DON'T understand is wanting to do it using apply().
(And that's what looked like a homework problem, it's so artifi
On Fri, 04 Oct 2024 11:16:45 -0700
Jeff Newmiller via R-help wrote:
> Even if this is not a homework question, it smells like one. If you
> read the Posting Guide it warns you that homework is off-topic, so
> when you impose an arbitrary constraint like "must use specific
> unrelated function" we
Even if this is not a homework question, it smells like one. If you read the
Posting Guide it warns you that homework is off-topic, so when you impose an
arbitrary constraint like "must use specific unrelated function" we feel like
you are either cheating or wasting our time, and it is up to you
Pardon me!!!
What makes you think this is a homework question? You are not obligated
to respond if the question is not intelligent enough for you.
I did the following: two ways to calculate a covariance matrix but
wonder how I might replicate the results with "apply". I am not too
comfortable
Hello,
You don't need apply, covariance calculations are so frequent that R or
any other statistics package already has pre-programmed functions.
This time with two vectors x and y.
set.seed(123)
n <- 3
x <- rnorm(n)
y <- rnorm(n)
# the two main diagonal values
var(x)
#> [1] 1.300025
var(y)
Why must the answer use apply? It feels like there are elements of the problem
that are not explained.
-Original Message-
From: R-help On Behalf Of Ben Bolker
Sent: Friday, October 4, 2024 8:45 AM
To: r-help@r-project.org
Subject: Re: [R] apply
[External Email]
It's still hard to fi
Hallo
you can extract POSIX object
tv <- as.POSIXct(index(dt_train))
and use cut together with aggregate
cut(tv, "hour")
aggregate(dt_train, list(cut(tv, "hour")), mean)
2014-10-06 21:00:00 9.807692
2014-10-06 22:00:00 8.67
Cheers.
Petr
čt 3. 10. 2024 v 17:25 odesílatel roslinazairimah
It's still hard to figure out what you want. If you have two vectors
you can compute their (2x2) covariance matrix using cov(cbind(x,y)).
If you want to compute all pairwise squared differences between elements
of x and y you could use outer(x, y, "-")^2.
Can you explain a little bit more
В Fri, 4 Oct 2024 20:28:01 +0800
Steven Yen пишет:
> Suppose I have two vectors, x and y. Is there a way
> to do the covariance matrix with “apply”.
There is no covariance matrix for just two samples (vectors) 'x' and
'y'. You can only get one covariance value for these.
If you had a pair of v
OK. Thanks to all. Suppose I have two vectors, x and y. Is there a way
to do the covariance matrix with “apply”. The matrix I need really
contains the deviation products divided by the degrees of freedom (n-1).
That is, the elements
(1,1), (1,2),...,(1,n)
(2,1), (2,2),, (2,n)
(n,1)
Hello,
This doesn't make sense, if you have only one vector you can estimate
its variance with
var(x)
but there is no covariance, the joint variance of two rv's. "co" or
joint with what if you have only x?
Note that the variance of x[1] or any other vector element is zero, it's
only one va
В Fri, 4 Oct 2024 19:14:30 +0800
Steven Yen пишет:
> I have a vector:
> set.seed(123) > n<-3 > x<-rnorm(n); x [1] -0.56047565 -0.23017749
> 1.55870831
> var(x[1]) cov(x[1],x[2])
Are you sure you don't have a matrix? If you type var(x[1]) or
cov(x[1],x[2]) into R, you can see that all these are
Hello
I have a vector:
set.seed(123) > n<-3 > x<-rnorm(n); x [1] -0.56047565 -0.23017749
1.55870831 I like to create a matrix with elements containing variances
and covariances of x. That is var(x[1]) cov(x[1],x[2]) cov(x[1],x[3])
cov(x[2],x[1]) var(x[2]) cov(x[2],x[3]) cov(x[3],x[1]) cov(x[3]
Hello,
If you have a numeric matrix or data.frame, try something like
cov(mtcars)
Hope this helps,
Rui Barradas
Às 10:15 de 04/10/2024, Steven Yen escreveu:
On 10/4/2024 5:13 PM, Steven Yen wrote:
Pardon me!!!
What makes you think this is a homework question? You are not
obligated to res
On 04.10.2024 11:13, Steven Yen wrote:
Pardon me!!!
What makes you think this is a homework question? You are not obligated
Otherwise you called cov()
Best,
Uwe Ligges
to respond if the question is not intelligent enough for you.
I did the following: two ways to calculate a covariance
On 10/4/2024 5:13 PM, Steven Yen wrote:
> Pardon me!!!
>
> What makes you think this is a homework question? You are not
> obligated to respond if the question is not intelligent enough for you.
>
> I did the following: two ways to calculate a covariance matrix but
> wonder how I might replicate
Homework questions are not answered on this list.
Best,
Uwe Ligges
On 04.10.2024 10:32, Steven Yen wrote:
The following line calculates standard deviations of a column vector:
se<-apply(dd,1,sd)
How can I calculate the covariance matrix using apply? Thanks.
The following line calculates standard deviations of a column vector:
se<-apply(dd,1,sd)
How can I calculate the covariance matrix using apply? Thanks.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/l
18 matches
Mail list logo