R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Ejemplo Calcular la funcion de autorrelacion parcial para

Xt=0.4Xt-1+0.25Xt-2-0.1Xt-3+Wt

W<-rnorm(1000)
X<-numeric(1000)
X1<-numeric(1000)
X2<-numeric(1000)
X3<-numeric(1000)
X4<-numeric(1000)

for(t in 4:1000)
X [t]<- 0.4*X[t-1]+0.25*X[t-2]-0.1*X[t-3]+W[t]
plot(X,type='l')

pacf(X)

pacf(X, plot = FALSE)
## 
## Partial autocorrelations of series 'X', by lag
## 
##      1      2      3      4      5      6      7      8      9     10     11 
##  0.376  0.260 -0.077  0.013  0.004 -0.038  0.066 -0.027 -0.004  0.012  0.033 
##     12     13     14     15     16     17     18     19     20     21     22 
## -0.036  0.009  0.004  0.032  0.030 -0.046 -0.038  0.004 -0.043 -0.003  0.026 
##     23     24     25     26     27     28     29     30 
##  0.000 -0.015  0.021  0.034 -0.030 -0.019  0.007 -0.004
for(t in 2:1000)
X1[t]<-X[t-1]

modelo1<-lm(X~X1)
summary(modelo1)
## 
## Call:
## lm(formula = X ~ X1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.0648 -0.7214 -0.0001  0.6966  3.6869 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.01554    0.03269  -0.475    0.635    
## X1           0.37604    0.02934  12.815   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.034 on 998 degrees of freedom
## Multiple R-squared:  0.1413, Adjusted R-squared:  0.1404 
## F-statistic: 164.2 on 1 and 998 DF,  p-value: < 2.2e-16
for(t in 3:1000)
X2[t]<-X[t-2]

modelo2<-lm(X~X1+X2)
summary(modelo2)
## 
## Call:
## lm(formula = X ~ X1 + X2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.3091 -0.6959 -0.0012  0.6661  3.2086 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.01157    0.03159  -0.366    0.714    
## X1           0.27798    0.03060   9.084   <2e-16 ***
## X2           0.26038    0.03061   8.507   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9985 on 997 degrees of freedom
## Multiple R-squared:  0.1994, Adjusted R-squared:  0.1978 
## F-statistic: 124.2 on 2 and 997 DF,  p-value: < 2.2e-16
for(t in 4:1000)
X3[t]<-X[t-3]

modelo3<-lm(X~X1+X2+X3)
summary(modelo3)
## 
## Call:
## lm(formula = X ~ X1 + X2 + X3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.3239 -0.7026  0.0044  0.6592  3.3275 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.01256    0.03151  -0.399   0.6902    
## X1           0.29831    0.03163   9.431   <2e-16 ***
## X2           0.28189    0.03177   8.874   <2e-16 ***
## X3          -0.07762    0.03166  -2.451   0.0144 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.996 on 996 degrees of freedom
## Multiple R-squared:  0.2042, Adjusted R-squared:  0.2018 
## F-statistic:  85.2 on 3 and 996 DF,  p-value: < 2.2e-16
for(t in 5:1000)
X4[t]<-X[t-4]

modelo4<-lm(X~X1+X2+X3+X4)
summary(modelo4)
## 
## Call:
## lm(formula = X ~ X1 + X2 + X3 + X4)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.3221 -0.7035 -0.0020  0.6503  3.3196 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.01238    0.03153  -0.393   0.6946    
## X1           0.29920    0.03173   9.429   <2e-16 ***
## X2           0.27852    0.03303   8.433   <2e-16 ***
## X3          -0.08114    0.03304  -2.456   0.0142 *  
## X4           0.01194    0.03181   0.375   0.7075    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9964 on 995 degrees of freedom
## Multiple R-squared:  0.2043, Adjusted R-squared:  0.2011 
## F-statistic: 63.88 on 4 and 995 DF,  p-value: < 2.2e-16
  1. Xt = .5Xt−1 + W t con X1 = 2 con X2 = 6.
