Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix multiplication with correlated vector components #40

Open
charvey23 opened this issue Oct 23, 2020 · 3 comments
Open

Matrix multiplication with correlated vector components #40

charvey23 opened this issue Oct 23, 2020 · 3 comments

Comments

@charvey23
Copy link

Very excited to have come across this code and implement it for my experimental analysis! I have been running into one issue when implementing the code. I have a vector of values each of which has an uncertainty associated with it and each value of the vector is correlated to the others. I have attempted to set correlation following this convention:
correl(vec[1],vec[2]) <- some_number
This does not throw an error however I then print correl(vec[1],vec[2]) and it returns NULL as if it had not been set.

My fix has been to break down all of my vector components (i.e. vec1 = vec[1], vec2 = vec[2]) then assign the correlation to vec1 and vec2. This is not a clean solution because I need to multiple this vector by a matrix so this leads to hand writing out matrix multiplications which is tedious. I really would like to keep the known correlation between the vector components because in matrix multiplication they are being added together and I would like to keep track of that error.

On that note, the matrix operator %*% does not seem to be overloaded to bring along the errors even if I didn't need to hand write out the equations due to the correlation issues.

Am I misunderstanding how to set correlations between different elements of a vector/matrix? If not, could I request this feature and the %*% overload be added if possible as it would save a lot of time?

@Enchufa2
Copy link
Member

The, let's say, philosophy of the package (which matches what the units package does) is that different vectors are different quantities. So the values of a vector are treated as independent observations of the same quantity. Therefore, correlations between components of the same vector are not currently supported.

On the other hand, matrix support is limited, because some operations (notably, %*%) are not generic, and thus we cannot write methods for them. We could overload them, but then the interaction between errors and units becomes messy, so we decided not to do that.

Could you further describe your use case to see if there's room in the current workflow for it?

@charvey23
Copy link
Author

charvey23 commented Oct 24, 2020

I understand entirely! In my case I have load cell channel readings that are 6 time series. I perform a time series analysis separately to extract the mean of each time series, uncertainty and correlation between each channel. I next need to convert the channels into their appropriate loads by multiplying the vector of the means of the channel by the 6x6 calibration matrix. This is why each value in my vector becomes a dependent value. As each channel mean has an associated uncertainty but also is correlated to the others I wanted to bring that through the calculation.

I should say that I was able to make the package work as is just by decomposing each operation. Not hand writing out the uncertainty propagation still saved me more time than the time spent writing out the matrix multiplication. I just wanted to check that I wasn't missing anything!

@Enchufa2
Copy link
Member

You didn't miss anything. :) So, yes, basically you need to decompose your operations. Note that putting those means in a list might save you some typing, because then you can just use a couple of loops to perform the operations (one for columns of the matrix, another for the list of means and the rows of the matrix).

Anyway, I can see it's still a bit cumbersome for this kind of use case. Correlated vector components is something that it may be worth considering for future releases, so let's keep this issue open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants