Ha! I just discovered that even an English major can write an R function.
Here is a picture of all five of my lovely children (the oldest is wading, wearing the orange shirt) for those of you who are thinking, "Is she talking about her stats program AGAIN?" But perhaps you might also like to see the pretty picture I just made.
I am looking longitudinally at kids' language abilities, based on transcripts collected at three visits, each a year apart. In the first year, they were in first or second grade; by the last visit, they were in third or fourth grade. In addition to looking at group differences at each point, I am also looking at growth trajectories.
So-- I wanted to superimpose density curves. What did they look like in year 1 vs. year 2 vs. year 3? How were they changing? I figured out how to make these superimposed curves show up on my own computer screen, but I couldn't figure out how to save them in a usable format. I figured my committee would frown on a dissertation that said "Stop by my house and I will show you the pretty pictures I can't get into this document."
If you would like to make your very own superimposed density curves, it's actually not hard. Open a text editor and type the stuff in black.
progress<-function(x,y,z) [Hey, R, make me a function called "progress" where the expected input is three vectors.]
{
plot(density(x),col=1)
lines(density(y),col=2)
lines(density(z),col=3)
}
Then save your function as "progress.R" and at the R command line type
> source("directory_name/progress.R")
Now we're all set to create a save-able image:
> progress(year1,year2,year3)
> dev.off()
And tada! This image shows the changes in the density of elaborated noun phrases across the three home visits. How much more often are kids using rich descriptive phrases as they mature? (More details here if you are pining away for want of knowledge about elaborated noun phrases.)
It's not perfect -- I'm going to change the title and the labels for the axes (which I know how to do) and ideally the scaling (which I have no idea how to do, but which would make it easier to compare curves across samples -- the numbers change each time due to attrition). But hey-- I wrote an R function and it did what I meant it to do! Hurray!
Recent Comments