/
cov.wt.html
121 lines (93 loc) · 3.33 KB
/
cov.wt.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: Weighted Covariance Matrices</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="R.css">
</head><body>
<table width="100%" summary="page for cov.wt"><tr><td>cov.wt</td><td align="right">R Documentation</td></tr></table>
<h2>Weighted Covariance Matrices</h2>
<h3>Description</h3>
<p>Returns a list containing estimates of the weighted covariance matrix
and the mean of the data, and optionally of the (weighted) correlation
matrix.</p>
<h3>Usage</h3>
<pre>
cov.wt(x, wt = rep(1/nrow(x), nrow(x)), cor = FALSE, center = TRUE,
method = c("unbiased", "ML"))
</pre>
<h3>Arguments</h3>
<table summary="R argblock">
<tr valign="top"><td><code>x</code></td>
<td>
<p>a matrix or data frame. As usual, rows are observations and
columns are variables.</p>
</td></tr>
<tr valign="top"><td><code>wt</code></td>
<td>
<p>a non-negative and non-zero vector of weights for each
observation. Its length must equal the number of rows of <code>x</code>.</p>
</td></tr>
<tr valign="top"><td><code>cor</code></td>
<td>
<p>a logical indicating whether the estimated correlation
weighted matrix will be returned as well.</p>
</td></tr>
<tr valign="top"><td><code>center</code></td>
<td>
<p>either a logical or a numeric vector specifying the
centers to be used when computing covariances. If <code>TRUE</code>, the
(weighted) mean of each variable is used, if <code>FALSE</code>, zero is
used. If <code>center</code> is numeric, its length must equal the number
of columns of <code>x</code>.</p>
</td></tr>
<tr valign="top"><td><code>method</code></td>
<td>
<p>string specifying how the result is scaled, see
‘Details’ below.</p>
</td></tr>
</table>
<h3>Details</h3>
<p>By default, <code>method = "unbiased"</code>,
The covariance matrix is divided by one minus the sum of squares of
the weights, so if the weights are the default (<i>1/n</i>) the conventional
unbiased estimate of the covariance matrix with divisor <i>(n - 1)</i>
is obtained. This differs from the behaviour in S-PLUS which
corresponds to <code>method = "ML"</code> and does not divide.
</p>
<h3>Value</h3>
<p>A list containing the following named components:
</p>
<table summary="R valueblock">
<tr valign="top"><td><code>cov</code></td>
<td>
<p>the estimated (weighted) covariance matrix</p>
</td></tr>
<tr valign="top"><td><code>center</code></td>
<td>
<p>an estimate for the center (mean) of the data.</p>
</td></tr>
<tr valign="top"><td><code>n.obs</code></td>
<td>
<p>the number of observations (rows) in <code>x</code>.</p>
</td></tr>
<tr valign="top"><td><code>wt</code></td>
<td>
<p>the weights used in the estimation. Only returned if given
as an argument.</p>
</td></tr>
<tr valign="top"><td><code>cor</code></td>
<td>
<p>the estimated correlation matrix. Only returned if
<code>cor</code> is <code>TRUE</code>.</p>
</td></tr>
</table>
<h3>See Also</h3>
<p><code>cov</code> and <code>var</code>.
</p>
<h3>Examples</h3>
<pre>
(xy <- cbind(x = 1:10, y = c(1:3, 8:5, 8:10)))
w1 <- c(0,0,0,1,1,1,1,1,0,0)
cov.wt(xy, wt = w1) # i.e. method = "unbiased"
cov.wt(xy, wt = w1, method = "ML", cor = TRUE)
</pre>
</body></html>