-
More Boring Updates
-
I have typed up my phone log with the specialty pharmacy and have organized it in a spreadsheet. According to a call that I received from K. at the specialty pharmacy at 2018-07-19 14:19, the medication will be delivered on Tuesday. I’ll believe that when I see it. Allegedly there is no way for me to get the tracking number until Tuesday morning.
-
Future is still very hard to predict. Even more disturbing, the world’s bestest methods for predicting the future seem very… simple. Maybe they are just so very parsimonious and not trivial? I really, really, really don’t want to build some sort of bullshit overfit future out of machine learning buzzwords. On the plus side, since the current methods of future prediction are so… parsimonious, the modification thereof is within my skillset.
-
Not as boring: Our federal government has sent four planes to San Diego this week to deport people to Central America. Most are going to Honduras, but one was going to Guatemala. I went out to take a picture of today’s deportation plane, but the auto-focus settings on my overly-complicated camera were not set up correctly for taking good pictures of airplanes, so the shots were all unacceptably out of focus. Relatedly: I am starting to feel like I should pay someone to explain all of my camera’s features to me because the documentation is terrible.
-
Boring to everyone except me: Caught seven Unown in Pokémon Go the other day.
-
Things that happened a while ago and that I should have written about at the time: Three members of the IMO team from Uzbekistan were disqualified for cheating. Lots of people with incomplete information had a lot of opinions about this.
-
Haven’t yet made it to the airport to take pictures of the planes with Shark Week livery.
-
-
Lucy and the Football
There is not much to say about what has been going on lately. The specialty pharmacy is making me feel like a fool. They keep telling me that they are processing my prescription and that I should hear from them in a few days, and then when I call after a few days, they tell me that it will be a few more days. This company is, allegedly, the world leader in pharmaceutical supply chain management. And they can not manage to put my medicine in a FedEx box and send it to me. For those keeping track at home, my prescription was faxed to them 19 days ago.
Yesterday I spent an hour on hold for them to tell me that they don’t know why they haven’t sent me my medication. But they promise that they will call me today.
Also yesterday I was trying to buy a hard drive to serve as an extra back-up drive for my new-to-me six-year-old laptop. I wasn’t even looking for one of the Prime Day deals, I was just trying to use the $10 credit that I got from shopping at Whole Foods. But all I could see on Amazon’s site were 503 errors and pictures of dogs. AWS claims that it has all sorts of magical load balancers and whatnot to handle sudden spikes in traffic. And, yet, I had to wait several hours to buy a hard drive.
Fortunately, no other companies in the Fortune 10 let me down by failing at one of their core businesses.
But I look forward to being disappointed again later this week.
-
Where Did the Week Go?
-
Spent far too much time debugging what turned out to be a really stupid problem. I had a bound defined by a min when it should have been a max.
-
Headaches. Last night I had a headache so bad that it woke me up around midnight. This was not the only headache this week.
-
Kafkaesque conversations with the specialty pharmacy. I called them today, and I gave them my name and date of birth so that they could find my file and explain to me why the pharmacist still hasn’t called. They looked up my file and reviewed the notes. The pharmacist hasn’t called my because my file is not complete. They have my prescription and my paperwork from the drug company, but they are missing my name and date of birth and that my doctor’s office needed to fax them this information. (There is someone at my doctor’s office who deals with this sort of stuff, so I had her call them. I also emailed her a copy of my phone log.)
-
My insurance covers this medication. The drug company has given me a copay card. I am running out of patience for this program that gives me two months for free but doesn’t actually give me anything but wastes my time by having me call up and wait on hold for someone to give me the run-around. I could get this medicine for $5 from a different mail-order pharmacy.
-
Hiring stuff. I have a form letter that I send to people who do not send the information that is requested in the job ad. Like a cover letter. The ad says to send a resume and a cover letter. Please send a cover letter. Please? (We also ask what your favorite math problem is, but you can write about that in the cover letter. Maybe you don’t know what to put in a cover letter? In this one you can write about your favorite math problem because we specifically asked you to do that.)
-
I made some really lovely graphs about the past (to better understand the future). The future is still hazy and confusing.
-
Someone quit, but technically he is on vacation for the rest of the month. Or maybe he is “sick” for the rest of the month.
-
Got the new-to-me (six-year-old) laptop on Thursday. Need to finish setting it up and installing everything on it this weekend. I’m thinking that I’m going to try to install ImageMagick with homebrew so that I can do everything with one package installer.
-
-
Using R to Apply a Function to Each Subset
tl;dr
ave
is my new best friend.So far I am bravely surviving First Summer. It is supposed to get up to 90 today, and it will be in the 80s for most of the rest of the week. I have several cans of lightly flavored fizzy water (and air conditioning).
Conventional wisdom says that every time you think that you want to use a loop in R, you are wrong. Your mind is thinking, “For each level of my categorical variable, find the subset of my data that corresponds to that level, calculate some quantity on the rows in this subset, store this variable in a new column, and then put everything back together.” But there is someone out there who will judge you if you explicitly do this.
I can now solve this problem in just one line!
But, wait, there’s more! Sometimes I will do an
aggregate
followed by amerge
, and it will make me feel bad about myself. In my heart of hearts I know that instead ofSELECT
ing so much stuff and then doing anaggregate
followed by amerge,
I should have written a better query and made more clever use ofJOIN
andGROUP BY
.Let’s imagine that you have the following data:
set.seed(10) values <- runif(20, 1, 100) labels <- c(rep("a", 10), rep("b", 7), rep("c", 3)) my_data <- data.frame(values=values, labels=labels)
Suppose you want to add a new column to this dataframe with the average of the values for each label. So you still want 20 rows, but you want all of the
a
rows to have the value 38.98794 inmy_data$average
, theb
rows have a value of 40.14164 inmy_data$average
and so on and so forth. Old me would have used anaggregate
to find the average for eachlabel
and then used amerge
(onlabel
) to put everything back together.New me does it with the classic application of the
ave
function.my_data$average <- ave(my_data$values, my_data$labels, FUN = mean)
NB: If you have
NA
s in your data, this can rain sadness upon you.For example, if you kill one of your data points with
my_data$values[2] <- NA
and try this again, you will getNA
for the average of thea
values, following the usual operation of themean()
function. However, you can ignore theNA
s with the following.my_data$average <- ave(my_data$values, my_data$labels, FUN = function(x) mean(x, na.rm=TRUE))
But nothing requires us to only calculate averages. We can calculate anything on our subsets! Without ending up with everything collapsed into its group (like happens with
aggregate
)!In my particular case, I needed to rank the values within each subset. You can rank the values within each subset from high-to-low with
my_data$rank <- ave(my_data$values, my_data$labels, FUN = function(x) rank(-x, ties.method = "first"))
ave
is now my go-to function for applying something to subsets of my data, especially when I do not feel like fighting with the*apply
family of functions. I’m sure that everyone in the*apply
family is a lovely function, but I have so far been unable to use them to quickly and efficiently write code that works. So for now I’m sticking withave
.(Aside: How would you pronounce
ave
? I say av, like the beginning of average or avenue, like how I would say Mass Ave. But one of the cats suggests that it should rhyme with knave, and the other one insists on ahv-ay, like in Ave Maria.)
-
Making it Easier to Do the Right Thing
I know that a lot of the code that I write is disappointing. One of the first things that you learn in a computer science class is how to wrap up things into modular little bits and turn everything into a function.
But since most of my code only runs once (after it is working) and answers a specific question (How many students satisfy these conditions, Make a spreadsheet that we can use in a mail merge, Is there a statistically significant difference between this situation and that situation, etc.), there is no need to properly modularize it. Even the SQL queries are a little bit different from one problem to the next. Do students who switched classes count as drops? Sometimes yes, sometimes no.
Yesterday, however, my so-far-futile efforts to predict the future inspired me to make a function! It is not a small function. It is roughly 60 lines long. If I were taking an undergraduate computer science class, it would probably be broken down into smaller functions.
So what inspired me to create this function? My future needed a lot more past. My new function asks the database about the past, and then it arranges the past into a format that can be understood by standard future-prediction algorithms. Not only did I feel a deep sense of existential dread even thinking about copy-pasting a 60-line chunk of code, I knew that I was going to have name collisions. And the easiest way for me to deal with that was to hide all the names of the intermediate variables inside the scope of the function. The downside was that I had to do fussy stuff with string manipulation in order to pass in some parameters that are used by the SQL query inside the function.
Unrelated: We are going to have weather today. Unlike on Game of Thrones, where seasons last for years, in San Diego we have micro-seasons. First Summer starts today and may last for almost a week.
-
Stabbing Yourself with the Future
When you go to the specialty pharmacy’s web page, it is pretty clear that the site is not meant for patients. The specialty pharmacy is very proud of its excellence in supply chain management. You will see hardly any mention of their clinical skills and biomedical knowledge on their site, but there is an awful lot of content about how good they are at delivering drugs—especially weird drugs—to where they need to go in a timely manner. They can optimize end-to-end efficiencies and provide inventory management solutions for all of your weird drug supply chain management needs.
For reasons that are not entirely clear to me, the drug company is making me get my medication from this specialty pharmacy instead of mailing me a magical coupon that I could redeem at a normal pharmacy. Well, that is not true; I have a pretty good guess about their motivation. Money. There’s probably enough mark-up between the drug company, the distributer, and the retail pharmacy that it seems like a good idea to the drug company to have the medicine FedExed to me overnight by the world’s leading experts in pharmaceutical supply chain management.
They’ve had my prescription for seven calendar days. Sure, many of them are not business days, but I feel like specialty pharmaceutical distribution shouldn’t just be a Monday - Friday thing. Retail pharmacies are open on evenings and weekends. Patients probably need weird drugs at all sorts of weird times. I have been told that I am unlikely to hear from them for probably another week, give or take. But once I hear from them, it should only be another day or two, give or take, before they FedEx me my medicine.
If I asked you to guess the ten most successful companies in the Fortune 500 (measured in terms of revenue), most people I know would be able to come up with more than half of them with a reasonable number of guesses. The specialty pharmacy is currently in sixth place (fifth place last year), and I had never ever heard of this company before last week. They bring in more revenue than Amazon.com. Almost as much revenue as Apple.
(Aside: I will now name-drop this company in future arguments about how we pay for healthcare in the United States.)
Why is it taking them so long to process my prescription and send me my medication? Because they were off by a factor of five in predicting demand for this drug. The rep on the phone told me that they expected to be delivering the medication to roughly 200 patients per day, but they are currently looking at a volume of over a thousand patients per day. If anyone should know about drug demand forecasting, it should be this company.
This makes me feel a little bit better about my early attempts at predicting the future being really quite terrible.
My first runs were entirely awful because some default setting in the software really wanted to force a particular type of model that is obviously wrong, wrong, wrong for what I was doing. After I overrode that feature, the predictions were still wrong, but less so. As they were consistently wrong, though, I think that I know what I need to try next. Unfortunately, my next step is going to be hard to learn about because its name shares almost all of its characters with something trendy in machine learning, and Google is all clogged up with ML. And what I need are some old-timey statistics. When I get back in the office next week, we’ll see what sort of code is out there to help me minimize some sums of squares.
-
Things Coming in the Mail (Maybe)
-
Dad says that he is going to send me his six-year-old laptop, which would be an upgrade from the five-year-old laptop that I am currently using. Twice as much memory! Four times as much hard drive space! Much bigger screen! OK, probably twice as heavy, too. I need to figure out what sorts of things to put on the new-to-me laptop and which sorts of things to keep on the old laptop. Maybe the six-year-old laptop should replace my eight-year-old desktop computer? Why do I think I need three computers?
-
Normally I hate talking on the phone, but it is easier for me to order cat food over the phone than to do it online. It all started out because Sophie (the barfy cat) eats prescription food (and Whole Foods macaroni and cheese and anything else that she can steal from you), and I could not figure out how to use a paper prescription to order prescription food online, so I called their 24/7 toll-free number, and a very friendly person helped me buy cat food. But time has passed, and now the cat needs more food. And I never set up a username and password for the site, so I just called them on the phone, and they still had everything on file, and the cat food will be here before the laptop.
-
Shortly after 3pm today I called the drug company and spoke to their very friendly customer service rep, D. And D tells me that the drug company sent my prescription to the specialty pharmacy on June 28. D also gave me the patient hotline number for the specialty pharmacy, and if I don’t hear from them by tomorrow morning, I will call them to get an update on the status of my file AND WHEN ARE THEY GOING TO MAIL ME MY FREAKIN’ MEDICINE?
-
subscribe via RSS