W<-rnorm(1000)
X<-numeric(1000)
X1<-numeric(1000)
X2<-numeric(1000)
X3<-numeric(1000)
X4<-numeric(1000)

for(t in 4:1000)
X [t]<- 0.5*X[t-1]+W[t]
plot(X,type='l')

pacf(X)

pacf(X, plot = FALSE)
## 
## Partial autocorrelations of series 'X', by lag
## 
##      1      2      3      4      5      6      7      8      9     10     11 
##  0.487  0.014  0.019 -0.016 -0.020  0.004  0.025 -0.046  0.000 -0.007  0.017 
##     12     13     14     15     16     17     18     19     20     21     22 
##  0.017  0.020 -0.034  0.028  0.034  0.009 -0.049  0.002 -0.002  0.011 -0.002 
##     23     24     25     26     27     28     29     30 
##  0.037 -0.002  0.002  0.050 -0.022  0.029  0.020 -0.007
for(t in 2:1000)
X1[t]<-X[t-1]

modelo1<-lm(X~X1)
summary(modelo1)
## 
## Call:
## lm(formula = X ~ X1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.1435 -0.6298 -0.0161  0.6683  3.4216 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.02876    0.03267    0.88    0.379    
## X1           0.48720    0.02766   17.62   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.032 on 998 degrees of freedom
## Multiple R-squared:  0.2372, Adjusted R-squared:  0.2364 
## F-statistic: 310.3 on 1 and 998 DF,  p-value: < 2.2e-16
for(t in 3:1000)
X2[t]<-X[t-2]

modelo2<-lm(X~X1+X2)
summary(modelo2)
## 
## Call:
## lm(formula = X ~ X1 + X2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.1564 -0.6375 -0.0205  0.6630  3.4334 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.02838    0.03269   0.868    0.385    
## X1           0.48013    0.03167  15.162   <2e-16 ***
## X2           0.01454    0.03171   0.459    0.647    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.032 on 997 degrees of freedom
## Multiple R-squared:  0.2373, Adjusted R-squared:  0.2358 
## F-statistic: 155.1 on 2 and 997 DF,  p-value: < 2.2e-16
for(t in 4:1000)
X3[t]<-X[t-3]

modelo3<-lm(X~X1+X2+X3)
summary(modelo3)
## 
## Call:
## lm(formula = X ~ X1 + X2 + X3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.1553 -0.6392 -0.0199  0.6648  3.4231 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.027906   0.032707   0.853    0.394    
## X1          0.479848   0.031680  15.147   <2e-16 ***
## X2          0.005017   0.035143   0.143    0.887    
## X3          0.019978   0.031765   0.629    0.530    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.033 on 996 degrees of freedom
## Multiple R-squared:  0.2376, Adjusted R-squared:  0.2354 
## F-statistic: 103.5 on 3 and 996 DF,  p-value: < 2.2e-16
for(t in 5:1000)
X4[t]<-X[t-4]

modelo4<-lm(X~X1+X2+X3+X4)
summary(modelo4)
## 
## Call:
## lm(formula = X ~ X1 + X2 + X3 + X4)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.1683 -0.6386 -0.0172  0.6666  3.4211 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.028305   0.032728   0.865    0.387    
## X1           0.480181   0.031698  15.149   <2e-16 ***
## X2           0.005103   0.035156   0.145    0.885    
## X3           0.027961   0.035216   0.794    0.427    
## X4          -0.016718   0.031791  -0.526    0.599    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.033 on 995 degrees of freedom
## Multiple R-squared:  0.2379, Adjusted R-squared:  0.2348 
## F-statistic: 77.63 on 4 and 995 DF,  p-value: < 2.2e-16
  1. Xt = .5Xt−2 + 0.25Xt−1 + Wt con X1 = 2 con X2 = 4
