cov computation in Matlab
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
If the definition of covariance is (x-mean(x))'*(x-mean(x)), why cov(x) does not return the same result? Thank you.
채택된 답변
Roger Stafford
2017년 10월 27일
0 개 추천
The 'cov' function normalizes by dividing by N-1 where N is the number of observations, which in this case is the number of rows in your matrix x.
댓글 수: 10
Bi Bu
2017년 10월 27일
Thanks, that means that Matlab by default uses the sample covariance (n-1). Is this correct?
Roger Stafford
2017년 10월 27일
Yes, by default it divides by the number of samples minus one except in case of one sample (heaven forbid!) it divides by 1.
Bi Bu
2017년 10월 27일
Thank you!
Steven Lord
2017년 10월 27일
And if you want it to normalize by N instead of N-1 even when N > 1, specify the input argument named w in the documentation as 1 instead of omitting it or specifying it as 0.
Bi Bu
2017년 10월 27일
Thanks, this is helpful.
Bi Bu
2017년 10월 28일
Dear Steven, one more question popped up: does the "mean" function in Matlab have the option to divide by n or n-1? Because in the case of "cov", it is taking the expected value (mean) of the results by dividing by n-1 and not n. So if I wanted to write differently this formula, and use "mean" I wouldn't have the option to use n-1. Thanks.
Roger Stafford
2017년 10월 28일
@Bi Bu: It would make no sense dividing by n-1 in taking the mean. To get an unbiased estimate from the sum of n samples, one needs to divide by just n. That is, assuming subsequent samples each have the same expected value, then the sum of n of them will have an expected value of n times the expected value of any one of them, so such a sum should be divided by just n.
However, the definition of the covariance between two variables involves the mean of each of them. If one uses samples to estimate these means along with estimating their covariance, it can be shown by rather simple mathematics that a division by n-1 rather than n is necessary in the sum of products used to yield an unbiased estimate of the theoretical covariance. This is due to the expected deviation of these sample means from their true means. If you are interested in the mathematics involved, there are many such demonstrations on the internet. One such is located at:
https://www.youtube.com/watch?v=D1hgiAla3KI
Bi Bu
2017년 10월 28일
Thank you so much! Great response. I will definitely watch the video. However, I can't see how the simple mean of a sample wouldn't be as biased as the means of the samples used to compute covariance. They are samples in both cases, after all.
Roger Stafford
2017년 10월 28일
편집: Roger Stafford
2017년 10월 28일
@Bi Bu: No, the two expressions approximating the mean and the covariance are of a different nature. In the case of the mean the expression is a simple sum so that its expected value is simply the sum of the n separate means, and that certainly indicates the need to divide by n, not n-1 (where n is the number of terms). To divide by n-1 would be to give a biased estimate.
On the other hand, the expression for approximating the covariance is the sum of products, which in part depend on an approximation to the means of the two variables. It is this latter source of variation that has the effect of reducing, somewhat, the expected value of this expression, and results in a need to divide by the smaller n-1, not n. There is no such feature in the simple mean computation.
Remember, producing an unbiased estimate is defined as having the expected value of the approximation be precisely equal to the theoretical mean or covariance, so there is no choice in the matter in either case.
By the way, the website demonstration I mentioned above is actually concerned with the variance of one variable rather than the covariance of two variables. However, its argument is very similar to that needed for covariance, so it should serve to show the need for dividing by n-1 for the covariance computation. I would give the proof here, but I’m afraid it would take up quite a lot of space in this supposedly simple “answer”.
Bi Bu
2017년 10월 29일
It would be great if you could write the answer. Is it too long?
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
