讲解:R、data、RMatlab|SQL

Homework 5For this homework install the updated simts package as well as the expsmooth, quantmod and pageviews Rpackages from CRAN.Question 1Suppose we collect a time series data X = (X1, . . . , XT ).(a) According to the following R outputs, please write the estimated AR(1) model for the data X. What isthe estimation for the variance of withe noise?> fit.ML = estimate(AR(1),X, demean = FALSE)> fit.MLFitted model: AR(1)Estimated parameters:Call:arima(x = as.numeric(Xt), order = c(p, intergrated, q), seasonal = list(order = c(P,seasonal_intergrated, Q), period = s), include.mean = demean, method = meth)Coefficients:ar10.97s.e. 0.04sigma^2 estimated as 0.8929: log likelihood = -137.17, aic = 278.34(b) Please give out the 95 percent confidence interval for φ(the 97.5 percent quantile is 1.96).Is there anydrawback of this confidence interval?Any method to avoid this issue? Please state in detail.(c)Now we use AIC and BIC to select the model from a candidates pool. Model 1 has AIC=246.34 andBIC=268.64. Model 2 has AIC=256.45 and BIC=264.26.If the sets of candidate models (i.e. model 1 and model 2 we are considering) do not include the true model.Which information criteria we should use? Which model we should select? If the sets of candidate models(i.e. model 1 and model 2 we are considering) include the true model. Which information criteria we shoulduse? Which model we should select?(d)After selecting the model, we have the following R outputs.Based on this estimated model, if we know that XT −4 = 1, XT −3 = 1.3, XT −2 = 0.8, XT −1 = 1 and XT = 0.6,please give one day ahead prediction XTT +1 and two day ahead prediction XTT +2.Show the details of your work.Fitted model: AR(2)Estimated parameters:Call:arima(x = as.numeric(Xt), order = c(p, intergrated, q), seasonal = list(order = c(P,seasonal_intergrated, Q), period = s), include.mean = demean, method = meth)Coefficients:1ar1 ar2-0.3 0.6s.e. 0.0804 0.0819sigma^2 estimated as 0.9282: log likelihood = -138.97, aic = 246.34Question 2The data hospital contains monthly patient counts for 767 hospitals from January 2000 to December 2007.Focus on the eighth hospital (i.e. hospital[, 8]):1. Comment on the plot of the time series: does it appear to be stationary?2. If not stationary, use a linear regression to remove possible trends and/or seasonalities.3. Perform a diagnostic analysis on the residuals. Please state the purpuse of six graphs one by one indetail. does there appear to be dependence between lags?4. If there appears to be dependence in the residuals, propose and estimate a time series model for them.Justify the model.Question 3Using the quantmod library, download the stock prices of Microsoft from January 1st, 2000 (use the symbol“MSFT” within the getSymbols() function).1. Comment on the plot of the time series: does it appear to be stationary? If not, suggest how to make itstationary.2. To obtain the stock returns we need to take a first difference of the stock prices: does this time seriesappear to be stationary?3. Analyse the ACF and PACF plots of the returns: does there appear to be dependence?4. Analyse the ACF and PACF plots of the absolute value of the returns: does there appear to bedependence? Discuss.5. Propose and estimate a time series model for the returns and for the absolute returns. Justify themodels.Question 4Consider the utility data that contains hourly utility demand in the Midwest from January 1st 2003 toMay 7th 2003. Suppose you’re an analyst for the energy company:1. Apply linear regression (or another method) on time-related variables (e.g. hours, days, months) toobtain stationary residuals.2. Remove the last 24 hours (observations) from the residuals:a) Suggest and estimate a time series model for the first 3000 observations.b) Deliver point forecasts and 95% confidence intervals for the next 24 hours.c) Based on the point forecasts you obtained from the previous question, compute the MedianAbsolute Prediction Error (MAPE) of your point forecasts defined asMAP E = median are the j-ahead point forecasts and Xt+j are the j-ahead realizations representing theremoved 24 hours.2d) Based on the confidence intervals computed in question 3b, compute the empirical coverage ofyour confidence intervals (i.e. the percentage of times your confidence intervals contain the actualcorresponding future realization). Is it close to 95% ? If not, explain possible reasons why.Question 5Using the ukcars data representing the quarterly production of cars in the UK (in thousands) from the firstquarter of 1977 to the first quarter of 2005, do the following:1. Check if the time series is stationary and, if not, perform a linear regression to make the residualsstationary (use time and quarters as covariates).2. Estimate an AR(8) for the residuals using the MLE and give the parameters estimatesa) Give the parameter confidence intervals using their asymptotic distribution.b) Give the parameter confidence intervals using parametric bootstrap (B = 500)Question 6Consider the following code:set.seed(2)Xt = gen_gts(n = 200, AR(phi = c(0.75, 0.2), sigma2 = 1))B = 5000mat = matrix(0,B,52)mat[,1] = rep(Xt[199], B)mat[,2] = rep(Xt[200], B)for (i in 1:B){for (j in 3:52){mat[i,j] = 0.75*mat[i,(j-1)] + 0.2*mat[i,(j-2)] + rnorm(1)R留学生作业代做、代写data课程作业、代做R编程设计作业 调试Matlab程序|代做数据库SQL}}1. Explain what this code is doing.2. Change the code to obtain only point forecasts for the next 10 observations (i.e. 201 to 210).3. Use this code to deliver 95% confidence intervals for the next 10 observations (i.e. 201 to 210).4. Modify the code in order to obtain point forecasts and 95% confidence intervals for the next 20observations of following time series:Yt = gen_gts(n = 100, AR(phi = c(0.8), sigma2 = 0.5))Question 7Using the article_pageviews() function in the pageviews package, download the number of views for thearticle on “Cheese” (Cheese) from August 1st to September 30th (2018).1. Comment on the plot of this time series.2. Comment on the ACF and PACF plots of the time series.3. Use the robacf() function in the robcor package: do you notice a difference with the standard ACF?Discuss.34. Use the estimate() function to estimate the φ parameter of an AR(1) model using the MLE and theRGMWM: comment on the two estimates of φ.5. Adapting the code from Question 5, use the RGMWM estimates to deliver point forecasts and confidenceintervals for the next 28 days (October 1st to October 28th):a) Compute the MAPE for your point forecasts.b) Compute the empirical coverage of your confidence intervals.Question 8Consider the Ljung-Box statistic defined as:Qh = T(T + 2)X,where ρˆj is the estimated autocorrelation on a given time series. Show that, as T → ∞,meaning that the statistic tends towards a Chi-square distribution with h degrees of freedom.Question 9Please check the following models satisfy the conditions of causal and invertible ARMA models. (check theparamertric redundancy firstly)1. Xt − 1.5Xt−1 + 0.5Xt−2 = Wt − 1.8Wt−1 + 0.8Wt−22. Xt − 1.1Xt−1 + 0.28Xt−2 = Wt − 0.7Wt−1Question 10Consider the causal model:Xt = φXt−1 + Wt, t = 1, . . . , T,where Wt are i.d.d N(0, 1).1. Derive the conditional MLE for φ, say φˆ.2. Please find the theretical PACF values of Xt.3. From R output, we have φˆ = 0.94 and the standard error of φˆ is 0.05. please give our 95 percentageconfidence interval. Is this result reasonable or not? If we have X8 = 10, Please give the best linearprediction of X10.4. If we don’t have model assumptions on a series of observations: Y1, . . . , YN .. Now using the AICprincipal to select the model. If we have model 1 with AIC=275 and Model 2 with AIC=276. Whichmodel we shall use and explain the reason.5. Why is the property of stationay important when working with a time series?4Question 11Consider the theoretical ACF and PCAF are presented in the figure below. Using the figure below:1. Propose a reasonable model for this time series. Justify your answer.2. Propose a value of the model’s parameters. Justify your answer.## Warning: package simts was built under R version 3.5.2LagsACFTheoretical ACF plot0 5 10 15 20−0.5 0.0 0.5 1.0LagsPACFTheoretical PACF plot5 10 15 20−0.5 −0.4 −0.3 −0.2 −0.1 0.0Question 12(Adapted from Cryer & Chan Exercise 7.28 ) The data file named deere3 contains 57 consecutive values froma complex machine tool at Deere & Co. The values given are deviations from a target value in units of tenmillionths of an inch. The process employs a control mechanism that resets some of the parameters of themachine tool depending on the magnitude of deviation from target of the last item produced. Load the TSApackage and then use data(deere3) to load the data.1. Plot the data. Does it appear stationary?2. Plot the ACF and PACF for the data. Which values for ARMA(p, q) are suggested?53. Estimate the parameters of an AR(1) model for this series using maximum likelihood. Repeat this foran AR(2) model. Report the estimates, their standard errors, and the AIC values.4. Simulate from both fitted models using the estimated parameters, with n = 57. Plot the simulateddata for both models, and compare them to the original data.5. Using your observations from parts (3) and (4), which of AR(1) or AR(2) would you prefer and why?Question 13The data in sheep.dat are the sheep population (in millions) for England and Wales from 1867-1939. It canbe read into R with the commandsheep=ts(scan(‘sheep.dat’),start=1867)1. Plot the time series.2. Perform any transforms, take differences, and/or remove mean structure via regression to produce astationary series.3. Plot diagnostics from removing mean structure.4. Produce plots of the ACF and PACF of the stationary series.5. Justify a preliminary order of ARMA model.6. Fit the model, simulate from it, and compare with the data.7. Perform model diagnostics: calculate the residuals, check them for normality, and their ACF forremaining time series structure. Apply the Ljung-Box test.8. Make any adjustments to your model suggested by residuals diagnostics.9. State your final model, and include 1-2 sentences of justification.Question 14Please calculate the auto correlation function ρ(h) of Xt, where Xt comes from the following model.Xt = 1.4Xt−1 − 0.48Xt−2 + Wt − 0.2Wt−1 − 0.48Wt−2where Wt is a Gaussian white noise with variance σ2.Question 15In this question, after fitting a linear model, The model diagnostics plots are presented in Figure 1.Based on this diagnostic plot, what kind of model you will suggest to try? Please state your reason forselecting this model.6Figure 1: Diagnostic of the model7转自:http://www.daixie0.com/contents/18/4950.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,907评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,987评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,298评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,586评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,633评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,488评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,275评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,176评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,619评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,819评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,932评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,655评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,265评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,871评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,994评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,095评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,884评论 2 354

推荐阅读更多精彩内容