W<-rnorm(1000)
X<-numeric(1000)
X1<-numeric(1000)
X2<-numeric(1000)
X3<-numeric(1000)
X4<-numeric(1000)

for(t in 4:1000)
X [t]<- 0.5*X[t-2]+0.25*X[t-1]+W[t]
plot(X,type='l')

pacf(X)

pacf(X, plot = FALSE)
## 
## Partial autocorrelations of series 'X', by lag
## 
##      1      2      3      4      5      6      7      8      9     10     11 
##  0.468  0.460  0.038  0.097  0.024 -0.036 -0.050  0.023  0.003  0.044 -0.022 
##     12     13     14     15     16     17     18     19     20     21     22 
##  0.001  0.024  0.004  0.025  0.061  0.020  0.032 -0.031 -0.001 -0.025 -0.065 
##     23     24     25     26     27     28     29     30 
## -0.057 -0.009 -0.019  0.001 -0.016  0.005 -0.008 -0.037
for(t in 2:1000)
X1[t]<-X[t-1]

modelo1<-lm(X~X1)
summary(modelo1)
## 
## Call:
## lm(formula = X ~ X1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.8118 -0.8023  0.0147  0.7717  4.7791 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.07345    0.03631  -2.023   0.0434 *  
## X1           0.46863    0.02798  16.746   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.141 on 998 degrees of freedom
## Multiple R-squared:  0.2194, Adjusted R-squared:  0.2186 
## F-statistic: 280.4 on 1 and 998 DF,  p-value: < 2.2e-16
for(t in 3:1000)
X2[t]<-X[t-2]

modelo2<-lm(X~X1+X2)
summary(modelo2)
## 
## Call:
## lm(formula = X ~ X1 + X2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.8715 -0.6785  0.0010  0.6694  3.7166 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.03936    0.03232  -1.218    0.224    
## X1           0.25266    0.02815   8.976   <2e-16 ***
## X2           0.46045    0.02815  16.356   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.014 on 997 degrees of freedom
## Multiple R-squared:  0.3845, Adjusted R-squared:  0.3833 
## F-statistic: 311.4 on 2 and 997 DF,  p-value: < 2.2e-16
for(t in 4:1000)
X3[t]<-X[t-3]

modelo3<-lm(X~X1+X2+X3)
summary(modelo3)
## 
## Call:
## lm(formula = X ~ X1 + X2 + X3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.8331 -0.6718  0.0121  0.6609  3.7070 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.03791    0.03234  -1.172    0.241    
## X1           0.23517    0.03173   7.411 2.68e-13 ***
## X2           0.45089    0.02926  15.409  < 2e-16 ***
## X3           0.03789    0.03175   1.193    0.233    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.014 on 996 degrees of freedom
## Multiple R-squared:  0.3854, Adjusted R-squared:  0.3835 
## F-statistic: 208.2 on 3 and 996 DF,  p-value: < 2.2e-16
for(t in 5:1000)
X4[t]<-X[t-4]

modelo4<-lm(X~X1+X2+X3+X4)
summary(modelo4)
## 
## Call:
## lm(formula = X ~ X1 + X2 + X3 + X4)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.9464 -0.6387  0.0020  0.6463  3.7928 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.03447    0.03223  -1.070  0.28497    
## X1           0.23127    0.03163   7.312 5.39e-13 ***
## X2           0.40724    0.03246  12.545  < 2e-16 ***
## X3           0.01542    0.03246   0.475  0.63492    
## X4           0.09666    0.03167   3.052  0.00233 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.01 on 995 degrees of freedom
## Multiple R-squared:  0.3911, Adjusted R-squared:  0.3886 
## F-statistic: 159.8 on 4 and 995 DF,  p-value: < 2.2e-16
  1. Xt = 0.5Xt−1 + 0.25Xt−2 − 0.15Xt−3 + Wt . con X1 = 2 , X2 = 4, , X3 = 1.
