“It’s a shame what’s happened with the FBI,” President Trump told reporters yesterday, calling the bureau’s conduct “really, really disgraceful.” He was building on criticisms he’d levied earlier this month, when he labeled the Federal Bureau of Investigation “tainted” and said its reputation was “in tatters.” The president claimed that ideological bias was behind the FBI’s decisions about criminal investigations involving Hillary Clinton and Robert S. Mueller III’s ongoing special counsel investigation.

The president’s charges have been amplified by conservative pundits such as Hugh Hewitt and Republicans in Congress.

Is the FBI biased?

The legitimacy of our legal system depends upon apolitical law enforcement. Justice demands that all citizens be treated equally before the law. Calling the FBI biased is a very serious charge.

The president charges FBI bias because some attorneys and investigators on special counsel Mueller’s team gave campaign contributions to Democrats, including donations to Hillary Clinton’s campaign. Further, some top officials on Mueller’s team exchanged a series of anti-Trump texts.

However, Mueller and Rod J. Rosenstein, who appointed Mueller, are both longtime Republicans. The former FBI director, James B. Comey, and the current director, Christopher A. Wray, have both previously donated to Republicans.

All agencies this size include employees who donate to Democrats and others who donate to Republicans — donations that are protected as part of their free-speech rights. That does not tell us enough to judge bias.

Here’s how we did our research

To look more deeply into this question of ideological leanings within federal agencies, at the end of 2014, Mark Richardson of James Madison University and I surveyed 3,500 top federal executives with the help of Charles Cameron at Princeton and nonprofit and government partners. Specifically, we asked federal executives to name the agencies they worked with the most, and then asked: “In your opinion, do the policy views of the following agencies tend to slant liberal, slant conservative, or neither consistently in both Democratic and Republican administrations?”

In a forthcoming paper with Joshua Clinton, we aggregate these ratings with a statistical measurement model to generate estimates of agency ideology. On our scale, -2 would indicate the most liberal, and 2 the most conservative. The figure below shows the agency ideology estimates we received for the 20 most conservative and liberal agencies out of the 165 agencies measured. The FBI ranks as one of the most conservative. This confirms the evidence suggested by the party registration and campaign donations of top agency officials such as Mueller, Rosenstein, Comey and Wray.

These numbers also correlate very highly with what the executives reported about their own ideology and partisanship. We found no evidence (at all) of widespread liberal politicization among high level executives within the FBI.

Of course, this data is current as of the start of 2015. Could the Obama administration, including Eric H. Holder Jr. at the head of the Justice Department, have politicized the FBI and shifted it to the left between 2015 and the inauguration in 2017?

It’s hard to see how. The director is the only politically appointed employee among 37,000 people who work in the FBI. Promoting individuals because of their political views is prohibited by civil service law and regulation; presumably, had a massive politically motivated change occurred in just two years, outraged employees would have let news about it leak out.

As you can also see in the figure above, the defense, intelligence and law enforcement agencies are all among the most conservative bureaucracies in the executive branch. And yet the president has attacked the intelligence agencies as well.

This suggests that Trump’s attacks when he runs into bureaucratic resistance do not seem to be related to ideology. The president’s public repudiation of the intelligence services’ findings about Russian attempts to influence the 2016 U.S. election and his attempts to influence law enforcement’s efforts by urging that Hillary Clinton be investigated and arrested may have put him at odds with civil service employees’ belief in their own professionalism.

Is Trump correct that the FBI’s reputation is in tatters?

In the same research, we also asked federal executives, “In your view, how skilled are the workforces of the following agencies?” In this case, answers ranged from “not at all skilled” to “very skilled.” (They could also have reported “don’t know.”) We asked each respondent about agencies they knew something about in the course of their work.

When we aggregated these ratings across the executive establishment — again using modern scaling techniques — the FBI ranked as among the most skilled, in the top quarter of all agencies.

Again, this was in 2015. However, leadership and morale appear to have improved since then. According to the magazine Government Executive:

In the Partnership for Public Service’s 2016 Best Places to Work rankings, based on data from the annual Federal Employee Viewpoint Survey, the FBI was rated in the top third out of 305 components across government and fourth out of 15 law enforcement agencies. On an index score out of 100, FBI employees gave their agency a score of 68.7. That was up from 65.5 in 2013, the year Comey took over as director.

The civil service professionals who work in government are obligated to serve not only elected officials like the president, but also the Constitution and the law. As a result, officials who expect these agencies to respond to their wishes may find their actions puzzling and unresponsive.

David E. Lewis is the William R. Kenan Jr. Professor at Vanderbilt University and author of “The Politics of Presidential Appointments” (Princeton, 2008). He can be reached at david.e.lewis@vanderbilt.edu.