"The Prophet Joseph Smith taught, “Being born again, comes by the Spirit of God through ordinances” (Teachings of Presidents of the Church: Joseph Smith [2007], 95).
What role did your baptism (being “born of water” [John 3:5]) and confirmation (being born “of the Spirit” [John 3:5]) play in being born again?" (Come, follow me)
Baptism represents death and a new life, when an individual is emerged in the water. Their sins are forgiven as they enter into the covenant. The Gift of the Holy Ghost endowed upon man at Confirmation allows an individual to have the spirit as a constant companion.
This is my understanding of the mind. Our minds are drawn to weaknesses and strengths, and people's minds get thoughts from two sources.
"Man could not act for himself save it should be that he was enticed by the one or the other." "For it must needs be, that there is an opposition in all things. If not so, my firstborn in the wilderness, righteousness could not be brought to pass, neither wickedness, neither holiness nor misery, neither good nor bad." (2 Nephi 2:16 & 11)
When man takes upon themselves the covenant of baptism, man have more consistent promptings of the Holy Ghost. They become more Godly. Confirmation, the ordinance, granting the Gift of the Holy Ghost, is key to being born again because God will guide his covenant people to a life where man can recognize in them that they have taken upon themselves the name of Christ, becoming a new person.