I am stuck in the following problem when I am doing my master thesis, and I failed to find any solution online by myself and thus your help will be really appreciated. Thanks for your reading and help in advance.
As the below sample dataset shows, I have collected five variables measuring subjects' mental health. Then, I need to derive an index that incorporates these five variables. To do so, previous literature suggests that I need to firstly get the covariance matrix of these five variables. Let's call it Mat_A. Then, for each subject, I need to do a calculation like: (a 1*5 vector of ones) multiply with (a 5*5 matrix) multiply with (a 5*1 vector of the outcomes of the five variables.)
As for the above operation, I have several operation problem:
- How can I save the covariance matrix with codes automatically, instead of entering the numbers one by one by hands?
- How can I do the above matrix multiplication to get the index? Sharing the codes will be the best for me.
subject | Q1 | Q2 | Q3 | Q4 | Q5 | Index |
1 | 3 | 3 | 1 | 2 | 4 | |
2 | 3 | 2 | 2 | 5 | 5 | |
3 | 4 | 4 | 2 | 4 | 6 | |
4 | 7 | 6 | 6 | 7 | 8 | |
5 | 8 | 7 | 3 | 7 | 4 | |
6 | 4 | 8 | 6 | 5 | 6 | |
7 | 1 | 2 | 3 | 2 | 1 | |
8 | 3 | 3 | 2 | 2 | 3 | |
9 | 5 | 4 | 1 | 7 | 6 | |
10 | 5 | 6 | 7 | 8 | 7 |
Wu
0 Response to How to multiply a vector of variables with a matrix?
Post a Comment