Oxygen gains two electrons when it bonds to form a complete outer shell and magnesium loses two electrons when bonding to gain its full outer shell.
As electrons are negative, the oxygen (which gains electrons) will become negative and the magnesium (which loses electrons) will become positive.
The negative and positive ions will then attract to one another due to the magnetic pull of the positive and negative.
Scientists should control most possible variables in experiments to get the most valid and correct data. If many variables are included in experiments it is more difficult to interpret what is causing a different outcome.
The logarithm from my understanding can never be negative. You can check this on a calculator. You may have a negative if it is shown as -(log x).