April 08, 2010

10 tips for making your R graphics look their best

I found that this page gives helpful advices for creating high-quality images in R.

March 29, 2010

Wow. Is it true?

台灣助理教授月薪約6萬元,副教授約8萬元,教授10萬元,與外國相比,算是廉價的「知識勞工」。國民所得比我們差一截的中國,助理教授薪水是台灣的2 倍;教授可高達台灣的3~5倍,香港與新加坡平均約為台灣的3~4倍。(引自鄭盈湧的部落格)

July 31, 2009

For more information about using LyX and Sweave in Windows machines...

Check out the updated instruction by Murat Yildizoglu here: http://yildizoglu.blogspot.com/2009/02/lyx-and-sweave-under-windows-xp.html
And a wonderful paper "Using Swave with Lyx" by Gregor Gorjanc is worth reading, too: http://gregor.gorjanc.googlepages.com/lyx-sweave


LyX and Sweave

I am dreaming if someday I have enough time to write a Chinese text book about how to use R to replace SPSS in processing survey datasets. I am dreaming this book is done with LyX and the R codes in the book are well incorporated into the book. Then I thought about Sweave, a tool that I heard about when I was in  graduate school.

After some  hours of reviewing concepts about shell and online materials about Sweave, I am writing down the steps for setting up the LyX-Sweave environment in a Linux (Fedora 11) machine:

A good guidance of installation and example Lyx files provided by Paul Johnson are available here: http://wiki.lyx.org/LyX/LyxWithRThroughSweave. Below is a bit updated information about the steps.

1. Create a file named Rweave in /usr/local/bin, where two lines of codes are put into the file:
#!/bin/sh
echo "library(\"utils\"); Sweave(\"$1\")" | R --no-save --no-restore


2. Put Noweb.sty and Sweave.sty in /usr/share/texmf/tex/latex/noweb (create the folder "noweb" if necessary). Noweb.sty can be downloaded here and Sweave.sty is available in your R library: /usr/share/R/texmf/Sweave.sty.

3. In the terminal, change to the root, type "texhash" to update the tex system. Then go to LyX, Tools -> Reconfigure. Next, restart LyX.

4. In LyX, Tools->Preferences-->File Handling, choose "Noweb" in "From format" and "LaTeX(pdflatex)" in "To format". Then, in converter box, type "Rweave $$i". Hit Add and Save.

5. Then you can try to open the example files and making the pdf files.

April 03, 2009

Note for installing Traditional Chinese in Lyx (1.6.2)

I recently updated my Lyx to 1.6.2 (released on March 15, 2009)
My operation system is Linux-Fedora Core 10, but I chose to compile the source code rather than using rpm
because the default coding scheming of rpm uses simplified Chinese font "song," which caused errors
when I use for traditional Chinese fonts like uming and ukai.

so, here are the steps for the installation.

1. download, compile and install lyx-1.6.2.tar.gz (note: you should have both qt and qt-devel packages to pass the configuration_

2. download and install texlive packages (use "yum")

3. download and install CJK package (cjk-4.8.2.tar.gz). Extract the file to the directory /usr/share/texmf/tex/latex/cjk.

4. download and install CJK unifornts (including AR PL UMing and AR PL Uaki).
RPM packages are also available (try cjkunifonts-ukai and cjkunifonts-uming).
These packages give you ttc files. But this ttc or ttf files are not what Lyx recognizes. Lyx need to find tmf files. (See Paul Johnson's notes).

5. transforming the ttc files into tfm files (the most difficult part in this process).
If you read Chinese, read this guide. Below is just a brief modification of the note.

5.1  install the package "fontforge"
5.2 download and extract this package font.tar.bz2 to your local folder, say, ~/font.
5.3 copy your ttc font files to ~/font.
5.4 transform the file from uming.ttc to tfm files (this took me about 4 hours):
time fontforge -script subfonts.pe uming.ttc uming Unicode.sfd
5.5 in the folder of ~/font, create a file called "makemap" with these lines in it.
for i in *.tfm
do
cat >> uming.map << EOF
${i%.tfm} ${i%.tfm} < ${i%.tfm}.pfb
EOF
done
5.6 make this file excutable
chmod +x makemap
5.7. do:
./makemap
5.8 create another file called c70uming.fd
% This is c70song.fd for CJK package.
% created by Edward G.J. Lee
% modify by Frank Liu
\ProvidesFile{c70uming.fd}
\DeclareFontFamily{C70}{uming}{\hyphenchar \font\m@ne}
\DeclareFontShape{C70}{uming}{m}{n}{<-> CJK * uming}{}
\DeclareFontShape{C70}{uming}{bx}{n}{<-> CJKb * uming}{\CJKbold}
\endinput
5.9 create the following directories for newly created files:
mkdir -p ~/.texlive2007/texmf-var/fonts/map/dvips/CJK
mkdir -p ~/.texlive2007/texmf-var/fonts/tfm/CJK/uming
mkdir -p ~/.texlive2007/texmf-var/fonts/type1/CJK/uming
mkdir -p ~
/.texlive2007/texmf-var/tex/latex/CJK/UTF8
5.10 copy the files in ~/fonts into specified paths:
cp ~/font/uming.map ~/.texlive2007/texmf-var/fonts/map/dvips/CJK
cp ~/font/*.tfm ~/.texlive2007/texmf-var/fonts/tfm/CJK/uming
cp ~/font/*.pfb ~/.texlive2007/texmf-var/fonts/type1/CJK/uming
cp ~/font/c70uming.fd ~/.texlive2007/texmf-var/tex/latex/CJK/UTF8
5.11 do:
sudo texhash
updmap --enable Map ukai.map

6. follow the above procedule and install another font "ukai" (note, in step 5 replace "uming" with "ukai")

7. Start LyX and run Tools/Reconfigure

8. Restart Lyx and make two environmental settings:
8.1 In Document/Settings/Language, change the language to Chinese (traditional) and change encoding to Unicode CJK (utf8).
8.2 In the Document/Settings/Fonts panel, type "uming" or "ukai" in the CJK box.

Then you should be able to create Chinese documents with Lyx.

December 22, 2008

太感動人的舞

我很少看電視,但這幾集的舞林大道我都沒有錯過。
爵劇影色舞團+小Call的「最真的期待」讓我感動到不行;
法老與舞姬+Mandy的「神鬼戰役」讓人激賞不已。
我做研究有他們練舞的那種精神就好了。

September 20, 2008

基因與政治行為

政治學界的跨界研究已到此地步,我們還有什麼好敝帚自珍的?

「科學」:選自由派或保守派 基因決定

基因決定論是否可以成立,當然還有待討論,
但我們切莫太快跳入「這就是科學主義」的批判邏輯裡。
就我所知,這些跨域的研究者從未主張基因必然「決定」政治傾向。
這是屬於關聯性(association)的研究,而非因果關係(causal relationships)的研究。

我覺得值得大家思考的,是:同樣都是做政治學的研究,為什麼他們的研究可以這麼有趣。