W<-rnorm(1000)
X<-numeric(1000)
X1<-numeric(1000)
X2<-numeric(1000)
X3<-numeric(1000)
X4<-numeric(1000)

for(t in 4:1000)
X [t]<- 0.5*X[t-1]+0.25*X[t-2]-0.15*X[t-3]+W[t]
plot(X,type='l')

pacf(X)

pacf(X, plot = FALSE)
## 
## Partial autocorrelations of series 'X', by lag
## 
##      1      2      3      4      5      6      7      8      9     10     11 
##  0.608  0.192 -0.135 -0.001  0.006 -0.032  0.004 -0.020 -0.051 -0.001 -0.017 
##     12     13     14     15     16     17     18     19     20     21     22 
##  0.022  0.012 -0.029  0.003  0.049 -0.024  0.029  0.001 -0.005  0.018 -0.032 
##     23     24     25     26     27     28     29     30 
## -0.031 -0.034 -0.053  0.014  0.021 -0.034 -0.017  0.013
for(t in 2:1000)
X1[t]<-X[t-1]

modelo1<-lm(X~X1)
summary(modelo1)
## 
## Call:
## lm(formula = X ~ X1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.8884 -0.6969  0.0001  0.7048  3.4191 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.07066    0.03320  -2.129   0.0335 *  
## X1           0.60926    0.02514  24.232   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.039 on 998 degrees of freedom
## Multiple R-squared:  0.3704, Adjusted R-squared:  0.3698 
## F-statistic: 587.2 on 1 and 998 DF,  p-value: < 2.2e-16
for(t in 3:1000)
X2[t]<-X[t-2]

modelo2<-lm(X~X1+X2)
summary(modelo2)
## 
## Call:
## lm(formula = X ~ X1 + X2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.8942 -0.6834 -0.0087  0.6645  3.5142 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.05691    0.03268  -1.742   0.0819 .  
## X1           0.49240    0.03115  15.807  < 2e-16 ***
## X2           0.19168    0.03115   6.153  1.1e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.021 on 997 degrees of freedom
## Multiple R-squared:  0.3935, Adjusted R-squared:  0.3922 
## F-statistic: 323.4 on 2 and 997 DF,  p-value: < 2.2e-16
for(t in 4:1000)
X3[t]<-X[t-3]

modelo3<-lm(X~X1+X2+X3)
summary(modelo3)
## 
## Call:
## lm(formula = X ~ X1 + X2 + X3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.7754 -0.6755  0.0095  0.6438  3.3342 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.06469    0.03244  -1.995   0.0464 *  
## X1           0.51886    0.03147  16.488  < 2e-16 ***
## X2           0.25899    0.03454   7.499 1.42e-13 ***
## X3          -0.13690    0.03148  -4.349 1.51e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.012 on 996 degrees of freedom
## Multiple R-squared:  0.4048, Adjusted R-squared:  0.403 
## F-statistic: 225.8 on 3 and 996 DF,  p-value: < 2.2e-16
for(t in 5:1000)
X4[t]<-X[t-4]

modelo4<-lm(X~X1+X2+X3+X4)
summary(modelo4)
## 
## Call:
## lm(formula = X ~ X1 + X2 + X3 + X4)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.7759 -0.6762  0.0085  0.6421  3.3336 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.064795   0.032517  -1.993 0.046571 *  
## X1           0.518648   0.031781  16.319  < 2e-16 ***
## X2           0.259396   0.035533   7.300 5.87e-13 ***
## X3          -0.136092   0.035539  -3.829 0.000137 ***
## X4          -0.001561   0.031792  -0.049 0.960850    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.012 on 995 degrees of freedom
## Multiple R-squared:  0.4048, Adjusted R-squared:  0.4024 
## F-statistic: 169.1 on 4 and 995 DF,  p-value: < 2.2e-16
  1. Xt = 0.2Wt−1 + 0.8Wt−2 + Wt
