Sunday, May 22, 2011

Legends in ggplot2

A simple plot takes a few lines of coding:

g1 <- ggplot(d, aes(birth.year))

g2 <- g1 + geom_line(aes(y=alive0, linetype="Famale")) + 
geom_line(aes(y=alive1, linetype="Male")) + scale_linetype_discrete(name = "")

g3 <- g2 + geom_point(aes(y=alive0, shape="Famale")) + 
geom_point(aes(y=alive1, shape="Male")) + scale_x_continuous("") + scale_y_continuous("Proportion Alive in 1982") + opts(legend.position=c(.24, .95), legend.justification = c(1, 1)) + scale_shape_discrete(name="")

g4 <- g3 + labs(fill="")

Friday, May 20, 2011

LaTeX template for NSF proposal

Since I am beginning to work on a NSF grant proposal, I started to look for suitable LaTeX templates. Here is one. And here are some useful tips as well as examples.

Here is an official resource, and here are some very useful LaTeX resources.

A good blog on programming

In Chinese.

Monday, May 16, 2011

Replicating multilevel analysis Mplus results

Since I am relatively unfamiliar with Mplus, The first step toward building a complicated model is to replicate some simpler results using statistical packages I have more knowledge on such Stata and R, then build it up piece by piece. 

As the effort to understand the multilevel mixture modeling capacity of Mplus, I have decided to use the Mplus sample data set, "ex10.1.dat", to try alternative model specifications in both Mplus, Stata and R. I am going to post a series of code and results. 

As the first step, I try this really simple Mplus code: 
DATA: FILE IS ex10.1.dat;
VARIABLE: NAMES ARE y x1 x2 w class clus;
WITHIN = x1 x2;
CLUSTER = clus;
y ON x1 x2;
y ON ;
which gives exactly the same results as the following Stata code: 
xtreg y x1 x2, i(clus) mle

Tuesday, May 10, 2011

Wednesday, May 04, 2011

Mplus for Bayesian analysis

The new Mplus has a quite rich set of Bayesian analysis feature. I cannot wait to play with it.

Extension to mtable function

Here are some useful extension to the "mtable" function in the memisc package.