How to replace the missing value using the correlation between x and y?

6 次查看(过去 30 天)
Hi,
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?

回答(2 个)

Ayush Singh
Ayush Singh 2022-6-18
Hi Omar,
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
  1 个评论
Omar Mfarij
Omar Mfarij 2022-6-18
编辑:Omar Mfarij 2022-6-18
Hi Ayush,
Thanks for answering!
I tried this method before, and it returns everything with NaN. That is why it was weird to me!
What I need is to not ignore the missing value. I need to replace this NaN value after I correlate between x and y. I can simply replace it with mean value and then correlate between x and y.
However, the correlation comes first and then replacing the missing value.

请先登录,再进行评论。


Jeff Miller
Jeff Miller 2022-6-20
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.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by