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)的研究。

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

June 04, 2008

LyX now supports for Chinese characters! Cheers!

LyX 是個免費的文件編排軟體,支援各種作業系統平台而且可以製出高品質的pdf檔案。直到最近它終於能夠以Utf-8編碼來支援中文字體了。能夠用它編輯中文文件是件令人振奮的事。
看看這篇的精彩介紹。

April 19, 2008

R still dominates the graduate programs at top universities

A recent course on quantitative method at Harvard emphasizes the use of R. Here is a website that gives all of the course materials, including R codes.

April 10, 2008

Some clips showing the glory of the KU championship

Thanks to KU jayhawk fans and the Internet, I was able to share the joy back to Lawrence.

The happiness and craziness on KU campus and in Lawrence
The rap for KU jayhawks!
The craziness in KU football stadium
The craziness in KU Allen Fieldhouse 1
The craziness in KU Allen Filedhouse2
The craziness on Mass street downtown Lawrence

My favorite:
The summary of the classic moments
The classic last minutes of the game
Kansas 2008 National Champions: Stand up for the Champion (by Right Said Fred)

I was built to be the best
Number one and nothing less
Leave me to my destiny
I have waited patiently
I have vision' oh i believe
I know I can count on me
So stand up for the champions
For the champions stand up
Stand up stand up
For the champions for the champions
Stand up for the champions
For the champions stand up
Stand up stand up
For the champions for the champions
Stand up

Here we go it's getting close
Now it's just who wants it most
It's just life that's how it is
Cause we have our strength and weaknesses
Oh i have vision' oh can't you see
I'm on the move make way for me
So stand up for the champions
For the champions stand up
Stand up stand up
For the champions for the champions
Stand up for the champions
For the champions stand up
Stand up stand up
For the champions for the champions
Stand up

And when i fall down
I have to pick myself back up
And when i fall down
I have to pick myself back up
And when i fall down
I have to pick myself back up
And when i fall down
I have to pick myself back up
So stand up stand up for the champions
For the champions stand up
Stand up stand up
For the champions for the champions
Stand up
Stand up stand up
For the champions for the champions
Stand up stand up
For the champions for the champions
Stand up stand up
For the champions for the champions
Stand up stand up
For the champions for the champions
stand up