Skip to main content

Table 3 Abridged R code for missing wind speed imputation and forecasting

From: On multivariate imputation and forecasting of decadal wind speed missing data

Code line

R code for imputation and time series prediction of wind speed data

Code line 1

# required R library functions

Code line 2

library(VIM)

Code line 3

library(mice)

Code line 4

library(lattice)

Code line 5

library(“TTR”)

Code line 6

library(“forecast”)

Code line 7

# Inspection of the missing data

Code line 8

p <− md.pairs(wind)

Code line 9

marginplot()

Code line 10

# MICE uses predictive mean matching, pmm

Code line 11

imp <− mice(wind)

Code line 12

# Further diagnostic checking

Code line 13

imp$imp$values

Code line 14

c1 <− complete(imp)

Code line 15

# Inspection of the distributions of original and the imputed data

Code line 16

com <− complete(imp, “long”, inc=T)

Code line 17

# Perform time series prediction modelling

Code line 18

windts<− ts(c1$values,start=c(1995,1),frequency=36)

Code line 19

# Decompose seasonal data

Code line 20

windtscmpnts <− decompose(windts)

Code line 21

plot(windtscmpnts)

Code line 22

# Seasonally Adjusting

Code line 23

windtssadjusted <− windts - windtscmpnts$seasonal

Code line 24

windforecasts <− HoltWinters(windts, beta=FALSE, gamma=FALSE)

Code line 25

windforecasts$fitted

Code line 26

plot(windforecasts)

Code line 27

windforecasts$SSE

Code line 28

# Forecast and forecast errors

Code line 29

windforecasts1 <− forecast.HoltWinters(windforecasts, h=360)