Archive

Archive for the ‘work’ Category

Multi-level enumerated list in Latex

December 16, 2011 1 comment

For my PhD thesis writing, I’d like to have a nice multi-level enumerated list with custom numbering (1, 1.1, 1.2, …) like this:

1. First level
   1.1 Second level
   1.2 Second level
2. First level 
   2.1 Second level 
   2.2 Second level

With only enumerate command, I couldn’t have the second level displayed as expected. There are some workarounds with the enumitem package, but I have no success with the shortlabels option, for some reasons my enumitem.sty file does not have that option declared. A nice simple way to achieve this is adding these two lines:

\renewcommand{\labelenumi}{\arabic{enumi}.}
\renewcommand{\labelenumii}{\arabic{enumi}.\arabic{enumii}}

arabic (1, 2, 3, …) can be replaced with Roman (I, II, III, …) or alph (a, b, c, …) if necessary.

Then in the body of the tex, just call enumerate normally:

\begin{enumerate}
   \item First level
       \begin{enumerate}
          \item Second level
          \item Second level
       \end{enumerate}  
   \item First level
       \begin{enumerate}
          \item Second level
          \item Second level
       \end{enumerate} 
\end{enumerate}
Categories: Latex

Simple MMRE function in R

December 15, 2011 Leave a comment

After a while reading through R tutorials, here’s a simple function in R to calculate MMRE

function(data)
{
    n = nrow(data);
    total_mre = 0;
    for(i in 1:n)
    {
        current_x = data[i,1];
        current_y = data[i,2];
        temp_data = data[-i,];
        temp_series_x = temp_data[,1];
        temp_series_y = temp_data[,2];
        
        // this bit took me relatively more time to figure out how to 
        // extract data from atomic vectors
        formular = matrix(coef(lm(temp_series_y~temp_series_x)), 1, 2);

        m = formular[1,2];
        c = formular[1,1];
        pred = m*current_x + c;
        mre = abs(current_y - pred)/current_y;
        total_mre = total_mre + mre;
    }
    mmre = (total_mre)/n;
    return (mmre);
}
Categories: R