I understand that a nonresident alien is taxed either using flat rates, or using potentially lowered rates if the US has a tax treaty with her country of residency.
Question: how is the country of residency determined?
Context: The examples here and elsewhere assume that a nonresident alien will be traveling to the US from their country of citizenship, which simplifies things a lot. My case is slightly more complicated: I am an Indian national who presently lives in Singapore and has filed taxes in Singapore for the last three years. I have also filed taxes in India for the last six years. I am about to leave Singapore permanently and head to the US. In the US's eyes, is my country of residency India or Singapore?
Suppose it is Singapore, since that's the last place I have drawn substantial salary and was last a tax resident and a physical resident. In that case, is there a time during my degree when my residency switches to India? I may never visit Singapore again, but I will likely visit India annually while completing a 6-year degree in the US.