A student on an 「F」, 「J」, 「M」, or 「Q」 visa and substantially complies with the requirements of that visa. Immediate family members of a student are also counted as students for this purpose. Students are exempt from the 「substantial presence」 test for 5 years. But any part of a calendar year in which the student is present in the US counts as a full year.
Teacher or Trainee
A person who was primarily admitted to the US to teach or research (not study); is temporarily present with 「J」 or 「Q」 visa status. Teachers and trainees are exempt from the 「substantial presence」 test only if they have been in the US no more than 2 out of the last 6 years. Any part of a calendar year in which the person was present counts as a full year.
You may be a Resident for Tax Purposes if:
You are an F1 or J1 student (or F2 or J2 dependent) who entered the US in 2012 or earlier.
You are a J1 scholar (or J2 dependent of a J1 scholar) who entered the US in 2015 or earlier.
You are on an H1B or TN visa and were in the US at least 183 days in 2017.
You became a 「green card」 holder (US permanent resident) in 2017.