q( ) 2: R 2 R R R R C:nProgram FilesnRnrw1030) [File] [Change Dir] c:ndatadir OK 2



Similar documents
DAA09

(lm) lm AIC 2 / 1

1.2 R R Windows, Macintosh, Linux(Unix) Windows Mac R Linux redhat, debian, vinelinux ( ) RjpWiki ( RjpWiki Wiki

1 R Windows R 1.1 R The R project web R web Download [CRAN] CRAN Mirrors Japan Download and Install R [Windows 9

k2 ( :35 ) ( k2) (GLM) web web 1 :

> usdata01 と打ち込んでエンター キーを押すと V1 V2 V : : : : のように表示され 読み込まれていることがわかる ここで V1, V2, V3 は R が列のデータに自 動的につけた変数名である ( variable

1 15 R Part : website:

R John Fox R R R Console library(rcmdr) Rcmdr R GUI Windows R R SDI *1 R Console R 1 2 Windows XP Windows * 2 R R Console R ˆ R

BMIdata.txt DT DT <- read.table("bmidata.txt") DT head(dt) names(dt) str(dt)

untitled

インターネットを活用した経済分析 - フリーソフト Rを使おう

Use R

講義のーと : データ解析のための統計モデリング. 第3回

卒業論文

●70974_100_AC009160_KAPヘ<3099>ーシス自動車約款(11.10).indb

情報管理学科で学ぶ

R Console >R ˆ 2 ˆ 2 ˆ Graphics Device 1 Rcmdr R Console R R Rcmdr Rcmdr Fox, 2007 Fox and Carvalho, 2012 R R 2

untitled

kubostat2015e p.2 how to specify Poisson regression model, a GLM GLM how to specify model, a GLM GLM logistic probability distribution Poisson distrib

kubostat2017c p (c) Poisson regression, a generalized linear model (GLM) : :

一般化線形 (混合) モデル (2) - ロジスティック回帰と GLMM

lec03

2.1 R, ( ), Download R for Windows base. R ( ) R win.exe, 2.,.,.,. R > 3*5 # [1] 15 > c(19,76)+c(11,13)

J1順位と得点者数の関係分析

untitled

講義のーと : データ解析のための統計モデリング. 第2回

DAA01

R R-console R R Rscript R-console GUI 1

untitled

yamadaiR(cEFA).pdf

こんにちは由美子です

¥¤¥ó¥¿¡¼¥Í¥Ã¥È·×¬¤È¥Ç¡¼¥¿²òÀÏ Âè2²ó

²¾ÁÛ¾õ¶·É¾²ÁË¡¤Î¤¿¤á¤Î¥Ñ¥Ã¥±¡¼¥¸DCchoice ¡Ê»ÃÄêÈÇ¡Ë

kubostat2017e p.1 I 2017 (e) GLM logistic regression : : :02 1 N y count data or

!!!!!

講義のーと : データ解析のための統計モデリング. 第5回

Stata11 whitepapers mwp-037 regress - regress regress. regress mpg weight foreign Source SS df MS Number of obs = 74 F(

R による共和分分析 1. 共和分分析を行う 1.1 パッケージ urca インスツールする 共和分分析をするために R のパッケージ urca をインスツールする パッケージとは通常の R には含まれていない 追加的な R のコマンドの集まりのようなものである R には追加的に 600 以上のパッ

R による統計解析入門

回帰分析 単回帰

201711grade2.pdf

1

PowerPoint プレゼンテーション

Microsoft PowerPoint - Econometrics

PackageSoft/R-033U.tex (2018/March) R:

1 2 Windows 7 *3 Windows * 4 R R Console R R Console ˆ R GUI R R R *5 R 2 R R R 6.1 ˆ 2 ˆ 2 ˆ Graphics Device 1 Rcmdr R Console R Rconsole R --sdi R M

kubostat2018d p.2 :? bod size x and fertilization f change seed number? : a statistical model for this example? i response variable seed number : { i

<4D F736F F F696E74202D BD95CF97CA89F090CD F6489F18B4195AA90CD816A>

改訂版 :基本的な文字化の原則(Basic Transcription System for Japanese: BTSJ)

.3 ˆβ1 = S, S ˆβ0 = ȳ ˆβ1 S = (β0 + β1i i) β0 β1 S = (i β0 β1i) = 0 β0 S = (i β0 β1i)i = 0 β1 β0, β1 ȳ β0 β1 = 0, (i ȳ β1(i ))i = 0 {(i ȳ)(i ) β1(i ))

28

こんにちは由美子です

1 kawaguchi p.1/81

第11回:線形回帰モデルのOLS推定

「統 計 数 学 3」

REALV5_A4…p_Ł\1_4A_OCF

untitled

「都市から地方への人材誘致・移住促進に関する調査」

<91498EE88CA D815B2E786C73>

〔 大 会 役 員 〕

橡本体資料+参考条文.PDF

Lecture on

<4D F736F F D20939D8C7689F090CD985F93C18EEA8D758B E646F63>

2X Y Y X θ 1, θ 2,... Y = f(x, θ 1, θ 2,...) θ k III 8 ( ) 1 / 39



康乘聡子(P105‐121)/康乘聡子 p105‐121

‡Æ‡Ý‡©457_01-12

' % % &! #


76

†ı25”Y„o-PDF.ren

™ƒŒì„³001†`028.pwd

★分冊3-説明資料PDF用/02-PDF個別


k3 ( :07 ) 2 (A) k = 1 (B) k = 7 y x x 1 (k2)?? x y (A) GLM (k

: (EQS) /EQUATIONS V1 = 30*V F1 + E1; V2 = 25*V *F1 + E2; V3 = 16*V *F1 + E3; V4 = 10*V F2 + E4; V5 = 19*V99

-34-

untitled


2 R : R R [ 1.1] [ 2.1] R R R plot() contour() 2

最小2乗法

第9回 日経STOCKリーグレポート 審査委員特別賞<地域の元気がでるで賞>

1 2 *3 Windows 7 *4 Windows * 5 R R Console R R Console ˆ R GUI R R R *6 R 2 R R R 6.1 ˆ 2 ˆ 2 ˆ Graphics Device R R Rcmdr Rconsole R --sdi R MDI R *3

Excel基礎講座テキスト-表紙と目次v1.3.doc

2 と入力すると以下のようになる > x1<-c(1.52,2,3.01,9,2,6.3,5,11.2) > y1<-c(4,0.21,-1.5,8,2,6,9.915,5.2) > cor(x1,y1) [1] > cor.test(x1,y1) Pearson's produ

% 10%, 35%( 1029 ) p (a) 1 p 95% (b) 1 Std. Err. (c) p 40% 5% (d) p 1: STATA (1). prtesti One-sample test of pr

¥¤¥ó¥¿¡¼¥Í¥Ã¥È·×¬¤È¥Ç¡¼¥¿²òÀÏ Âè2²ó

<4D F736F F F696E74202D2088E D8C768A7789C482CC8A778D5A F939D8C76835C FC96E52E >

σ t σ t σt nikkei HP nikkei4csv H R nikkei4<-readcsv("h:=y=ynikkei4csv",header=t) (1) nikkei header=t nikkei4csv 4 4 nikkei nikkei4<-dataframe(n

mosaic Daniel Kaplan * 1 Nicholas J. Horton * 2 Randall Pruim * 3 Macalester College Amherst College Calvin College St. Paul, MN Amherst, MA Grand Rap

270万回再生レポート

以下の内容について説明する 1. VAR モデル推定する 2. VAR モデルを用いて予測する 3. グレンジャーの因果性を検定する 4. インパルス応答関数を描く 1. VAR モデルを推定する ここでは VAR(p) モデル : R による時系列分析の方法 2 y t = c + Φ 1 y t

ワードプロセッシングについて

1 1 ( ) ( % mm % A B A B A 1

untitled

超簡単、売上入力画面作成

1 Amazon.co.jp *1 5 review *2 web Google web web 5 web web 5 (a) (b) (c) 3 S-PLUS S S-PLUS 1 S-PLUS S R R RMeCab *3 R term matrix S-PLUS S-PLUS *1 Ama

橡統計担当者のためのエクセル表紙.PDF

2. S 2 ɛ 3. ˆβ S 2 ɛ (n p 1)S 2 ɛ χ 2 n p 1 Z N(0, 1) S 2 χ 2 n T = Z/ S 2 /n n t- Z T = S2 /n t- n ( ) (n+1)/2 Γ((n + 1)/2) f(t) = 1 + t2 nπγ(n/2) n

Transcription:

R 2001 9 R R S Splus R S 1 R 1: R 2 [File] [Exit] 1

q( ) 2: R 2 R R R R C:nProgram FilesnRnrw1030) [File] [Change Dir] c:ndatadir OK 2

2.1 7+3 1 10 7-3 7*3 7/3 7^3 2 > 7+3 [1] 10 > 7-3 [1] 4 > 7*3 [1] 21 > 7/3 [1] 2.333333 > 7^3 [1] 343 > 7*(1+2) [1] 21 > 2*6+2 [1] 14 > 6/3*2 [1] 4 > 2^3*4 [1] 32 R 1 R 2 [1] 3

2.2 2.5 3 10 > 2.5*3 [1] 7.5 > 2.5*4 [1] 10 > 2.5*5 [1] 12.5 > 2.5*6 [1] 15 > 2.5*7 [1] 17.5 > 2.5*8 [1] 20 > 2.5*9 [1] 22.5 > 2.5*10 [1] 25 2.5 > h<-2.5 h 2.5 3 h > h<-2.5 > h*3 [1] 7.5 > h*4 [1] 10 > h*5 3 < ; ; > 4

[1] 12.5 > h*6 [1] 15 2.3 2.3.1 c( ) seq( ) rep( ) 2.5 h h* c( ) 4 > w<-c(3,4,5,6,7,8,9,10) > w [1] 3 4 5 6 7 8 9 10 > h*w [1] 7.5 10.0 12.5 15.0 17.5 20.0 22.5 25.0 w 3 10 h 1 1 100 > w<-c(1,2,3,4,5,...,99,100) seq( ) 1 100 4 c( ) c concatenate 5

> w<-seq(1,100) > w [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 [37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 [91] 91 92 93 94 95 96 97 98 99 100 5 [1] [19] 6 > v<-seq(100,110) > v [1] 100 101 102 103 104 105 106 107 108 109 110 > seq(100,110,2) [1] 100 102 104 106 108 110 > seq(1,10)/10 [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 > seq(1,2,length=20) [1] 1.000000 1.052632 1.105263 1.157895 1.210526 1.263158 1.315789 1.368421 [9] 1.421053 1.473684 1.526316 1.578947 1.631579 1.684211 1.736842 1.789474 [17] 1.842105 1.894737 1.947368 2.000000 seq(s,e) s e 1 2 seq(s,e,step) rep( ) rep(2,4) (2,2,2,2) rep( ) > rep(2,4) [1] 2 2 2 2 > rep(c(0,1),3) [1] 0 1 0 1 0 1 > rep(c(-1,0,1),c(1,2,3)) [1] -1 0 0 1 1 1 1 2 3 5 100 1000 1000 6 [1] 6

2.3.2 > w[3] 3 w 3 3 w[3] [ ] > w<-seq(1,100) > w[3] [1] 3 > w[11:20] [1] 11 12 13 14 15 16 17 18 19 20 > w[c(1,3,7,10)] [1] 1 3 7 10 > w[seq(50,60)] [1] 50 51 52 53 54 55 56 57 58 59 60 > w[seq(1,20,2)] [1] 1 3 5 7 9 11 13 15 17 19 w[11:20] 11 20 c( ) seq( ) seq(1,20,2) 1 2 20 3 w>50 [ ] 50 w>50 w>50 TRUE FALSE W 1 50 w>50 50 TRUE FALSE 7

3: TRUE < > <= >= ==!= & and j or > w<-seq(1,10) > w [1] 1 2 3 4 5 6 7 8 9 10 > w[w>=5 & w<=7] [1] 5 6 7 8

> w<-seq(1,10) > w [1] 1 2 3 4 5 6 7 8 9 10 > w[-2] [1] 1 3 4 5 6 7 8 9 10 > w[-c(1,3,5)] [1] 2 4 6 7 8 9 10 > w[-2:9] Error: only 0's may mix with negative subscripts > w[-(2:9)] [1] 1 10 2:9 7 2.3.3 + ; w<-seq(1,10) > w [1] 1 2 3 4 5 6 7 8 9 10 > w+2 [1] 3 4 5 6 7 8 9 10 11 12 > w-5 [1] -4-3 -2-1 0 1 2 3 4 5 7 2 9 1 9

> x<-c(1,2,3,4,5) y<-c(1,3,5,7,9) > x+y [1] 2 5 8 11 14 > x-y [1] 0-1 -2-3 -4 > x*y [1] 1 6 15 28 45 > x/y [1] 1.0000000 0.6666667 0.6000000 0.5714286 0.5555556 1 R 8 1 1 GDP 2 GDP 3 4 1 c( ) matrix( ) matrix(,nrow=,ncol=,byrow=f or T) 1:6 > matrix(1:6,nrow=2) [,1] [,2] [,3] [1,] 1 3 5 8 10

[2,] 2 4 6 > matrix(1:6,nrow=3) [,1] [,2] [1,] 1 4 [2,] 2 5 [3,] 3 6 9 nrow nrow ncol byrow T F F T > matrix(1:6,nrow=2,byrow=t) [,1] [,2] [,3] [1,] 1 2 3 [2,] 4 5 6 > matrix(1:6,nrow=3,byrow=t) [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 5 6 10 > A<-matrix(1:6,nrow=3) B<-matrix(c(1,3,5,7,9,11),nrow=3) > A [,1] [,2] [1,] 1 4 [2,] 2 5 [3,] 3 6 > B [,1] [,2] [1,] 1 7 9 10 1 6 byrow 11

[2,] 3 9 [3,] 5 11 > A+B [,1] [,2] [1,] 2 11 [2,] 5 14 [3,] 8 17 > A-B [,1] [,2] [1,] 0-3 [2,] -1-4 [3,] -2-5 > A*B [,1] [,2] [1,] 1 28 [2,] 6 45 [3,] 15 66 > A/B [,1] [,2] [1,] 1.0000000 0.5714286 [2,] 0.6666667 0.5555556 [3,] 0.6000000 0.5454545 R %*% A B > A %*% B Error in A %*% B : non-conformable arguments 11 A B 3 2 AB 0 B t(b) 11 12

> A %*% t(b) [,1] [,2] [,3] [1,] 29 39 49 [2,] 37 51 65 [3,] 45 63 81 > t(a) %*% B [,1] [,2] [1,] 22 58 [2,] 49 139 3 2 2 3 3 3 2 3 3 2 2 2 A c(1,2) 1 1 %*% > x<-c(1,2) > A %*% x [,1] [1,] 9 [2,] 12 [3,] 15 c(1,2,3) A > y<-c(1,2,3) > y %*% A [,1] [,2] [1,] 14 32 A y y 3 1 3 y 0 A R 13

2.4 1990 2000 GDP R gdpcons.txt 12 13 ls( ) > ls() [1] "gdpcons" "last.warning" "year" gdpcons year 14 gdpcons > gdpcons GDP CONS [1,] 312712.7 174382.7 [2,] 321490.5 177074.9 [3,] 331710.7 184799.3 [4,] 339823.8 189292.0 [5,] 353436.2 194237.4 [6,] 368184.1 201627.8 [7,] 379895.7 209050.0 [8,] 399442.3 217356.6 [9,] 424657.3 229129.5 [10,] 445468.8 238784.9 [11,] 469780.5 248840.1 [12,] 481660.7 256905.6 [13,] 483375.6 261560.2 [14,] 485498.4 266385.2 [15,] 490730.7 272342.2 [16,] 502794.3 277906.5 [17,] 520053.8 284766.8 [18,] 521315.1 281393.7 [19,] 518380.7 285094.0 [20,] 525695.8 289454.2 [21,] 530312.8 288981.1 > year [1] 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 [16] 1995 1996 1997 1998 1999 2000 12 gdpcons.txt 13 14 rm( ) 14

gdpcons year 15 dim( ) length( ) > dim(gdpcons) [1] 21 2 > dim(year) NULL > length(year) [1] 21 dim( ) length( ) gdpcons year gdpcons 1 GDP 2 CONS > dimnames(gdpcons) [[1]] NULL [[2]] [1] "GDP" "CONS" dimnames( ) [[1]] [[2]] 16 NULL 1 \GDP" 2 \CONS" gdpcons > dimnames(gdpcons)[[1]]<-year > gdpcons GDP CONS 1980 312712.7 174382.7 1981 321490.5 177074.9 1982 331710.7 184799.3 1983 339823.8 189292.0 15 16 15

1984 353436.2 194237.4 1985 368184.1 201627.8 1986 379895.7 209050.0 1987 399442.3 217356.6 1988 424657.3 229129.5 1989 445468.8 238784.9 1990 469780.5 248840.1 1991 481660.7 256905.6 1992 483375.6 261560.2 1993 485498.4 266385.2 1994 490730.7 272342.2 1995 502794.3 277906.5 1996 520053.8 284766.8 1997 521315.1 281393.7 1998 518380.7 285094.0 1999 525695.8 289454.2 2000 530312.8 288981.1 dimnames( ) 17 gdpcons GDP GDP gdpcons 1 [ ] A[1,1] 1 1 A(1,1) 1 GDP > gdpcons[1,1] [1] 312712.7 > gdpcons[1:3,1] 1980 1981 1982 312712.7 321490.5 331710.7 > gdpcons[,1] 1980 1981 1982 1983 1984 1985 1986 1987 312712.7 321490.5 331710.7 339823.8 353436.2 368184.1 379895.7 399442.3 1988 1989 1990 1991 1992 1993 1994 1995 424657.3 445468.8 469780.5 481660.7 483375.6 485498.4 490730.7 502794.3 1996 1997 1998 1999 2000 520053.8 521315.1 518380.7 525695.8 530312.8 1 1 gdpcons(1,1) 1:3 17 [[ ]] 2.5 16

1 3 1 gdpcons 3 gdpcons[3,] "GDP" "1980" 18 > gdpcons["2000","cons"] [1] 288981.1 > gdpcons["1995",] GDP CONS 502794.3 277906.5 x<-c("a",1,2,3,"b") > x<-c("a",1,2,3,"b") > x [1] "a" "1" "2" "3" "b" GDP "bubble" "b" "a" 1987 1991 1980 1986 "b" 1987 1991 "bubble" "a" id" 18 R 17

> id<-c("b","b","b","b","b","b","b","bubble","bubble","bubble","bubble","bubble", + "a","a","a","a","a","a","a","a","a") > length(id) [1] 21 21 R id gdpcons 3 rbind( ) cbind( ) cbind( ) > cbind(gdpcons,id) gdp cons id 1980 "312712.7" "174382.7" "b" 1981 "321490.5" "177074.9" "b" 1982 "331710.7" "184799.3" "b" 1983 "339823.8" "189292" "b" 1984 "353436.2" "194237.4" "b" 1985 "368184.1" "201627.8" "b" 1986 "379895.7" "209050" "b" 1987 "399442.3" "217356.6" "bubble" 1988 "424657.3" "229129.5" "bubble" 1989 "445468.8" "238784.9" "bubble" 1990 "469780.5" "248840.1" "bubble" 1991 "481660.7" "256905.6" "bubble" 1992 "483375.6" "261560.2" "a" 1993 "485498.4" "266385.2" "a" 1994 "490730.7" "272342.2" "a" 1995 "502794.3" "277906.5" "a" 1996 "520053.8" "284766.8" "a" 1997 "521315.1" "281393.7" "a" 1998 "518380.7" "285094" "a" 1999 "525695.8" "289454.2" "a" 2000 "530312.8" "288981.1" "a" data.frame( ) 18

> gdpcons<-data.frame(gdpcons,id) > gdpcons gdp cons id 1980 312712.7 174382.7 b 1981 321490.5 177074.9 b 1982 331710.7 184799.3 b 1983 339823.8 189292.0 b 1984 353436.2 194237.4 b 1985 368184.1 201627.8 b 1986 379895.7 209050.0 b 1987 399442.3 217356.6 bubble 1988 424657.3 229129.5 bubble 1989 445468.8 238784.9 bubble 1990 469780.5 248840.1 bubble 1991 481660.7 256905.6 bubble 1992 483375.6 261560.2 a 1993 485498.4 266385.2 a 1994 490730.7 272342.2 a 1995 502794.3 277906.5 a 1996 520053.8 284766.8 a 1997 521315.1 281393.7 a 1998 518380.7 285094.0 a 1999 525695.8 289454.2 a 2000 530312.8 288981.1 a data.frame( data.frame( ) gdp > gdpcons[,1] [1] 312712.7 321490.5 331710.7 339823.8 353436.2 368184.1 379895.7 399442.3 [9] 424657.3 445468.8 469780.5 481660.7 483375.6 485498.4 490730.7 502794.3 [17] 520053.8 521315.1 518380.7 525695.8 530312.8 > gdpcons$gdp [1] 312712.7 321490.5 331710.7 339823.8 353436.2 368184.1 379895.7 399442.3 [9] 424657.3 445468.8 469780.5 481660.7 483375.6 485498.4 490730.7 502794.3 [17] 520053.8 521315.1 518380.7 525695.8 530312.8 > attach(gdpcons) > gdp [1] 312712.7 321490.5 331710.7 339823.8 353436.2 368184.1 379895.7 399442.3 [9] 424657.3 445468.8 469780.5 481660.7 483375.6 485498.4 490730.7 502794.3 [17] 520053.8 521315.1 518380.7 525695.8 530312.8 19

attach( ) 19 attach( ) detach( ) detach(gdpcons) attach(gdpcons) id > id [1] "b" "b" "b" "b" "b" "b" "b" "bubble" [9] "bubble" "bubble" "bubble" "bubble" "a" "a" "a" "a" [17] "a" "a" "a" "a" "a" 2.5 R R 4 > list(gdp,cons,id) [[1]] [1] 312712.7 321490.5 331710.7 339823.8 353436.2 368184.1 379895.7 399442.3 [9] 424657.3 445468.8 469780.5 481660.7 483375.6 485498.4 490730.7 502794.3 [17] 520053.8 521315.1 518380.7 525695.8 530312.8 [[2]] [1] 174382.7 177074.9 184799.3 189292.0 194237.4 201627.8 209050.0 217356.6 [9] 229129.5 238784.9 248840.1 256905.6 261560.2 266385.2 272342.2 277906.5 [17] 284766.8 281393.7 285094.0 289454.2 288981.1 19 20

[[3]] [1] "b" "b" "b" "b" "b" "b" "b" "bubble" [9] "bubble" "bubble" "bubble" "bubble" "a" "a" "a" "a" [17] "a" "a" "a" "a" "a" gdp cons id list( ) [[1]] [[2]] [[3]] list(gdp,cons,id)[[2]] cons 3 GDP R 3.1 > attach(gdpcons) > plot(year,gdp) GDP 4 plot( ) X Y plot( ) 4 20 > plot(year,gdp,type="l",main="gdp from 1980 to 2000") 20 pch="." 21

gdp 350000 400000 450000 500000 1980 1985 1990 1995 2000 year 4: GDP type type="l" help(plot) 21 GDP from 1980 to 2000 gdp 350000 400000 450000 500000 1980 1985 1990 1995 2000 year 5: GDP ( ) R Version 1.3.0 Microsoft Word 21 help.start( ) Internet Explorer 22

ps jpeg GDP plot(year,gdp,cons) 6 > plot(year,gdp,main="gdp and Consumption",type="l", + ylim=c(100000,600000)) > lines(year,cons,lty=2) plot( ) GDP lines( ) 2 ylim=c(100000,600000) 100000 600000 GDP 300000 cons cons 170000 300000 GDP lines(year,cons,...) lines( ) lty 22 GDP and Consumption gdp 1 e+05 2 e+05 3 e+05 4 e+05 5 e+05 6 e+05 1980 1985 1990 1995 2000 year 6: GDP 22 GDP CONS 23

3.2 plot( ) GDP gdp ; cons gdp 23 > par(mfrow=c(1,2)) > growth.gdp<-(gdp[2:21]-gdp[1:20])/gdp[2:21]*100 > growth.cons<-(cons[2:21]-cons[1:20])/cons[2:21]*100 > plot(year[2:21],growth.gdp,main="gdp and Consumption Growth", + type="l") > lines(year[2:21],growth.cons,lty=2) > saving.rate<-(gdp-cons)/gdp*100 > plot(year,saving.rate,main="macro Saving Rate", + type="l") 1 2 par( ) GDP 100 1 plot( ) plot( ) lines( ) plot 7 24 23 R 24

GDP and Consumption Growth Macro Saving Rate growth.gdp 0 1 2 3 4 5 6 saving.rate 44.5 45.0 45.5 46.0 46.5 47.0 1985 1990 1995 2000 year[2:21] 1980 1985 1990 1995 2000 year 4 7: GDP GDP GDP 4.1 mean( ) var( ) sqrt( ) 1 var( ) n (n-1)/n > mean(growth.gdp) mean(growth.cons) [1] 2.589886 [1] 2.482524 > n<-length(growth.gdp) 24 1 25

> sqrt(var(growth.gdp)*(n-1)/n) [1] 1.78986 > sqrt(var(growth.cons)*(n-1)/n) [1] 1.494700 GDP GDP 1980 1990 10 1990 > ysub<-seq(1981,2000) > mean(growth.gdp[ysub<=1989]) [1] 3.849082 > mean(growth.gdp[ysub>1989]) [1] 1.559634 > mean(growth.cons[ysub<=1989]) [1] 3.426539 > mean(growth.cons[ysub>1989]) [1] 1.710148 > sqrt(var(growth.gdp[ysub<=1989])) [1] 1.157558 > sqrt(var(growth.gdp[ysub>1989])) [1] 1.655496 > sqrt(var(growth.cons[ysub<=1989])) [1] 1.096810 > sqrt(var(growth.cons[ysub>1989])) [1] 1.430941 var( ) ysub 1980 2000 1981 2000 20 20 20 26

T F 1990 10 80 Volatility 1990 4.2 hist( ) GDP > hist(growth.gdp) 8 Histogram of growth.gdp Frequency 0 1 2 3 4 1 0 1 2 3 4 5 6 growth.gdp 8: GDP 27

4.3 GDP 4.3.1 GDP GDP GDP GDP vs Consumption growth.cons 1 0 1 2 3 4 5 0 1 2 3 4 5 6 growth.gdp 9: GDP GDP GDP 28

C Y C = + Y ;1 H 0 : = 0 vs H 1 : 6= 0 > x<-growth.gdp[1:19] > y<-growth.cons[2:20] > reg1<-lm(y~x) > summary(reg1) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -4.0393-0.2069 0.2463 0.5585 1.6227 Coefficients: Estimate Std. Error t value Pr(> t ) (Intercept) 1.2425 0.5446 2.282 0.0357 * x 0.4815 0.1689 2.850 0.0111 * --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 Residual standard error: 1.319 on 17 degrees of freedom Multiple R-Squared: 0.3234, Adjusted R-squared: 0.2836 F-statistic: 8.125 on 1 and 17 DF, p-value: 0.01106 GDP 1 19 GDP gdp[1:19] 25 cons[2:20] 25 29

lm( ) summary( ) lm( ) y ~ x ~ y~x 1 + x 2 + x 3 + GDP 0.4815 T 2.850 5% 26 4.3.2 S Y = + T T T=1,2,3,.. > length(saving.rate) [1] 21 > trend<-seq(1,21) > reg1<-lm(saving.rate~trend) > summary(reg1) Call: lm(formula = saving.rate ~ trend) Residuals: Min 1Q Median 3Q Max 26 GDP R 30

-0.9506-0.6835-0.1488 0.4676 1.7126 Coefficients: Estimate Std. Error t value Pr(> t ) (Intercept) 44.94598 0.35065 128.178 <2e-16 *** trend 0.03382 0.02793 1.211 0.241 --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 Residual standard error: 0.7749 on 19 degrees of freedom Multiple R-Squared: 0.07166, Adjusted R-squared: 0.0228 F-statistic: 1.467 on 1 and 19 DF, p-value: 0.2407 trend 0.034 T 1.211 1980 2000 27 5 gdpcons 1. read.table( ) 1 2 28 gdpcons<-read.table("gdpcons.txt",header=t) 1 29 2. scan( ) scan( ) 27 28 gdpcons 29 read.table( ) 31

> x<-scan() 1: 1 2: 2 3: 5 4: 6 5: 8 6: 9 7: Read 6 items > x [1] 1 2 5 6 8 9 scan() 1 x 30 R write( ) write( ) 31 write(t(x),"filename",ncol=ncol(x)) t(x) x 24 R 30 scan( ) help(scan) 31 R 32

32 R m2y <- function(x){ if((length(x) %% 12)!= 0) return("inconsistent Number of Data") n <- length(x) / 12 y <- 1:n for(i in 1:n){ b <- 12*(i-1)+1 e <- 12*(i-1)+12 y[i] <- mean(x[b:e]) } y } m2y.r R > source("m2y.r") x.month x.year<-m2y(x.month) m2y( ) 33 R R Save workspace image? OK.Rdata.Rdata R 32 33 [File] [Source R code] OK 33

.Rdata.Rdata [File] [Load Workspace] [Save Workspace] [Save Workspace].Rdata.Rdata 34 34.Rdata 34

YEAR GDP CONS 1980 312712.7 174382.7 1981 321490.5 177074.9 1982 331710.7 184799.3 1983 339823.8 189292.0 1984 353436.2 194237.4 1985 368184.1 201627.8 1986 379895.7 209050.0 1987 399442.3 217356.6 1988 424657.3 229129.5 1989 445468.8 238784.9 1990 469780.5 248840.1 1991 481660.7 256905.6 1992 483375.6 261560.2 1993 485498.4 266385.2 1994 490730.7 272342.2 1995 502794.3 277906.5 1996 520053.8 284766.8 1997 521315.1 281393.7 1998 518380.7 285094.0 1999 525695.8 289454.2 2000 530312.8 288981.1 35