作者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