Hi Sophia,
The Root Mean Square Error (RMSE) is a measure of how well your model's predictions match the actual data. It is calculated as the square root of the average of the squared differences between the predicted and actual values.
In your case, you have the actual data values in your array a. The estimated data values would be the values predicted by your linear trend model. Here is a sample code to find rmse:
% Your actual data
a = [2 3 4 5 1 6 3 6 7 8];
years = 1979:1988;
% Fit a linear model to your data using polyfit or any other function
p = polyfit(years, a, 1);
% Use the model to estimate values
estimated = polyval(p, years);
% Calculate the differences between actual and estimated values
differences = a - estimated;
% Square the differences
squaredDifferences = differences .^ 2;
% Calculate the mean of the squared differences
meanSquaredDifference = mean(squaredDifferences);
% Take the square root to get the RMSE
rmse = sqrt(meanSquaredDifference);
This script first fits a linear model to your data using the polyfit function. It then uses this model to estimate values for each year using the polyval function. The differences between the actual and estimated values are calculated, squared, and then averaged. The square root of this average is your RMSE.
You can also directly use the rmse function using the actual and forecast data. You can read more about it here:
Hope this helps!