# Fit and Predict Arima in R [closed]

I am trying to fit a Arima model in R with an independent variable (ARIMAX). The model fit data contains both positive and negative numbers. The issue is that after fitting the model, the predict function throws out numbers which are not even close to data that was used to fit the model.

# Sample Data
y <- c( -0.05628948,  0.01907727,  0.00000000, -0.01907727,  0.00000000, -0.01940678,
0.05724351, -0.01875946, -0.03848405,  0.05724351)
x <- c(0.000000000,-0.071700531 ,-0.023863364,  0.013701646,  0.000000000,  0.085009788,
-0.028666940, -0.046181130, -0.027316528,  0.006895152)

#Fit the model
model <- arima(y, order=c(2,0,1),fixed = c(NA,NA,NA,NA,NA),xreg=x)

#Use the predict function with x again as the input
fore <- predict(model,newxreg = x)

########################Output########################################
Model -
Call:
arima(y, order = c(2, 0, 1), xreg = x, fixed = c(NA, NA, NA, NA, NA))

Coefficients:
ar1      ar2      ma1  intercept       x
-0.7935  -0.5747  -0.2986    -0.0010  0.0569
s.e.   0.4327   0.4399   0.6892     0.0026  0.1245

sigma^2 estimated as 0.0005055:  log likelihood = 22.91,  aic = -33.83

Predict -

> fore
\$pred
Time Series:
Start = 11
End = 20
Frequency = 1
 -0.03206240 -0.03614031 -0.03341961 -0.03128313 -0.03206240 -0.02722754
 -0.03369281 -0.03468892 -0.03361601 -0.03167025


Not sure why all the values from predict are only negative (while the original y has both positive and negative) and so off from the original y values. Please advise. Thanks! ## closed as off-topic by mkt - Reinstate Monica, S. Kolassa - Reinstate Monica, user158565, Michael Chernick, StatsStudentJun 21 at 4:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – mkt - Reinstate Monica, S. Kolassa - Reinstate Monica, Michael Chernick
If this question can be reworded to fit the rules in the help center, please edit the question.

Calling predict() generates forecasts, not in-sample fits. In your particular case, the forecasts are associated with the exact same predictor values x as were used in model fitting, but predict() of course does not care about this. And of course, forecasts usually do not look similar to the historical data (or to in-sample fits).
plot(y,type="o") Better still, use the forecast package, which does have a fitted method for outputs from Arima() and auto.arima().