W<-rnorm(1000)
X<-numeric(1000)
X1<-numeric(1000)
X2<-numeric(1000)
X3<-numeric(1000)
X4<-numeric(1000)
Wt<-numeric(1000)

for(t in 4:1000)
X [t]<- 0.2*W[t-1]+0.8*X[t-2]+W[t]
plot(X,type='l')

pacf(X)

pacf(X, plot = FALSE)
## 
## Partial autocorrelations of series 'X', by lag
## 
##      1      2      3      4      5      6      7      8      9     10     11 
##  0.306  0.775 -0.177  0.011 -0.043  0.081 -0.005  0.024 -0.025 -0.001 -0.041 
##     12     13     14     15     16     17     18     19     20     21     22 
## -0.008  0.011  0.003 -0.030 -0.026 -0.031 -0.012  0.019 -0.001  0.011  0.037 
##     23     24     25     26     27     28     29     30 
## -0.006 -0.002 -0.005  0.040  0.002 -0.055 -0.051 -0.019
for(t in 2:1000)
X1[t]<-X[t-1]

modelo1<-lm(X~X1)
summary(modelo1)
## 
## Call:
## lm(formula = X ~ X1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.2813 -1.1111  0.0326  1.1246  4.6050 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.21076    0.05196  -4.056 5.38e-05 ***
## X1           0.30620    0.03016  10.154  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.618 on 998 degrees of freedom
## Multiple R-squared:  0.09363,    Adjusted R-squared:  0.09273 
## F-statistic: 103.1 on 1 and 998 DF,  p-value: < 2.2e-16
for(t in 3:1000)
X2[t]<-X[t-2]

modelo2<-lm(X~X1+X2)
summary(modelo2)
## 
## Call:
## lm(formula = X ~ X1 + X2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -3.05569 -0.67705 -0.02001  0.68157  2.76304 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.04993    0.03306  -1.511 0.131231    
## X1           0.06912    0.01999   3.458 0.000568 ***
## X2           0.77648    0.02000  38.834  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.021 on 997 degrees of freedom
## Multiple R-squared:  0.6393, Adjusted R-squared:  0.6385 
## F-statistic: 883.4 on 2 and 997 DF,  p-value: < 2.2e-16
for(t in 4:1000)
X3[t]<-X[t-3]

modelo3<-lm(X~X1+X2+X3)
summary(modelo3)
## 
## Call:
## lm(formula = X ~ X1 + X2 + X3)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -3.07384 -0.66224  0.00105  0.68316  2.71182 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.05780    0.03258  -1.774   0.0764 .  
## X1           0.20655    0.03122   6.616 6.00e-11 ***
## X2           0.78856    0.01980  39.817  < 2e-16 ***
## X3          -0.17711    0.03123  -5.672 1.85e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.006 on 996 degrees of freedom
## Multiple R-squared:  0.6506, Adjusted R-squared:  0.6495 
## F-statistic: 618.1 on 3 and 996 DF,  p-value: < 2.2e-16
for(t in 5:1000)
X4[t]<-X[t-4]

modelo4<-lm(X~X1+X2+X3+X4)
summary(modelo4)
## 
## Call:
## lm(formula = X ~ X1 + X2 + X3 + X4)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -3.09298 -0.65745 -0.00759  0.68322  2.71806 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.05722    0.03264  -1.753   0.0799 .  
## X1           0.20853    0.03174   6.570 8.11e-11 ***
## X2           0.77980    0.03192  24.432  < 2e-16 ***
## X3          -0.17941    0.03192  -5.620 2.47e-08 ***
## X4           0.01112    0.03177   0.350   0.7263    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.006 on 995 degrees of freedom
## Multiple R-squared:  0.6506, Adjusted R-squared:  0.6492 
## F-statistic: 463.2 on 4 and 995 DF,  p-value: < 2.2e-16