As annoying as Networks are most of the time, sometimes they stick with quality despite the ratings because they believe in a show.
The Office, by all normal logic, wouldn't have made it past the third episode based on its ratings. But NBC believed in the show and the ratings came around.
Also, shows like Arrested Development, The Wire, and Friday Night Lights, some of the best TV shows in decades, were continually renewed despite very bad ratings.
I hate some of the networks as much as anyone, but I do think they have more taste than they are given credit for. Maybe they push the terribleness of American Idol and such to compensate for keeping the Arrested Developments in the world.