Inverse transform method, theoretical graph not matching sample Suppose a density function is
$$f_X(x)=\left\{\begin{aligned}\frac{1}{(1+x)^2} & \quad x \ge 0 \\ 0 & \quad \text{otherwise.}\end{aligned}\right.$$
I am trying to write an algorithm to generate a sample of size $n = 10^4$ from this distribution by using the inverse transform method. Why does my histogram not look "nice" like the one below?
n <- 10^4
u <- runif(n)
x <- (-u)/(u-1)
# histogram
hist(x, prob = TRUE, main = bquote(f(x)==1/((1+x)^2))) #density histogram of sample
y <- seq(0, 100, .01)
lines(y, 1/((1+y)^2))    #density curve f(x)

Output:

Nice histogram for another density:


I don't see anything wrong with the implementation of the inverse transform method.
The first distribution is strongly right-skewed. If you run your simulation, you should see that roughly 95% of observations will be smaller than 19 (=0.95/0.05), but the largest sample is typically much larger, say a few thousand.
So, most samples are small, but there is a small probability of very large samples. The bars on a histogram have a fixed width, so you end up with the first bar containing most observations, and then several other bars on the right that are just tiny slivers of rectangles.
For this specific distribution, since the support is the positive real numbers, you could plot the histogram on a log scale to see it better, but you'll need to derive the transformed density. If $X$ has density:
$$f_X(x) = \frac{1}{(1+x)^2}, \quad x \geq 0$$
Then you can check that $Y := \log(X)$ has density:
$$f_Y(y) = \frac{e^y}{(1+e^y)^2}, y \in \mathbb{R}$$
Then if you plot it:
hist(log(x), prob = TRUE, main = "Histogram for Y", xlab = "Y")
z <- seq(-10,10,length.out = 100)
lines(z, (exp(z)/(1+exp(z))^2))


You can see that they are in fairly good agreement.
For reference, the distribution of $Y$ is called the logistic distribution, and $X$ has the log-logistic distribution.
