"I should like to save the Shire, if I could - though there have been times when I thought the inhabitants too stupid and dull for words, and have felt that an earthquake or an invasion of dragons might be good for them. But I don't feel like that now. I feel that as long as the Shire lies behind, safe and comfortable, I shall find wandering more bearable: I shall know that somewhere there is a firm foothold, even if my feet cannot stand there again."
Ever since the death of Gandalf, Frodo began to have nightmares of it – they never left him, worsened along with everything else his small body bore. Because of this, he often found a coping method, that grew further by the madness of the Ring of his voice in his mind, combating the voice of Sauron and the Nine Riders. He would focus on what Gandalf would advise, like he always did, if he were there. If he were alive.
It was his only way of coping with the unbearable grief and sense of it being his fault that Gandalf fell in Moria, his fault that he sacrificed himself for the cause that Frodo never imagined he would be at the forefront of.