Inch by inch, day by day, a slow but dramatic change has occurred in the way John B. Anderson views Ronald Reagan

Reagan is no longer the chief villain in Anderson's speeches and interviews; President Carter is.

It is Carter who receives Anderson's most blistering attacks and caustic comments. It is Carter and his agents whom Anderson accuses of lacking leadership and conducting a fundamentally dishonest reelection campaign.

Perhaps more significantly, Anderson no longer expresses the slightest misgivings about the prospect of his independent candidacy throwing the election to the GOP standard-bearer. Often he seems more interested in making a political statement than actually winning the election.

Asked, for example, how he would feel the day after the election if it was clear Anderson votes had cost Carter reelection, the Illinois congressman told United Press International: "I would feel very, very good indeed because the American people will have freely exercised their right . . . There wouldn't be any reason for me to feel badly that the American people had freely decided what to do."

This is a dramatic turnabout for the candidate who five months ago said he would "do what was right" and consider dropping out of the race if he became convinced his candidacy would put Reagan in the White House.

"I care enough about this system and this country that I would not blindly and stubbornly and out of pure vanity and ambition stand in the way if the country had to choose between the lesser of two evils, making sure they got the lesser of two evils," Anderson had said.

At that time, Anderson made it clear he considered Reagan the greater evil. But since then Carter and his aides have sought to undermine Anderson's candidacy by launching an effort to keep him off the ballot in a number of states, refusing to participate in a debate with Anderson and Reagan, and portraying him as noting more than a "spoiler" in the election.

There is some political logic to this. Carter and Anderson, according to all polls, share much of the same Democratic constituency. To counter the Carter argument that a vote for Anderson is really a vote for Reagan, Anderson must convince voters that Carter is no better than Reagan, that the election of either would be equally disastrous to the nation.

But Anderson's reaction appears to be more emotional than strategic. His aides have instructed him to control his moral outrage, and balance his attacks on Reagan and Carter. He has tried, often pointedly so, to do this. But he has trouble containing his disdain for the president.

At Edwardsville High School Wednesday, for example, Anderson accused Carter of abdicating his responsibility for human rights in Korea and ignoring long-term problems of hunger and population control in the Third World.

"Here is President Carter using the incumbency like no other president before him," he told the student body. "There are more federal grants pouring out of Washington today than ever before, as if that were some great cornucopia being emptied all over the country."

Anderson's wife, Keke, normally an accurate barometer of the candidate's inner feelings, is more direct. On a long and bumpy flight from Denver to St. Louis Tuesday night, she told reporters she has grown to despise Carter.

"We're going to surprise him," she said. "What he doesn't realize is we don't have anything to lose and he has everything."

There is statistical evidence to support this. A Washington Post poll reported this week that although Anderson had the support of only 13 percent of the public, much of that support is concentrated in the Northeast, an area Carter must win if he is to be successful. Anderson currently draws 18 percent support in that region, enough to keep Carter from winning several key states. Additionally, 45 percent of all anderson supporters described themselves as Democrats.

There is another side to the shift in Anderson's attitude toward Carter. As it has hardened, so has the Carter camp's approach to Anderson. Rather than treating his independent candidacy with benigh neglect or as an outgrowth of any outpouring of public opinion, Carter aides have spared no effort to denigrate Anderson. Yesterday, for example, White House Counsel Lloyd Cutler told a breakfast meeting with reporters in Washington that Anderson "is an unwitting stalking horse for Reagan"

The president's steadfast refusal to join Anderson and Reagan in the League of Women Voters debate this Sunday fits into this same pattern.

Originally Anderson professed confidence that a public outcry would force Carter into the debate. When no such outcry developed, Anderson's rhetoric shifted.

By Tuesday, when he arrived in Boulder, Colo., the end of a western campaign swing, the Illinois Republican was sounding very much like Democratic Sen. Edward Kennedy sounded nine months ago when Carter refused to debate him. He complained he was being ignored, and forgotten.

To a crowd of several thousand college students, he testified: "Let me tell you, Teddy Kennedy, I know how it feels. It's awful hard to get him into the ring. As far as Jimmy Carter is concerned I'm the Stealth candidate. I don't show up on the Carter radar screen."