First-principles theory of inelastic currents in a scanning tunneling microscope