These final days could have been sour, resentful ones for John B. Anderson. He could have become bitter, caustic, preachy.

He has been ignored, even ridiculed. His independent presidential candidacy has become a political sideshow, attracting only passing notice. At every stop for a month, he has been tested, asked why he even bothers to continue.

These have been human tests more than political ones, but Anderson has survived them with dignity and grace. He has turned to humor, rather than anger.

Of his Republican opponent, he says, "I find Mr. Reagan to be a rather quaint figure, old-fashioned and outdated. I find it easy to believe when he was making films he was working for 18th Century Fox."

Of President Carter, he finds an unending amusement in his description -- in last Tuesday's presidential debate -- of discussing nuclear weaponry with his daughter, Amy. At every stop, Anderson apologizes, "I'd like to have my 9-year-old Susie with me here. But she's back home studying nuclear proliferation."

In these final days of the campaign he began 16 months ago, however, Anderson isn't running against Reagan or Carter. He's running against what he calls "fear" -- a fear he says is carefully cultivated by the Carter campaign that a vote for the Illinois congressman is a wasted vote.

"Don't believe the desperate last-minute efforts you're going to hear that a vote for John Anderson is a wasted vote," he declared as he boarded a train today for a whistlestop tour across the San Francisco peninsula from San Jose to San Francisco.

"Vote your future, not your fears," he added. "Send a message loud and clear to the two traditional parties that they may be asleep to the real needs of the American people but the American people have awakened."

This is Democratic country, and Carter needs to do well here to stand any chance of beating Reagan in his home state. But Anderson has been endorsed by two of the area's largest newspapers, the San Jose Mercury News and the Peninsula Times in Palo Alto. And when he arrived here there were signs in the crowd saying, "Anderson: Vote with a grin, not a grimace" and "A vote for Anderson is a vote for Anderson."

At each stop Anderson, standing at a railing at the rear of the colorfully decorated train, attacked the Carter campaign for running television and radio commercials criticizing his civil rights voting record in the House.

The ads falsify his record and are "libelous," Anderson said. "You ask any civil rights leader who was responsible for getting the 1968 open housing act and they will tell you John Anderson."

He said the ads show a sense of desperation in the Carter camp. "If there is one thing Jimmy Carter has, it is his finger on the pulse of Pat Caddell and the pulse must be beating hard."

Mitchell Rogovin, Anderson's chief counsel, told a news conference in Washington that Vice President Mondale has joined in attempts to convince blacks that Anderson voted against civil rights legislation. Rogovin said that Mondale in a radio interview, had falsely stated that Anderson voted against a 1964 fair housing act (there was no such bill), against the 1965 Voting Rights Act, against 1968 Civil Rights Act amendments and against financial assistance for older cities this year.

Becky Hendricks an aide to Carter media adviser Gerald Rafshoon, said the commercials are based on procedural votes and on Anderson's public remarks contained in a speech that supported the civil rights bill.

Anderson, in these final days, continues to insist he still has a chance of winning Tuesday, despite a Washington Post poll that shows his strength has dropped to 7 percent nationwide. However, he increasingly is conceding that he might have underestimated the difficulty of his task when he began his independent candidacy last April.

"It seems to me the mystique of the two-party system has been so crafted in the minds of many people as an institutional prop," Anderson told reporters in Stanford, Conn., the other day. "In an age of instability and rapid change, I think it's a little too much for people to comprehend and absorb my message in a relatively short time . . . That's been a very difficult thing to overcome -- the institutional framework we've lived with the last 200 years."