How would you detect if WordPress is installed in a subdirectory (not root)?

You need to check if the siteurl differs from the home URL:

if ( get_option( 'siteurl' ) !== get_option( 'home' ) ) { // whatever

This also works if home is a subdirectory of the root, with WordPress installed in yet another subdirectory. For example: domain.com/blog (URL) and domain.com/blog/wordpress (siteurl).