Prior expectation affects posterior experience and emotions. This psychological effect is called expectation effect. Two different patterns of expectation effect, contrast and assimilation, were observed. In this talk, I proposed a mathematical model of the expectation effect that explains the conditions of contrast and assimilation[1]. I hypothesized that perceived variable is estimated using a Bayes' inference of prior prediction and likelihood based on sensory stimuli. I formalized the expectation effect as a function of three factors: expectation error, prediction uncertainty, and external noise. Both the results of the computer simulation using the model and the experiment using Size-weight illusion (SWI) revealed that 1) the pattern of expectation effect shifted from assimilation to contrast as the prediction error increased, 2) uncertainty decreased the extent of the expectation effect, 3) and external noise increased the assimilation. Furthermore, I discussed the meanings of expectation effect from an ecological point of view.