作业:
1) A plot of data from a time series, which shows a cyclical pattern – please show a time series plot and identify the length of the major cycle.
2) Data from a full factorial or fractional factorial experiment with at least 2 factors – please identify the factors and the dependent variable. It is sufficient to provide me with a small part of the dataset (e.g. 10 records), if the dataset is large.
kings <- scan("http://robjhyndman.com/tsdldata/misc/kings.dat",skip=3)
kings
kingstimeseries <- ts(kings)
kingstimeseries
# An example is a data set of the number of births per month in New York city, from January 1946 to December 1959
births <- scan("http://robjhyndman.com/tsdldata/data/nybirths.dat")
birthstimeseries <- ts(births, frequency=12, start=c(1946,1))
birthstimeseries
#
souvenir <- scan("http://robjhyndman.com/tsdldata/data/fancy.dat")
souvenirtimeseries <- ts(souvenir, frequency=12, start=c(1987,1))
souvenirtimeseries
#
plot.ts(kingstimeseries)
#
plot.ts(birthstimeseries)
#
plot.ts(souvenirtimeseries)
#
logsouvenirtimeseries <- log(souvenirtimeseries)
plot.ts(logsouvenirtimeseries)
#
library("TTR")
birthstimeseriescomponents <- decompose(birthstimeseries)
birthstimeseriescomponents$seasonal
# get the estimated values of the seasonal component
plot(birthstimeseriescomponents)
#
birthstimeseriescomponents <- decompose(birthstimeseries)
birthstimeseriesseasonallyadjusted <- birthstimeseries - birthstimeseriescomponents$seasonal
plot(birthstimeseriesseasonallyadjusted)
#tell where the data come from
datafilename="http://personality-project.org/R/datasets/R.appendix1.data"
#read the data
data.ex1=read.table(datafilename,header=T)
#do the analysis
aov.ex1 = aov(Alertness~Dosage,data=data.ex1)
#show the table
summary(aov.ex1) # 2-way
datafilename="http://personality-project.org/r/datasets/R.appendix2.data"
#read the data
data.ex2=read.table(datafilename,header=T)
#show the data
data.ex2
#do the analysis
aov.ex2 = aov(Alertness~Gender*Dosage,data=data.ex2)
#show the summary table
summary(aov.ex2)
后面贴答案