Dear Help,
I'm trying to calculate a weighted correlation matrix from a data frame with 6 columns (variables) and 297 observations extracted from the regression. The last column is a weight column which I want to apply. $ model :'data.frame': 297 obs. of 6 variables: ..$ VAR1 : num [1:297] 5.21 9.82 8.08 0.33 8.7 6.82 3.94 4 0 5 ... ..$ VAR2 : num [1:297] 7.82 9.79 8.5 5.59 7.82 7.13 5.59 7 0 5 ... ..$ VAR3 : num [1:297] 8.07 9.82 8.07 5.19 8.69 7.45 6.08 5 0 8 ... ..$ VAR4 : num [1:297] 6.66 9.81 8.62 4.97 8.62 5.9 5.9 0 0 6 ... ..$ VAR5 : num [1:297] 4.79 9.8 7.9 0.27 7.9 5.76 3.44 5 0 4 ... ..$ (weights): num [1:297] 1.01e-05 4.05e-01 1.24e-02 2.68e-05 3.02e-01 ... I use cov.wt() function (as this is the only function I could find to calculate weighted correlations). If I use it without weight, it works OK: > cov.wt(y$model[1:5],cor=TRUE) $cov VAR1 VAR2 VAR3 VAR4 VAR5 VAR1 7.250067 5.558081 5.342363 5.771774 6.049620 VAR2 5.558081 8.079245 6.616040 6.552380 5.122272 VAR3 5.342363 6.616040 7.985783 6.447208 4.867224 VAR4 5.771774 6.552380 6.447208 8.610053 5.077627 VAR5 6.049620 5.122272 4.867224 5.077627 6.717658 $center VAR1 VAR2 VAR3 VAR4 VAR5 4.574175 4.450438 5.250236 4.439731 4.635421 $n.obs [1] 297 $cor VAR1 VAR2 VAR3 VAR4 VAR5 VAR1 1.0000000 0.7262204 0.7021075 0.7305256 0.8668584 VAR2 0.7262204 1.0000000 0.8236714 0.7856168 0.6952937 VAR3 0.7021075 0.8236714 1.0000000 0.7775173 0.6645285 VAR4 0.7305256 0.7856168 0.7775173 1.0000000 0.6676501 VAR5 0.8668584 0.6952937 0.6645285 0.6676501 1.0000000 If I try to apply weight, it doesn't work and gives me an error message: > cov.wt(y$model[1:5],wt=y$model[6],cor=TRUE) Error in cov.wt(y$model[1:5], wt = y$model[6], cor = TRUE) : length of 'wt' must equal the number of rows in 'x' The length of the weight variable is the same as for the other variables. What do I do wrong? Thanks in advance, Lena [[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.