For this project, I will be using the rejection sampling method to simulate random values from a continuous probability distribution with the pdf f(x) = x^2/9 for 0 < x < 3.
## [1] 2.8214019 2.8705000 0.7382632 2.6686179 2.8890727 2.2753786 2.3967745
## [8] 1.6828440 2.6851361 1.9953456 2.4439201 2.3830270 2.1305472 1.4259497
## [15] 1.0553937 2.9548709 2.6594072 2.3468829 1.7999669 2.7433146 1.2320693
## [22] 2.8058994 2.1617888 1.9436804 2.9394658 2.5281880 2.5423595 1.7158059
## [29] 1.9499555 2.2210031 1.8899192 2.6240470 2.5193033 2.1248710 2.9569227
## [36] 2.8119423 1.6262411 2.9021951 1.7791370 2.6131302 2.9156269 2.2757795
## [43] 2.9464211 2.3537258 0.4699106 2.1398370 2.5071265 2.5612901 2.9982136
## [50] 1.8517058
## Sample Mean: 2.254599
## Sample Standard Deviation: 0.5766685
## Probability That X < 2: 0.2936
## Theoretical Mean: 2.25
## Theoretical Standard Deviation: 0.5809475
## Theoretical Probability That X < 2: 0.2962963
## [1] 0.669159
The histogram shows a distribution skewed to the right, which is consistent with the shape of the true probability density function f(x) = x^2/9 over the interval (0,3).
The red curve (true PDF) overlays the histogram well, indicating the the sampled values closely align with the theoretical values.
The sample mean (~ 2.2546) is extremely close to the theoretical mean (2.25).
The sample standard deviation (~ 0.5767) is extremely close to the theoretical standard deviation (~ 0.5809).
The sample probability that X < 2 (0.2936) is extremely close to the theoretical probability that X < 2 (0.2963).
The rejection rate (~ 0.669) is high and means I would need to generate ~30,300 candidates to get 10,000 accepted samples. This is typical for rejection sampling when the proposal distribution is uniform and the target distribtuion is skewed.