A brief tutorial on ML estimation in R
Recently, a colleague asked me to demonstrate how one can calculate maximum-likelihood (ML) parameter estimates in R. As I had been meaning to do this for my R course anyway, I decided to write up the following brief tutorial. In the tutorial, I go through the three basic steps of ML estimation in R for both a statistical example (the simple linear model) and a psychological model of choice (the Proportional Difference model, Gonzalez-Vallejo, 2001).
You can view the tutorial on the preceding link. If you have any comments, criticisms or questions, please let me know and I will try to update the document!
Note: I am in debt to Dr. Stephen Lewandowsky and Dr. Simon Farrell’s summer school on computational cognitive modelling for teaching me these techniques. You can purchase their great book on the subject here Computational Modeling in Cognition: Principles and Practice
As of May 17 2015, I am proud to announce NDP Consulting! NDP Consulting is my new umbrella for providing consulting services for both academic and non-academic problems. While I have provided consulting services to many people in the past, this will be my first time officially advertising my services (and hey, it was fun creating my new logo – in R of course).
If you have a data analysis, forecasting, experimental design, or modelling problem that you need help with, please don’t hesitate to contact me with a brief outline of the project and I will let you know what I can do to help.
Today (March 1, 2015), I was honored to be interviewed by EADM, the European Association for Decision Making! You can see the interview here: http://eadm.eu/the-eadm-interview/nathaniel-philips/
Shiny Link: https://ndphillips.shinyapps.io/Visual_Resume/
How much do I love R? Enough that I maintain several ‘fun R’ projects. One of my favorites is my Visual Resume generator – which creates an individualised visual resume based on a person’s education and job history (and publications and research interests, etc.). I was inspired by this blog post on infographic resumes to build a version in R. For example, here is a copy of my visual resume (as of January 2014):
Since so many people like this, I decided to create a Shiny application where everyone can create their own. A beta version of the app is now live at https://ndphillips.shinyapps.io/Visual_Resume/. Play around with it and please send me feedback and recommendations for improvement!
What if I told you there was a new drug that has been proven to DOUBLE your changes of getting over a cough? Sounds great doesn’t it? Well, before we (ahem) cough up the dough for drug X, let’s take a closer look at the clinical trial data:
First, let’s look at the results from the placebo condition:
Ok, now let’s look at the results from the group of people given Drug X
Hmmm, as we can see from the plots, while the users of Drug X were indeed twice as likely to get over the cold, they were also much more likely to develop side-effects.
Frequency grid displays such as these can help people understand risks. But creating the plots themselves is a bit of a pain. To solve this, I wrote an R function called Icon.Array. A beta version of the function implemented in a Shiny app is located at https://ndphillips.shinyapps.io/IconArray_App/.
Well, after talking about it for about a year now, I’ve finally started converting my R course to a YouTube friendly format. Since I’m in the middle of my university R course, the videos don’t quite start at the beginning. I’ll add the beginning 3-5 lectures after the semester ends. In the meantime, here’s the permanent link: http://goo.gl/a6L0up
Here’s a quick example of how the dplyr package can dramatically improve your code for organising and manipulating dataframes [RPubs]
This comes at the end of a discussion on the October 2, 2014 Colbert Report between Colbert (playing the sensationalist news reporter role) and a scientist (whose name I couldn’t understand) downplaying any real potential outbreak of ebola after the announcement that a man in Texas came down with ebola
Colbert: Cards on the table time, alright? Does someone else come down with Ebola because this guy had ebola?
Scientist: There might be one secondary case…
Colbert: So there might be a 100% increase in ebola in the United States!!!
Scientist: (with sarcasm) That is correct!
Colbert: Ok, thank you for that shocking news doctor!
Perfect example of using relative risk versus absolute risk to mislead!
For research papers on perceptions of relative versus absolute risk, check out Baron (1997), Gigerenzer & Edwards (2003) and Gigerenzer et al. (2007)
I frequently find myself thinking of the best way to convince an SPSS user to make the switch to R. In the process, I came up with the three following most common objections by SPSS users and my responses.
Objection #1) I can’t use R because I don’t know how to program
Response: Of course you don’t, you haven’t learned yet. That’s like saying you can’t take a German class because you don’t know German (yes, I see the irony).
Objection #2) It will take too long for me to learn
Response: Want to do a t-test in R? – type t.test(x, y). Want to do linear regression? – type lm(y~x). Bayesian t-test? – type BESTmcmc(x,y). Create a scatterplot? – type plot(x,y). Congratulations! In 20 seconds you just learned in R what took you hours, if not days to learn in SPSS! Or imagine you had a friend with an alternative version of Microsoft Word where, instead of typing words letter by letter via the keyboard, she used her mouse to select each and every word she wanted via a series of confusing menus. What if she told you that it would take her too long to learn how to use a keyboard?
Objection #3) We have to teach students SPSS – they either won’t be able to learn R or they won’t want to
Response: I heard this objection from a psychology department head – but what I really think he meant was “I don’t want to learn R!” Trust me, students will thank you later for teaching them how to use software that saves them an incredible amount of time and money. Plus, which of these instructions is easier to follow:
- “To do a t-test, click the button X on the upper part of the screen, then click X. Scroll down and put X in the left column and X in the right column. Make sure to check the box X. If you need more help, here are a few pages of screenshots from a previous version of SPSS with different menus that will confuse the hell out of you.”
- “To do a t-test, type – t.test(x,y)”
Objection #4) If we stop paying for the SPSS license we’ll have extra money left over that we won’t know what to do with.
Response: Buy me the new iPhone.
And now to reduce cognitive dissonance, I’ll definitely have to switch from Word to Latex…
If you’re not using the dplyr package in R yet you’re crazy.
Thanks for the reference Michael Schulte-Mecklenbeck!