Anda di halaman 1dari 2

R version 3.0.

3 (2014-03-06) -- "Warm Puppy"


Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> getwd()
[1] "C:/Users/PHELPS1526-09/Documents"
> setwd("W:\TemporaryStorage\Time Series\LabC")
Error: '\T' is an unrecognized escape in character string starting ""W:\T"
> setwd("W:\temporaryStorage\Time Series\LabC")
Error: '\T' is an unrecognized escape in character string starting ""W:\temporar
yStorage\T"
> setwd("W:\\TemporaryStorage\\Time Series\\LabC")
> getwd()
[1] "W:/TemporaryStorage/Time Series/LabC"
> nhe = scan("healthexpand.txt",skip = 1)
Error in file(file, "r") : cannot open the connection
In addition: Warning message:
In file(file, "r") :
cannot open file 'healthexpand.txt': No such file or directory
> nhe = scan("healthexpend.txt",skip = 1)
Read 50 items
> nhe
[1] 27346.1 29212.7 31878.0 34675.1 38540.3
[6] 41936.7 46203.5 51736.5 58726.6 66172.2
[11] 74823.3 83185.6 93086.4 103312.1 117093.3
[16] 133519.6 152965.6 173895.6 195448.6 221569.5
[21] 255682.9 296611.6 334570.5 368828.6 406328.4
[26] 444404.5 476704.9 518884.6 581470.0 647205.4
[31] 724022.7 791237.2 857685.1 921296.0 972515.6
[36] 1027296.9 1081593.2 1142365.4 1208589.8 1286836.0
[41] 1378022.8 1495320.8 1636958.8 1772230.8 1894686.6
[46] 2021045.8 2152064.8 2283485.4 2391383.7 2486293.2
> #convert to a ts object
> nhe.ts = ts(nhe,start = 1960, #starting date)
+ freq = 1)
>
> plot(nhe.ts) # dont have to specify x,y values because ts object
> plot(nhe.ts,col = "red",ylab = "Health Expenditures")
> ((nhe.ts[-1]-nhe.ts[-length(nhe.ts)]))*100
[1] 186660 266530 279710 386520 339640 426680
[7] 553300 699010 744560 865110 836230 990080
[13] 1022570 1378120 1642630 1944600 2093000 2155300
[19] 2612090 3411340 4092870 3795890 3425810 3749980
[25] 3807610 3230040 4217970 6258540 6573540 7681730
[31] 6721450 6644790 6361090 5121960 5478130 5429630
[37] 6077220 6622440 7824620 9118680 11729800 14163800
[43] 13527200 12245580 12635920 13101900 13142060 10789830

[49] 9490950
> nhe.ts
Time Series:
Start = 1960
End = 2009
Frequency = 1
[1] 27346.1 29212.7 31878.0 34675.1 38540.3
[6] 41936.7 46203.5 51736.5 58726.6 66172.2
[11] 74823.3 83185.6 93086.4 103312.1 117093.3
[16] 133519.6 152965.6 173895.6 195448.6 221569.5
[21] 255682.9 296611.6 334570.5 368828.6 406328.4
[26] 444404.5 476704.9 518884.6 581470.0 647205.4
[31] 724022.7 791237.2 857685.1 921296.0 972515.6
[36] 1027296.9 1081593.2 1142365.4 1208589.8 1286836.0
[41] 1378022.8 1495320.8 1636958.8 1772230.8 1894686.6
[46] 2021045.8 2152064.8 2283485.4 2391383.7 2486293.2
> plot(nhe.ts,col = "red",ylab = "Health Expenditures")
> per = (nhe.ts[-1]/nhe.ts[-length(nhe.ts)]-1)*100
> plot(per,type="o")
> acf(per)
> pacf(per)
> arima(per,order=c(1,0,0))
Call:
arima(x = per, order = c(1, 0, 0))
Coefficients:
ar1 intercept
0.9042
8.4925
s.e. 0.0600
1.8944
sigma^2 estimated as 2.015: log likelihood = -87.54, aic = 181.08
> fit = arima(per,order=c(1,0,0))
> fit
Call:
arima(x = per, order = c(1, 0, 0))
Coefficients:
ar1 intercept
0.9042
8.4925
s.e. 0.0600
1.8944
sigma^2 estimated as 2.015: log likelihood = -87.54, aic = 181.08
> crime = scan("crimestats.txt",skip=2)
Read 151 items
> crime.ts = ts(crime,start=c(1966,1),freq=12)
> plot(crime.ts)
> crime.ts = ts(crime,start=c(1966,1),freq=4)
> plot(crime.ts)
> plot(crime.ts,type="o",col="red")
> crime.ts = ts(crime,start=c(1966,1),freq=12)
> plot(crime.ts,type="o",col="red")
> crime1 = window(crime.ts,start=start(crome.ts),end = c(1971,6)

Anda mungkin juga menyukai