Data correlation matrix is singular
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 274
- PR merge metrics
- No merged PRs in 30d
Description
So I might be missing some theoretical concept, but want to clear it now.
I have a dataset, take the fork scenario.
My data is generated as follows:
#c) Fork
# Create the graph describing the causal structure
graph = """graph[directed 1 node[id "W" label "W"]
node[id "X" label "X"]
node[id "Y" label "Y"]
edge[source "X" target "Y"]
edge[source "X" target "W"]]""".replace('\n', '')
# # Generate the data
X = np.random.randn(N_SAMPLES)
W = 0.5*X
Y = 0.8*X
# Data to df
df = pd.DataFrame(np.vstack([X, W, Y]).T, columns=['X', 'W', 'Y'])
print(df.head(10))
# Create a model
model = CausalModel(
data=df,
treatment=['X'],
outcome=['Y'],
# common_causes=['Z'],
graph=graph
)
plt.figure(figsize=(5,5))
model.view_model()
plt.show()
Clearly, the rank is 1 and you can see in the fig below
When I perform causal discovery using PC, I get 'ValueError: Data correlation matrix is singular. Cannot run fisherz test. Please check your data.'
Below you can find the code which I'm using to perform causal discovery using PC.
from causallearn.search.ConstraintBased.PC import pc
from causallearn.utils.cit import fisherz
from causallearn.utils.GraphUtils import GraphUtils
# default parameters
cg = pc(df.to_numpy(), 0.05, fisherz)
# visualization using pydot
cg.draw_pydot_graph(labels=df.columns)
# or save the graph
pyd = GraphUtils.to_pydot(cg.G, labels=df.columns)
pyd.write_png('pc_fork.png')
Need help in understanding it, although I think as the data is correlated and singular I'm getting this error, however, how can I resolve this error without adding some random noise in the variables W & Y. Isn't causal discovery possible in my case?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied Python reproducer and the causallearn.search.ConstraintBased.PC.pc and causallearn.utils.cit.fisherz entry points, then trace where the singular correlation matrix is rejected. Determine the supported behavior for perfectly dependent variables and add or update coverage so the reproducer has a defined outcome without requiring arbitrary noise.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, pandas, python
- Domain
- data, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100