2012年1月6日星期五

科学民主在中国 - science, democracy, Communism, economy and others in Chineses books

(1)Chinese words referred in Chinese books

我通过 google 的查询系统,查询了民主(democracy)、科学(science)、共产(Communism)、经济(economy)和其它几个词汇在中午书籍中的引用次数。我不想多解释什么,感兴趣可以看看。










(2)the same sets of words (in English) referred in English books

下面一张是世界范围内,英文书籍上述几种词汇的应用频次。


example for double y axis


Here I present an example for double y axis case:


# (1) you will want to generate a graph with the same X axis, but two plot with different y values.

x <- 1:10

y <- rnorm(10)

z <- runif(10, min=1000, max=10000) # second data set on a very different scale

par(mar = c(5, 4, 4, 4) + 0.3)  # Leave space for z axis

plot(x, y) # first plot

par(new = TRUE)

plot(x, z, type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "")

axis(side=4, at = pretty(range(z)))

mtext("z", side=4, line=3)
Created by Pretty R at inside-R.org




# (2) if you only want one plot, but two different annotation of y axis.   

x <- 1:10

y <- rnorm(10)

z <- runif(10, min=1000, max=10000) # second data set on a very different scale

par(mar = c(5, 4, 4, 4) + 0.3)  # Leave space for z axis

plot(x, y, type = "n") # first plot, with type = "n", we will get the empty graph

par(new = TRUE)

plot(x, z, type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "") # here, plot the plot you want

axis(side=4, at = pretty(range(z))) # becare of the pretty() function. it is really nice one.

mtext("z", side=4, line=3)
Created by Pretty R at inside-R.org




plot 2 or multiple X/Y axis in one plot with R

There are several solutions and tips.

(1) A discussion in stackoverflow
http://stackoverflow.com/questions/6142944/how-can-i-plot-with-2-different-y-axes-in-r

(2) two blog posts
http://evolvingspaces.blogspot.com/2011/05/multiple-y-axis-in-r-plot.html

http://robjhyndman.com/researchtips/r-graph-with-two-y-axes/

(3) one article in R wiki, this is the most useful one.
http://rwiki.sciviews.org/doku.php?id=tips:graphics-base:2yaxes

(4) a thread in R-help mailing list
https://stat.ethz.ch/pipermail/r-help/2000-September/008182.html


# plots an x y1 y2 using left and right axes for the different y's
# rescales y2 to fit in the same space as y1
TwoVarPlot <- function(xvar, y1var, y2var, labels, noincs = 5,
marks=c(1,2), legpos, leglabs, title)
{
# rescale to fit on same axis
scaledy2var <- (y2var - min(y2var)) / (max(y2var) - min(y2var))
scaledy2var <- (scaledy2var * (max(y1var) - min(y1var))) + min(y1var)

# plot it up and add the points
plot(xvar, y1var, xlab=labels[1], ylab="", axes=F, pch=marks[1],
main=title)
points(xvar, scaledy2var, pch=marks[2])

# make up some labels and positions
y1labs <- round(seq(min(y1var), max(y1var), length=noincs),2)

# convert these to the y2 axis scaling
y2labs <- (y1labs - min(y1var)) / (max(y1var) - min(y1var))
y2labs <- (y2labs * (max(y2var) - min(y2var))) + min(y2var)
y2labs <- round(y2labs, 2)

axis(1)
axis(2, at=y1labs, labels=y1labs)
axis(4, at=y1labs, labels=y2labs)
mtext(labels[3], side=4, line=2)
mtext(labels[2], side=2, line=2)
box()

legend(legpos[1], legpos[2], legend=leglabs, pch=marks, bty="n")
}

(5) some other scripts 

# A graph with 2 y axes.

#postscript("twoaxes.ps")
#pdf("twoaxes.pdf")

    # Load data table.
data_table <- read.table("twoaxes.data", col.names=c("X","Y1","Y2"))

    # prepare params of the three axes, including labels and ticks.
xMin <- 25
xMax <- 50
xMajorTick = 5
xMinorTick = 1

y1Min <- 0
y1Max <- 1800 
y1MajorTick = 500
y1MinorTick = 100

y2Min <-0
y2Max <-100
y2MajorTick = 20 
y2MinorTick = 10


    # axes' major ticks and labels
xMajorLab = seq(xMin, xMax, xMajorTick);
y1MajorLab = seq(y1Min, y1Max, y1MajorTick);
y2MajorLab = seq(y2Min, y2Max, y2MajorTick);

    # minor ticks and no lables;  num ticks == num intervals +1
