This is actually a very nice question, and although it appears deceptively simple, it is not.
The problem
Let $X \sim N(\mu, \sigma^2)$ with pdf $f(x)$, and let $s>0$ and $c$ denote known constants. That is:
Find the pdf of $W$, where:
$$W = \begin{cases} X+s & \text{if } X \leq c \\ X & \text{if } X > c \end{cases}$$
The problem is not as simple as it looks, because the transformation from $X$ to $W$ is NOT one to one. In particular, there is a zone of overlap where both branches of the piecewise function can contribute to the same value of $W$.
Solution
The cdf of $W$ is simply $P(W<w)$:
where:
- the
Prob
function is from the mathStatica package for Mathematica, which the OP is using;
- the
True
zone denotes $c<w<c+s$.
The pdf of $W$ is the derivative of the cdf wrt $w$:
with domain of support:
domain[pdf] = {w, -Infinity, Infinity} && {Element[c, Reals], s > 0};
All done.
Plotting the pdf of $W$
Given parameters, say:
params = {μ -> 2, σ -> 1, s -> 3, c -> 2};
... here is a plot of the pdf of $W$:
PlotDensity[pdf /. params, {w, -1, 7}]
Monte Carlo check
Here are some different parameters ($c$ has changed):
params = {μ -> 2, σ -> 1, s -> 3, c -> 2.8};
Here are $500,000$ pseudo-random drawings from $X$ and $W$:
xdata = RandomReal[NormalDistribution[2, 1], {500000}];
wdata = Map[If[# < 2.8, # + 3, #] &, xdata];
Now we can compare:
- the theoretical pdf (dashed RED curve) derived above
- to the empirical pdf (squiggly BLUE curve)
...
FrequencyPlot[wdata, {0, 7, .02}, pdf /. params]
Looks fine. :)
If you don't have mathStatica ...
If you don't have mathStatica, one can still obtain the transformed pdf using just Mathematica with:
mmasol = PDF[TransformedDistribution[Piecewise[{{x + s, x <= c}, {x, x > c}}],
Distributed[x, NormalDistribution[μ, σ]],
Assumptions -> {Element[c, Reals], s > 0}], w]
... but the solution produced is not very natural, and is expressed in terms of unnecessary DiracDelta
functions, UnitStep
functions and Erf
functions:
(1/2)*DiracDelta[c + s - w]*(1 + Erf[(w - μ)/(Sqrt[2]*σ)] -
(Erf[(c - μ)/(Sqrt[2]*σ)] - Erf[(w - μ)/(Sqrt[2]*σ)] -
Erfc[(s - w + μ)/(Sqrt[2]*σ)])*(-1 + UnitStep[c - w])) +(1/2)*DiracDelta[ c - w]*(-Erfc[(s - w + μ)/(Sqrt[2]*σ)] + (-Erf[(c - μ)/(Sqrt[2]*σ)] + Erf[(w - μ)/(Sqrt[2]*σ)] +
Erfc[(s - w + μ)/(Sqrt[2]*σ)])*(1 -
UnitStep[-c - s + w])) + (1/(Sqrt[2*Pi]*σ))*(UnitStep[c - w]/
E^((s - w + μ)^2/(2*σ^2)) +
(E^(-((w - μ)^2/(2*σ^2))) +
E^(-((s - w + μ)^2/(2*σ^2))))*(1 -
UnitStep[c - w])* (1 - UnitStep[-c - s + w]) +
UnitStep[-c - s + w]/E^((w - μ)^2/(2*σ^2)))