My book has an exercise that asks me two questions:
Be $X$ a variable following a normal distribution,
find $\mathbf{m_{x}}$ and $\mathbf{σ_{x}^2}$ knowing that $P(X \leq -1) = P(X > 3) = 9.12\%$
(the expected result is that $X \sim N(µ=1, σ²=1.5²)$)
then, calculate $\mathbf{P(X > 0)}$,
and $\mathbf{x}$ such as $P(X \leq x) = 3.60\%$
(the expected results are $P(X > 0) = 74.75\%$ and $x = -2$)
I attempted to solve that exercise with a Java program, using the NormalDistribution class from Apache Commons Maths which is convenient for that case, and only differs from the exercise by the fact that it takes for second parameter a standard deviation and not a variance.
package test.fr.ecoemploi.spark.inferentielle;
import java.io.Serializable;
import org.apache.commons.math3.distribution.;
import org.junit.jupiter.api.;
import static org.junit.jupiter.api.Assertions.;
import org.slf4j.;
/**
- Estimation de paramètres
/
public class EstimationParametresIT {
/* Logger. */
private static final Logger LOGGER = LoggerFactory.getLogger(EstimationParametresIT.class);
/**
* Estimation de Espérance mathématique m et de variance (σ²) d'une loi normale depuis deux valeurs :
* P(X > 3) = 0.0912 et P(X ≦ -1) = 0.0912
*
* Puis calcul de la probabilité de P(X > 0)
* enfin de x, tel que P(X < x) = 0.036
*/
@Test
@DisplayName("Estimation moyenne, variance loi normale depuis P")
public void estimationMoyenneVarianceLoiNormaleDepuisP() {
// On va se servir de la valeur centrée réduite qui suit une loi N(0,1)
// qui permet de substituer à X une valeur Y = (X - µ) / σ
NormalDistribution N = new NormalDistribution(0, 1); // μ=0, σ=1
double t1 = N.inverseCumulativeProbability(0.0912); // pour P(X ≦ -1) = 0.0912
double t2 = N.inverseCumulativeProbability(1 - 0.0912); // pour P(X > 3) = 0.0912
// Les deux équations qui ressortent de ces calculs sont :
// 3 - µ = 1.334σ (L1)
// -1 - µ = -1.334σ (L2)
// et l'on résout ce système en calculant L1 - L2 qui supprime µ et donne la valeur de σ :
double sigma = (3.0 - (-1.0)) / (t1 - t2);
double sigmaCarre = sigma * sigma;
double mu = 3.0 - t1 * sigma;
LOGGER.info("Cas 5 : L'espérance mᵧ σ² de X, sachant que P(X ≦ -1) = P(X > 3) = 9.12% valent m={} et σ²={}", mu, sigma);
assertEquals(1, mu, 0.01, "Mauvaise moyenne pour le cas 5"); // µ = 1
assertEquals(1.5 * 1.5, sigmaCarre, 0.01, "Mauvaise variance pour le cas 5"); // σ² = 1.5²
// Probabilité que P(X > 0) [sachant donc que X ~ N(µ=1, σ²=1.5²)]
// C'est 1 - F(0)
N = new NormalDistribution(1, 1.5); // μ=1, σ=1.5
double pSuperieur0 = 1 - N.cumulativeProbability(0);
assertEquals(0.7475, pSuperieur0, 0.01, "Mauvaise P(X > 0) pour le cas 5, quand les paramètres de N ont bien été définis");
// Et x, tel que P(X < x) = 0.036
double x = N.inverseCumulativeProbability(0.036);
LOGGER.info("P(X < -2) = {}", N.cumulativeProbability(-2));
assertEquals(-2, x, 0.01, "Mauvais x tel que P(X < x) = 0.036 pour le cas 5, quand les paramètres de N ont bien été définis");
}
}
Everything is running fine, except for the last question, where it finds
$x = -1.699$ for $P(X < x) = 0.036$,
saying that $P(X < -2) = 0.0228$
and I don't see where I did a mistake...