A large number of federal research positions are located at national labs. National labs have a higher billing rate than most universities. (An example would be a 100 - 200% billing rate at a national lab vs. 50 - 75% at a university.) Locating the researchers at an American university will also allow students better opportunities to work with the agencies they wish to work for after graduation.
Undergraduate and graduate students are also very creative and innovative. They are able perform some of the same research and development work as full time government employees, but at substantially less cost because they will work at hourly rates with no benefits.
Universities also have more lax security restrictions for the researchers than National Labs. A significant amount of research is done on topics that do not need a high level of security that is required at all national labs. (examples: weather, climate, geography, geology, general physics, applied mathematics, transportation, material science, ...)