Why does acceleration due to gravity $g$ vary with altitude, height, and depth from a direct square relationship inside the earth (below the earth's surface) to an inverse square relationship above the earth's surface? Further, how did we get the following equations for the below the earth and the above the earth, respectively?
$$ \begin{aligned}g'=g\left[ 1-\dfrac{x}{R}\right] \ldots \left( 1\right) \\ g'=g\left[ 1-\dfrac{2x}{R}\right] \ldots \left( 2\right) \end{aligned} $$
where $g'=g\left[ 1-\dfrac{x}{R}\right]$ is $g$ at depth $x$ and $g'=g\left[ 1-\dfrac{2x}{R}\right]$ is $g$ at altitude $x$.
