講解: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留學(xué)生作業(yè)代做速缨、代寫data課程作業(yè)锌妻、代做R編程設(shè)計作業(yè) 調(diào)試Matlab程序|代做數(shù)據(jù)庫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轉(zhuǎn)自:http://www.daixie0.com/contents/18/4950.html

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市旬牲,隨后出現(xiàn)的幾起案子仿粹,更是在濱河造成了極大的恐慌搁吓,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,110評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件吭历,死亡現(xiàn)場離奇詭異堕仔,居然都是意外死亡,警方通過查閱死者的電腦和手機晌区,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,443評論 3 395
  • 文/潘曉璐 我一進店門摩骨,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人契讲,你說我怎么就攤上這事仿吞』担” “怎么了捡偏?”我有些...
    開封第一講書人閱讀 165,474評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長峡迷。 經(jīng)常有香客問我银伟,道長,這世上最難降的妖魔是什么绘搞? 我笑而不...
    開封第一講書人閱讀 58,881評論 1 295
  • 正文 為了忘掉前任彤避,我火速辦了婚禮,結(jié)果婚禮上夯辖,老公的妹妹穿的比我還像新娘琉预。我一直安慰自己,他們只是感情好蒿褂,可當我...
    茶點故事閱讀 67,902評論 6 392
  • 文/花漫 我一把揭開白布圆米。 她就那樣靜靜地躺著,像睡著了一般啄栓。 火紅的嫁衣襯著肌膚如雪娄帖。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,698評論 1 305
  • 那天昙楚,我揣著相機與錄音近速,去河邊找鬼。 笑死堪旧,一個胖子當著我的面吹牛削葱,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播淳梦,決...
    沈念sama閱讀 40,418評論 3 419
  • 文/蒼蘭香墨 我猛地睜開眼析砸,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了谭跨?” 一聲冷哼從身側(cè)響起干厚,我...
    開封第一講書人閱讀 39,332評論 0 276
  • 序言:老撾萬榮一對情侶失蹤李滴,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后蛮瞄,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體所坯,經(jīng)...
    沈念sama閱讀 45,796評論 1 316
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,968評論 3 337
  • 正文 我和宋清朗相戀三年挂捅,在試婚紗的時候發(fā)現(xiàn)自己被綠了芹助。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,110評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡闲先,死狀恐怖状土,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情伺糠,我是刑警寧澤蒙谓,帶...
    沈念sama閱讀 35,792評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站训桶,受9級特大地震影響累驮,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜舵揭,卻給世界環(huán)境...
    茶點故事閱讀 41,455評論 3 331
  • 文/蒙蒙 一谤专、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧午绳,春花似錦置侍、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,003評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至耕漱,卻和暖如春算色,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背螟够。 一陣腳步聲響...
    開封第一講書人閱讀 33,130評論 1 272
  • 我被黑心中介騙來泰國打工灾梦, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人妓笙。 一個月前我還...
    沈念sama閱讀 48,348評論 3 373
  • 正文 我出身青樓若河,卻偏偏與公主長得像,于是被迫代替她去往敵國和親寞宫。 傳聞我的和親對象是個殘疾皇子萧福,可洞房花燭夜當晚...
    茶點故事閱讀 45,047評論 2 355

推薦閱讀更多精彩內(nèi)容