In Puerto Rico, prior to the Spanish-American War, there was a sentiment of Independence from Spain. As a fact, there was an attempt to revolution in the mid 1800s, the so called "Grito de Lares". The Spanish troops were able to defeat the demonstrators.
Several of the pro-indenpendence and pro autonomy politicians made trips to the USA to gain the support of the US for their cause. The US saw that the Islands of Cuba and Puerto Rico could be an economic asset to their own goals. In addition, by helping these Islands to gain independence, they could stop European nations having territories in America (refer to the Monroe Doctrine - America for the Americans).
Anyway, during the S-A War, the US troops invaded Puerto Rico from the South while the Navy bombarded San Juan. Several Spanish Regiments confromted the American troops but without success. In addition, some of the Puertoricans that supported the Spanish Crown confronted the american troops. Still, they were no match for the American troops.
The US received the Phillipines, Guam, Cuba, and Puerto Rico as war bounty. They gave the independence to the Phillipines and Cuba but kept the rights to military bases. As for Guam and Puerto Rico, they kept them as military possessions. I do not know why Guam, but in the case of Puerto Rico, the US saw the Island as a Strategic location.
The debate regarding Imperialism and colonialism as been going on for years. I'll say that at this time, Puerto Rico is to the US the same as Quebec is to Canada.