There are two root mean squared error functions. One simply calculates the rmse for given predicted and observed values:
$$ rmse = \sqrt{\frac{1}{N}\sum_{i=1}^{N}(y-\hat{y})^2} $$
Here is a working example:
require(ggplot2) require(trainR) # create observed obs <- 1:50 # create error and predicted e <- rnorm(n=50,mean=0,sd=5) pred <- obs + e # run function rmse(obs,pred) # plot qplot(obs,pred)
There is another function that calculates the RMSE by year. Here is a working example:
# generate year and observed year <- c(rep(1,25),rep(2,25),rep(3,25)) obs <- c(1:75) # generate errors that change by year e <- c(rnorm(n=25,mean=0,sd=2),rnorm(n=25,mean=0,sd=10),rnorm(n=25,mean=0,sd=50)) pred <- obs + e # create data frame df <- data.frame(year,obs,pred) # run function rmse.by.year(df)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.