Sancti, I think your possible finds for grandparents and young Mary with them in 1871 are looking good!
The family you found and posted info on were headed up by a John Moffat Duncan and Helen Anderson. They look to have had a daughter called Mary (possible mother for Mary born in 1862?). This looks to be her entry
https://familysearch.org/pal:/MM9.1.1/XTGN-XMR I like the address for this family you found Sancti in 1851:
John M Duncan 26 Coal & Ironstone Miner, b. Newton, Midlothian
Helen Duncan 30 b. Tyrone, Ireland
Mary Duncan 8 b. Cromwell Gate, p?shire
Marrion Duncan 6
John M Duncan 4
William A Duncan 1
Address: School House, Muirhouse, Carriden
Monica