xMinorLab<- rep("",((xMax - xMin)/xMinorTick) +1) 
y1MinorLab<- rep("",((y1Max - y1Min)/y1MinorTick) +1) 
y2MinorLab<- rep("",((y2Max - y2Min)/y2MinorTick) +1) 

    # axes title strings
xText <- "List Length"
y1Text <- "Total size (megabytes)"
y2Text <- "Space wastage (%)"

    # mark types
y1Mark= 21 #circle
y2Mark= 15 #filled box

    # legend strings 
y1Legend<- "Total size"
y2Legend<- "Space wastage"

    # increase margin to make sure axis titles are displayed.
par(mar = c(4, 4, 2, 4))

plot(data_table$X, data_table$Y1, type="o", axes=FALSE,
     xlim = c(xMin,xMax) , ylim =c(y1Min, y1Max), 
     xlab=xText, ylab=y1Text, pch=y1Mark)
     # cex = 1.5

    # X axis
axis(1, at=seq(xMin,xMax,xMinorTick), labels=xMinorLab, 
        tick=T, tck=-0.01, pos=y1Min)
axis(1, at=xMajorLab,labels=xMajorLab, tick=T, tck=-0.03, pos=y1Min)
#cex.axis = 1.2

    # Y1 axis , las -- label direction.
axis(2, at=seq(y1Min,y1Max,y1MinorTick), labels=y1MinorLab, 
        tick=T, tck=-0.01, pos=xMin)
axis(2, at=y1MajorLab, labels=y1MajorLab, tick=T, tck=-0.03, pos=xMin,
        las=2)

    # make sure next plot is on same graph
par(new = T)

plot(data_table$X, data_table$Y2, type="o", axes=FALSE, 
     xlim = c(xMin,xMax) , ylim =c(y2Min, y2Max), 
     xlab="", ylab="", pch=y2Mark)
mtext(y2Text, 4, 2)

    # Y2 axis
axis(4, at=seq(y2Min,y2Max,y2MinorTick), labels=y2MinorLab, 
        tick=T, tck=-0.01, pos=xMax)
axis(4, at= y2MajorLab, labels=y2MajorLab, tick=T, tck=-0.03, pos=xMax, las=2)

    # Legend, bty="n" -- no frame, 
legend(38, 20, c(y1Legend, y2Legend), bty="n", 
       lty=c(1,1), pch= c(y1Mark, y2Mark))


#dev.off()  # This is only needed if you use pdf/postscript in interactive mode

R or Python - as statistical bench

There is a nice discussion about choosing R or Python as your statistical bench. You could also find much good Python resources.

I just grab some here:
########################################
(1)

  • NumPy/Scipy You probably know about these already. But let me point out the Cookbookwhere you can read about many statistical facilities already available and the Example Listwhich is a great reference for functions (including data manipulation and other operations). Another handy reference is John Cook's Distributions in Scipy.
  • pandas This is a really nice library for working with statistical data -- tabular data, time series,panel data. Includes many builtin functions for data summaries, grouping/aggregation,pivoting. Also has a statistics/econometrics library.
  • larry Labeled array that plays nice with NumPy. Provides statistical functions not present in NumPy and good for data manipulation.
  • python-statlib A fairly recent effort which combined a number of scattered statistics libraries. Useful for basic and descriptive statistics if you're not using NumPy or pandas.
  • statsmodels Statistical modeling: Linear models, GLMs, among others.
  • scikits Statistical and scientific computing packages -- notably smoothing, optimization and machine learning.
  • PyMC For your Bayesian/MCMC/hierarchical modeling needs. Highly recommended.
  • PyMix Mixture models.
    If speed becomes a problem, consider Theano -- used with good success by the deep learningpeople.
    ########################################
    (2)

    • matplotlib for beautiful, publication quality graphics.
    • IPython for an enhanced, interactive Python console. Importantly, IPython provides a powerfulframework for interactive, parallel computing in Python.
    • Cython for easily writing C extensions in Python. This package lets you take a chunk ofcomputationally intensive Python code and easily convert it to a C extension. You'll then beable to load the C extension like any other Python module but the code will run very fast sinceit is in C.
    • PyIMSL Studio for a collection of hundreds of mathemaical and statistical algorithms that are thoroughly documented and supported. You can call the exact same algorithms from Python and C, with nearly the same API and you'll get the same results. Full disclosure: I work on this product, but I also use it a lot.
    • xlrd for reading in Excel files easily.
    If you want a more MATLAB-like interactive IDE/console, check out Spyder, or the PyDev plugin for Eclipse.
    ########################################
    (3)

    I know there's also rpy, where python can call R functions. This can be useful, but if you're "just"doing statistics then I would use R.
    ########################################
    (4)

    The following StackOverflow discussions might be useful

    Other useful packages specifically for data structures include:
    • pydataframe replicates a data.frame and can be used with rpy. Allows you to use R-likefiltering and operations.
    • pyTables Uses the fast hdf5 data type underneath, been around for ages
    • h5py Also hdf5, but specifically aimed at interoperating with numpy
    ########################################
    (5)

    What you are looking for is called Sage: http://www.sagemath.org/
    It is an excellent online interface to a well-built combination of Python tools for mathematics.
    ########################################
    (6)

    I like the http://enthought.com/ python distribution. It's commercial, yet free for academicpurposes and, as far as I know, completely open-source. As I'm working with a lot of students,before using enthought it was sometimes troublesome for them to install numpy, scipy, ipythonetc. Enthought provides an installer for Windows, Linux and Mac.
    Two other packages worth mentioning:
    1. ipython (comes already with enthought) great advanced shell. a good intro is on showmedohttp://showmedo.com/videotutorials/series?name=PythonIPythonSeries
    2. nltk - the natural language toolkit http://www.nltk.org/ great package in case you want to do some statistics /machine learning on any corpus

