Yang-Mills vs Einstein-Hilbert Action The classical Yang-Mills action is of the form
$$S=\frac{1}{2g^2}\int_{\mathcal{M}}\text{tr}\left[F\wedge\star F\right]\\
=\frac{1}{4g^2}\int\mathrm{d}^dx\sqrt{g}\,\text{tr}\left[F^{\mu\nu}F_{\mu\nu}\right],$$
where $F=dA+A\wedge A$ is the Yang-Mills field strength $2$-form and $g$ is a coupling constant that is irrelevant in the classical description.
Now, the classical Einstein-Hilbert action takes the form
$$S=\frac{1}{2\kappa}\int_{\mathcal{M}}\star\mathcal{R}=\frac{1}{2\kappa}\int\mathrm{d}^dx\sqrt{g}\,\mathcal{R},$$
where $\mathcal{R}=\text{tr}_g(\text{tr}(R))=R^{\mu\nu}_{\,\,\,\,\mu\nu}$ is the Ricci scalar curvature of the manifold and $R$ represents the Riemann curvature tensor, and $\kappa=8\pi G$ is again a coupling constant.
My question is this: why is the Einstein-Hilbert action linear in the curvature tensor while the Yang-Mills action is quadratic in the gauge-field curvature tensor? Both theories are required to be invariant under a specific set of transformations (Gauge transformations for Yang-Mills and diffeomorphisms for Einstein gravity), so it seems like their actions should be of a similar form (I know that gravity isn't exactly the gauge theory of diffeomorphisms, but this still seems odd to me). For instance, is there an a priori reason why we don't write down
$$S=\frac{1}{2\kappa'}\int\text{tr}\left[R\wedge\star R\right]=\frac{1}{4\kappa'}\int\mathrm{d}^dx\sqrt{g}\,g^{\alpha\mu}g^{\beta\nu}R^{\rho}_{\,\,\alpha\sigma\beta}R^{\sigma}_{\,\,\mu\rho\nu}$$
instead of the obvious reason that it doesn't give the Einstein equations?
Any insight into this would be excellent. Thanks!
Note: This question is essentially the last part of Is GR the Gauge Theory of Diffeomorphisms? Why is the EH action linear in the Curvature?. However, this question was never answered and was closed since the first few parts were essentially duplicates.
 A: Your are raising a legitimate question, as from an effective field theory point of view, all symmetry-permitting action terms should be included. 
However, there is a catch when it comes to an action linear in Yang-Mills curvature $F$: you can't possibly contract the  Lorentz indices of  antisymmetric $F$ with symmetric metric $g$. 
For special unitary group related YM fields there is another hindrance:  $Tr\langle F\rangle $ is identically zero since special unitary groups are traceless, while the YM action (with two Fs) does not experience the said issue.
The action you mentioned with two Riemann curvature $R$ tensors 
is perfectly allowed, only that this term is highly suppressed  at low energies so that it is not relevant under normal circumstances. Note that these high order $R$ terms play an important role at the embryonic stage of our universe, which is usually overlooked for the prevalent cosmological models. 
A: In Yang-Mills, the gauge connection plays the role of a potential and the curvature form plays the role of a "field strength".
In GR, the metric tensor plays the role of a potential, and the connection plays the role of a field strength.
This is why, in particular, the gravitational force is not a real force, as the connection is not gauge-covariant. Of course, we say that there is nonzero gravity somewhere, if the curvature is nonzero there, but that's because the curvature tensor obstructs the trivialization of the connection.
Furthermore, you should look into Ostrogradskij-instability. Because in YM, the gauge connection is the potential, and the curvature is the field strength, a lagrangian containing any function of the field strength will procude second order field equations at most.
But for gravity, the curvature tensor contains second derivatives of the metric, so if you don't restrict the curvature expression's form, Ostrogradskij instability will kick in. A lagrangian that is linear in the second metric derivatives avoids this issue.
