시간 시퀀스 코드(R언어)
7872 단어 시간 순서
시간 시퀀스 코드(R언어)
#----------------------- ---------------------------------
setwd("D:/data")
da = read.table("m-ibm6708.txt",header = T)# data.frame
ibm = da$ibm
sp = da$sprtn
plot(sp,ibm)
cor(sp,ibm)
marketmodel = lm(ibm~sp)
summary(marketmodel)# summary
#---------------------------------------------------------------
#---------------------------------------------------------
#Measure of Correlation and Dependence
cor(sp,ibm) #pearson's correlation
cor(sp,ibm,method = "spearman")#Spearman's rank correlation
cor(rank(sp),rank(ibm)) #Spearman's rank correlation
cor(sp,ibm,method = "kendall")#Kendall's tau
#invariance to monotonic nonlinear transformation
cor(exp(sp),exp(ibm)) #not invariant
cor(exp(sp),exp(ibm),method = "spearman")#invaraint
cor(rank(exp(sp)),rank(exp(ibm)))
cor(exp(sp),exp(ibm),method = "kendall")#invaraint
#---------------------------------------------------------
#--------------------------------------------------------------------
#ACF\PACF\
#Monthly returns of IBM stock from 1926 to 2008
setwd("D:/data")
da2 = read.table("m-ibm6708.txt",header = T)
ibm=da2[,2]
par(mfcol=c(2,1))
acf(ibm,lag=100)#100
pacf(ibm,lag=100)#
# ( p 0.05, )
B1=Box.test(ibm,lag=5,type='Ljung')#H0:rho_1=...=rho_5
B2=Box.test(ibm,lag=10,type='Ljung')#H0:rho_1=...=rho_10
B1$statistic
B1$p.value
B2$statistic
B2$p.value #Question:Q(5),Q(10) ?
#--------------------------------------------------------------------