How to replace the missing value using the correlation between x and y?
2 views (last 30 days)
Let's say I have this data:
T x y
------ ------ ------
1 150 7.2
2 150 7.1
3 210 NaN
4 235 6.1
5 280 5.5
I tried to use correlation on MATLAB but it gives me weired output where all the values are NaNs with size 5x5
Is there a way to replace this missing value using the correlation between x and y?
Ayush Singh on 18 Jun 2022
I understand from your question that you want to have the correlation between x and y but at the same time emit the NaN values.
You could use 'rows' , 'complete' name -pair values to avoid the rows with NaN values.
CorrXY = corr (X , Y, 'rows', 'complete') % Here X and Y are the two variables for which you are finding the correlation
Jeff Miller on 20 Jun 2022
Omar, if I understand what you are trying to do, I would suggest:
- Form a reduced dataset where you drop all rows with NANs. These rows cannot tell you anything about the relation between X and Y since you don't have Y.
- Using regress or fitlm, fit a linear model to predict Y from X within this reduced dataset.
- Going back to the full dataset, compute the predicted Y for each case with NAN based on its X and the linear model just fit.