作者htio (htio)
看板NCCU07_STGRA
標題Re: [公告] 政治大學小馬教授R講座
時間Fri Oct 26 22:54:52 2007
Dear all:
既然大家那麼賞臉埲場..我就會好好努力的~!
以下是我會講到的內容,先讓大家過目..
時間:星期六(明天)3pm~5pm, 地點:6樓party室.
請大家盡量帶notebook過來,對學習會比較有幫助.~XD
Part 1: R Introduction (Take approximate 30-45min)
- Getting started: (Optional)
Introduce the reason that "Why R is so popular in statistical field?"
Downloading software
Introduce the User interface
Introduce concept of package, Install, Load
Using "Help" in R~~>_<
- Defining object/variable
Introduce R object, Function ( <--This is super simple concept, )
Define some simple variable (variable,array,character string)
Simple computation between variable object
Remove object
- Some Simple Data Processing
Sort/Rank an array
Statistic computation(sum,mean,variance,s.d...blah blah..etc)
- Some logical computation
-Simple logical "IF"
(I will demo a super simple example)
- Matrix computation (IMPORTANT IN REGRESSION!!)
Creating a Matrix object
Matrix computation
(inverse,tranpose,diagonal,I will demo how to obtain the beta coefficient)
- Input/Output
Import/Export file in R
Extract/Explore the data file
Reconstruct a dataframe
- Graph Drawing
Plot a 2-D plot(scatter plot, pairs plot)
Histrogram
Drawing lines using ("abline")
Part 2: Regression homework DISCUSSING (Take approximate 15min)
- Introduce R command ("lm") (Fitting a linear model)
- Show the result that i done.
- Explain My Source code (take about 1 minute...,i will tell you why)
Part 3: Q/A
- Ask whatever as you like...
*--------------------------------------------------------------------------
以下是我的程式碼,希望大家可以先看一看.
明天我會解釋.
data=read.table("c:/UN2.txt",header=TRUE)
#Remark:Column 1 = X1 (log(PPGDP)),
# Column 2 = Y (log(Fertality) ,
# Column 3 = X2 (Purban)
#==============#
#Problem 3.2.1 #
#==============#
#Construct a Added-variable plot
e1=lm(data[,3]~data[,1])$resid
e2=lm(data[,2]~data[,1])$resid
#(a)Fit e1,e2 with a linear model (e2~b1*e1) without the intercept.
lm(e2~e1-1)$coef
#(b)Fit y,x1,x2 with a linear model (y=b0+b1*x1+b2*x2)
lm(data[,2]~data[,1]+data[,3])$coef
par(mfrow=c(2,1))
plot(e1,e2,xlab="ehat from Purban on log(PPgdp)",ylab="ehat from log(Fertility) on log(PPgdp)")
abline(h=0);abline(v=0)
abline(lm(e2~e1-1))
plot(lm(e2~e1-1)$resid,lm(data[,2]~data[,1]+data[,3])$resid)
#==============#
#Problem 3.2.2 #
#==============#
summary(lm(e2~e1-1))$coeff
summary(lm(data[,2]~data[,1]+data[,3]))$coeff
*--------------------------------------------------------------------------
還有,明天我會印一兩張Reference card給大家...
還有,如果大家不介意的話,我會在中途叫大家實做一兩個小小的操作,
這樣大家比較不會太無聊...也可以學到東西。
PS:到時講的不好的話,請多多包涵,特別是那些專程來的同學們.
小馬下台一鞠躬.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.119.203.85
1F:推 hiwinson:同學你專業的喔 高手 10/26 23:12
2F:推 AVclub:我可以旁聽嗎? 大大 10/26 23:36
3F:推 htio:樓上的...你當然可以來,問題是你應該比我強n倍吧 =.= 10/26 23:40
4F:推 rifle888:馬爺超酷耶~ 10/27 00:05
5F:推 javy:馬爺 程式碼借用一下嘿 10/27 00:12
6F:推 htio:ok,ok,free to use 10/27 00:17
7F:→ cravingtrue:Code也借我用一下吧...懶的想 10/27 00:30
8F:推 da1985:._./馬爺...我昨天沒學到畫圖 10/27 12:33