There is a major difference in the accident rate depending on where you ride in city traffic. Since changing my riding position in 1975 (when a motorist suddenly accelerated out of a gas station driveway broadsiding me as I was riding near the curb at about 20 mph), I've never been in a bike/car accident. Previously, I was in five, all the motorists "fault". I follow two simple rules.
First, keep away from parked car doors by the length of the door (unless going less than 8 mph). Just assume they are all open, since you never know when they would pop open.
Second, become as visible as possible by the rule "ride as far to the left as practical without unnecessarily inconveniencing automobiles." Related to visiblity is motorist estimation of your speed. Motorists often underestimate your speed when you're riding near the edge.
In contrast, the "ride as far to the right as possible" argument is mistakenly preached by some bicyclists. Their argument is based on not inconveniencing automobiles in any way. But their argument is not even applicable for most cases. For example, there are often many blocks of unused curbside parking spaces. They would place the bicycle maybe where the right wheel would be of a parked car (even though riding where the left wheels would be has no inconveniencing effect on motorists). This results in less visibility and motorist underestimation of bicyclist speed. It increases the chance of an accident by an oncoming motorist making a left turn in front of the bicyclist, or a motorist making a right turn and cutting off the bicyclist, or pulling out of a stop sign or driveway. Most experienced bicyclists will place the bicycle where the left wheel would be of a parked car.
The same reasoning applies in a bike lane or shoulder. I ride near the solid line. Other reasons for not riding near the edge are parallel drainage bars (which are illegal in California but still prevalent in cities like Oakland) and much more glass and debris.
Bicyclists can easily keep up with motorists in many cities like Berkeley or San Francisco if not going uphill. By far the safest place to ride in this case is in the lane of traffic, somewhat left of the center of the lane. The motorist is no more inconvenienced than if you would be just another car.
What about getting honked at? Occasionally it happens, often by juveniles. If you are slowing down the car, and it is safe to move over, then do so. Otherwise, don't. Be aware that for some, honking is a way of life, and they are not putting you down just because they honk at you.
What about getting rear ended? Statistically, only about 3% of daytime bicycle/car accidents are in the category of "motorist overtaking bicyclist". The motorists are looking forward for the most part. It is when they come out of intersections or driveways, or making a left or right turn, or about to pop the door that they resort to quick glancing eye movements. It is easy to underestimate speed or not register the presence of a bicyclist altogether when doing a quick glance, especially if the bicyclist is adjacent to the curb or a parked car. These situations pose the greatest threat to bicycle safety, not motorists from behind.
For night riding, a bright lamp not only make you more visible, it also has the illusion or interpretation of higher speed (i.e., less chance of the car turning left right in front of you). I use a 35 watt lamp on one bike for a dramatic difference.
Wearing a helmet is important, but this cannot substitute for riding in a safe manner as described in the two rules. I know of people with permanent knee damage as a result of not following rule #1.
Also see: list of bicycle articles.