2012年1月5日星期四

learn python programming - from here


(1) google course for python
http://code.google.com/edu/languages/google-python-class/

(2) Dive into python
http://www.diveintopython.net/

(3) biopython
http://biopython.org/wiki/Main_Page

(4) SciPy
http://www.scipy.org/

Google Code University - learn programming with/in google

Google Code University (http://code.google.com/edu/courses.html) has prepare you many learning resources (videos, text, links) of programming.  You may find what you are interested in.


#############################################################

Courses

Here is a list of courses and innovative resources to help CS students, faculty, and instructors. These are examples of the training Google engineers use to learn new skills.
Tip: Check out the General Google Code University Forum to ask and answer questions.

Programming Languages

Classes

C++

Java

Python

Go

Web Programming

Tutorials

Contributed Course Content

Video Lectures

Web Security

Algorithms

Android

Distributed Systems

Tools 101

Database

Software Configuration Management (SCM)

Linux

Google APIs & Tools

2012年1月4日星期三

bioinformatic/sequence manipulation with R

In this blog (fabio marroni's blog), the author presented much successful cases of manipulation sequences with R.

Supercharge your R experience

Supercharge your R experience in this blog, the author said in the 108. issue of Linux User & Developer there would be the interesting article.

2012年1月3日星期二

two nice plots

http://polstat.org/blog/2012/1/voting-networks-danish-parliament/

Coefplot: New Package for Plotting Model Coefficients


http://blog.revolutionanalytics.com/2012/01/new-package-for-plotting-model-coefficients.html



how it be generated - I am thinking

http://tonybreyal.wordpress.com/

Advanced Bash-Scripting Guide

http://www.tldp.org/LDP/abs/html/

2012年1月2日星期一

Drawing national flags on maps using R

http://vzemlys.wordpress.com/2012/01/03/drawing-national-flags-on-maps/
http://rsnippets.blogspot.com/2011/12/color-map-of-poland-for-new-year.html

Time series data aggregation - R and reshape

http://vzemlys.wordpress.com/2010/01/06/time-series-data-aggregation-using-r-and-reshape/

ggbio - tools for generating genomic visualizations

http://www.bioconductor.org/packages/release/bioc/html/ggbio.html

extend ggplot2 to bioinformatics utilities. bioconductor

synchronizing your file - tools

http://www.cerebralmastication.com/2011/04/fast-two-way-sync-in-ubuntu/

http://www.cerebralmastication.com/2011/04/details-of-two-way-sync-between-two-ubuntu-machines/

http://www.decisionsciencenews.com/2011/11/19/keep-your-files-in-sync-for-free/

kill your jobs in cluster

qdel -u XXX
qdel nnnn

# XXX is your log-in ID
# nnnn is your job ID

Interacting with bioinformatics webservers using R

http://nsaunders.wordpress.com/2011/09/08/interacting-with-bioinformatics-webservers-using-r/#more-2858


基于R 对网络界面的数据库进行查询。