Time Series Analysis

本文通过实例演示了时间序列分析中的三个核心概念:趋势、序列依赖性和平稳性,并展示了如何使用R语言进行数据预处理、趋势消除及自相关性分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The three key concepts in time series analysis are
trend,
serial dependence, and

stationarity


blowfly <- read.table("c:\\temp\\blowfly.txt",header=T)
attach(blowfly)

names(blowfly)


flies <- ts(flies)

plot(flies)


length(flies)

par(mfrow=c(2,2))

sapply(1:4, function(x) plot(flies[-c(361: (361-x+1))], flies[-c(1:x)] ) )

sapply(7:10, function(x) plot(flies[-c((361-x+1):361)], flies[-c(1:x)] ) )

par(mfrow=c(1,1))

acf(flies,main="",col="red")

acf(flies,type="p",main="",col="red") 

second <- flies[201:361]

summary(lm(second~I(1:length(second))))

detrended <- second - predict(lm(second~I(1:length(second))))
par(mfrow=c(2,2))

ts.plot(detrended)

acf(detrended,main="")

acf(detrended,type="p",main="")

par(mfrow=c(1,1))


ma3 <- function (x) {
y <- numeric(length(x)-2)
for (i in 2:(length(x)-1)) {
y[i] <- (x[i-1]+x[i]+x[i+1])/3
}

y }



temperature <- read.table("c:\\temp\\temp.txt",header=T)
attach(temperature)
tm <- ma3(temps)
plot(temps)

lines(tm[2:158],col="blue") 


weather <- read.table("c:\\temp\\SilwoodWeather.txt",header=T)
attach(weather)

names(weather)

plot(upper,type="l")

length(upper)

index <- 1:6940

6940/19

time <- index/365.2632

model <- lm(upper~sin(time*2*pi)+cos(time*2*pi))

plot(time, upper, pch=".")

lines(time, predict(model),col="red",lwd=2)

summary(model)

plot(model$resid,pch=".")

windows(7,4)
par(mfrow=c(1,2))
acf(model$resid,main="")

acf(model$resid,type="p",main="") 

temp <- ts(as.vector(tapply(upper,list(month,yr),mean)))
windows(7,7)

acf(temp,main="")

ytemp <- ts(as.vector(tapply(upper,yr,mean)))
acf(ytemp,main="")




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值