Exactly the way you figured it out. Not all stims/tics are caused by anxiety, but it can be a factor, and should be a consideration unless it's obviously medication induced like in your case.
My son started to stimulant at 5. No medications until just before he turned 13. His "dying coyote" phase was at 11-12. He's not always anxious when he stims. It's just something he does because it makes him feel good.