Take time to read this entire chapter and you'll understand why this verse begins with "therefore." David gives specific incidents that confirm God's interest in his life. How should he respond? With pride that he earned such attention? Surely we've seen people who think their actions have earned God's benevolent attention - are they as eager to give the same explanation for His disciplinary attention? David did.
God is, all the time, whether we acknowledge Him or not. He does not require our presence, our praise, our admittance of His grace or discipline. The praise we give Him does not change what He is, but does change us.
It is a good change, too. When we praise God, we focus on Him. It's not the same as giving thanks, where we focus on what we receive. Instead, we see His ability, His interest, His omnipotence.
Then, we can give thanks for His grace and mercy in our lives, which we can neither earn nor deserve. Praise God for His infinite mercy, available to whosoever believes.