Chang ,JX

рассказ и язык

Archive for the ‘Uncategorized’ Category

stata time gap

Posted by changjx on October 30, 2009

seb obs 30
gen t=_n+1
tsset t,d
gen tx=_n+1+t
tsset tx,d
gen gap=tx-t
format %9.0g t
format %9.0g tx
gen gapn = tx-t

Posted in Uncategorized | Tagged: | Leave a Comment »

Latex trick

Posted by changjx on October 29, 2009

\newcommand{\argmax}{\operatornamewithlimits{argmax}}
\def\[#1\]{\begin{align}#1\end{align}}
\newcommand{\ve}{\varepsilon}
\newcommand{\nf}{\textrm}
\newcommand{\argmax}{\operatornamewithlimits{argmax}}

Posted in Uncategorized | Tagged: | Leave a Comment »

latex bold symbol

Posted by changjx on October 26, 2009

use \pmb instead of \boldsymbol

Posted in Uncategorized | Tagged: | Leave a Comment »

extract coef,se,t,pv from stata reg

Posted by changjx on May 26, 2009

Maarten Buis’s method to extract estimate from stata reg

——-begin correct code —
sysuse auto, clear
reg price mpg rep78 headroom trunk weight
matrix a = vecdiag(e(V))
matrix b = (e(b)\a)’
svmat b
rename b1 beta
gen se = sqrt(b2)
gen t = beta/se
gen p = 2*ttail(63,abs(t))
——— end correct code—–

Or use May’s code
Read the rest of this entry »

Posted in Stata, Uncategorized | Tagged: , | Leave a Comment »

R:two axis label

Posted by changjx on April 8, 2008

http://www.apsnet.org/education/AdvancedPlantPath/Topics/RModules/Doc1/01_Nematode.html
## Set up the vector of nematode populations
npop <- c(220,180,150,250,270,300,500,580,580,1000,380,100)

## Set up vector of associated months
names(npop) <-c (
        "Jan",
        "Feb",
        "Mar",
        "Apr",
        "May",
        "Jun",
        "Jul",
        "Aug",
        "Sep",
        "Oct",
        "Nov",
        "Dec"
)

## Set up the bar plots of the nematode populations,
try help(barplot) for more information
barplot(
        npop,
        axes=FALSE,
        main="Nematode  Population",
        ylim=c(0,1200),
        col="orange",
        xlab="Month",
        ylab="Nematodes per 100 cc soil")
        axis(2,seq(0,1200,by=200)
)

## Set up the new plot to be drawn on top of the barplot,
try help(par) for more information
par(new=T)

# This sets the average monthly temperature
# for the line above the population
y <-c (15,17,20,24,26,28,30,31,30,28,19,16)

# This positions the points on the X axis
# correctly in the middle over the top of the bar chart.
y2 <-c (0.5,1.45,2.45,3.5,4.5,5.35,6.5,7.6,8.5,9.55,10.65,11.5)

## Plot the temperature points
plot(
        y2,
        y,
        ylim=c(0,35),
        xlab=NA,
        ylab=NA,
        xlim=c(0,12),
        axes=FALSE,
        type="o",
        pch=22,
        col="mediumblue"
)

axis(
        4,
        seq(0,35,by=5),
        labels=FALSE
)

## Lay out the points for temperature
points(
        y2,
        y,
        pch=22,
        col="mediumblue"
)

## Label the right axis, try help(mtext) for more information
mtext(
        c("0C","5C","10C","15C","20C","25C","30C","35C"),
        4,
        at=seq(0,35,by=5),
        line=.25
)

## Label the right axis, try search(mtext) for more information
mtext(
        "Average Soil Temperature",
        4,
        line=1,
        cex=1
)

## Create a legend
legend(
        "topleft",
        c("Soil Temperature","Nematode Population"),
        pch=c(22,NA),
        lty=c(1,NA),
        col=c("mediumblue",NA),
        inset=0.01
)

## Create an orange rectangle next to
the Nematode Population label for the legend
rect(-0.2,32.4,0.4,33.4,col="orange")

Posted in Uncategorized | Tagged: | Leave a Comment »

選課計界

Posted by changjx on February 26, 2008

Posted in Uncategorized | Tagged: | Leave a Comment »

Future education

Posted by changjx on January 16, 2008

Posted in Uncategorized | Leave a Comment »

Three Asymptotic Tests: LR, Wald, LM test

Posted by changjx on September 25, 2007

LR test : restricted parameter vector and specify distribution(∵ likelihood function)
Wald test : unrestricted parameter vector only
LM test: restricted parameter vector only, the popular method in econometrics since restricted model is easy to get.

Method 1

#read data
hs1 <- read.table("http://www.ats.ucla.edu/stat/R/notes/hs1.csv", header=T, sep=",") attach(hs1) # classify variable honcomp = 60
honcomp[1:20]
#LR test for logistic reg
lr <- glm(honcomp~female+read, family=binomial) lr2 <- glm(honcomp~female+read+science+math+as.factor(prog), binomial, na.action=na.exclude) drop1(lr2, test="Chisq")

Method 2

see http://cran.r-project.org/src/contrib/Descriptions/lmtest.html
#download the package lmtest
library(lmtest)
lrtest(lr,lr2)
waldtest(lr,lr2)
lmtest(lr,lr2)

Posted in Uncategorized | Leave a Comment »