On Tuesday, the Dow Jones industrial average rose 72.17 points, or 0.4 percent, to 18,110.14. The Standard & Poor’s 500-stock index rose 5.84 points, or 0.3 percent, to 2,114.76. The Nasdaq edged down 4.82 points, or 0.1 percent, to 5,055.42.

Merck shares rose $2.88, or 5 percent, to $59.98. While the company’s profits fell 44 percent from a year ago, the results still handily beat analysts’ estimates. Adjusted earnings for Merck, the maker of the diabetes drugs Januvia and Janumet, were 85 cents a share versus the 75 cents expected by analysts. Other health care stocks also rose, including Aetna, the drug maker AbbVie and the laboratory equipment maker Waters.

Twitter was the center of some late-day drama when its quarterly results were unexpectedly released before the market closed. Twitter’s revenue missed analysts’ expectations, sending its shares down $9.39, or 18 percent, to $42.27.

The Nasdaq ended lower partly because of Apple, which fell $2.09, or 1.6 percent, to $130.56. On Monday, the company reported a record quarterly profit of $13.6 billion, but Apple’s outlook was not as rosy as some analysts had predicted.