Medication adherence is a well-known problem for pharmaceutical treatment of chronic diseases. Understanding how nonadherence affects treatment efficacy is made difficult by the ethics of clinical trials that force patients to skip medication doses, the unpredictable timing of missed doses by actual patients, and the many competing variables that can either mitigate or magnify the deleterious effects of nonadherence, such as pharmacokinetic absorption and elimination rates, dosing intervals, dose sizes, adherence rates, etc. In this paper, we formulate and analyze a mathematical model of the drug concentration in an imperfectly adherent patient. Our model takes the form of the standard single compartment pharmacokinetic model with first order absorption and elimination, except that the patient takes medication only at a given proportion of the prescribed dosing times. Doses are missed randomly, and we use stochastic analysis to study the resulting random drug level in the body. We then use our mathematical results to propose principles for designing drug regimens that are robust to nonadherence. In particular, we quantify the resiliency of extended release drugs to nonadherence, which is quite significant in some circumstances, and we show the benefit of taking a double dose following a missed dose if the drug absorption or elimination rate is slow compared to the dosing interval. We further use our results to compare some antiepileptic and antipsychotic drug regimens.