Linear Correlation in LM's Compositional Generalization and Hallucination