Ra is extremely sensitive to sampling step and length.
You might be getting different results because you're measuring at very different scales, with differing lateral sampling steps.
Another hypothesis is that it depends on the probe you're using for optical profilometry : for instance, if your material is tranparent (a varnish) and you're using a white light aberration probe, you might be measuring the support beneath the actual surface layer.
Get more info on the sampling lengths and steps. If you're comparing a 10mm long profile by optical profilometry to a 100 nm long profile using AFM, no wonder you're getting different values.