明天交作业...共8论坛币,若不足可以微信,谢谢!
Exercise 3
Consider the data set from the file sunspot.XLSX. This set contains sunspots, which are “are temporary phenomena on the Sun's photosphere that appear as spots darker than the surrounding areas” [Wikipedia].
a) Are there missing values? If yes, how to replace them? Carry your idea out.
b) Are there outliers or irregular values? Check and if yes, please filter.
c) Is there are trend and other deterministic effects? Please extract trend and seasonality.
Exercise 4
Consider the data set from the file sampleSeries.xlsx.
a) Fit an appropriate time series model to the data set. Describe your decisions.
b) Create a set of 1000 simulations with length 500.
以上是原题,以下是我的code,问题是C)和4a)b),在最底下
#3.
#a)
library(readxl)
sunspots<-read_excel("C:/Users/Pretty-PC/Desktop/Homework_Assignment/Homework_Assignment/Sunspots.xlsx")
sun<-as.numeric(unlist(sunspots[,3]))
sum(is.na(sun))
lag=10
ma = numeric(length(sun))
for (k in (lag+1):(length(sun)-lag))
{
ma[k]<-mean(sun[(k-lag):(k + lag)],na.rm=TRUE)
}
plot(sun,type="l")
lines(ma,col="blue")
sum(is.na(sun))
sum(is.na(ma))
sun<-ma
#b)
x=sun[1:2000]
y=sun[1:2000]-mean(sun[1:2000])
z=diff(lag(x))
plot(z,type="l")
mean(z)
var(z)
sd(z)
a=z/sd(z)
plot(a,type="l")
sd(a)
y<-z[(z>-0.1)&(z<+0.1)]
plot(y,type = "l")
sd(y)
y<-numeric(length(z)-1)
counter=1
for(k in 1:length(z))
{
if(z[k]>-0.3)
{
y[counter]=z[k]
counter-counter+1
}
else
{
}
}
#c)如何取趋势....
for(k in 2:length(x))
{
epsilon=rnorm(1,mean=0,sd=0.5)
sun[k]=sun[k-1]+epsilon
}
plot(x,type="l")
#4.???求助如何选模型