I collected data over multiple locations and years on crop yield and want to regress yield as a function of rainfall and heat-stress which are in two different units. Suppose my dataframe has 5 columns: year, location, yield, rainfall and temperature. These are my steps:
dat[,4:5] <- scale(dat[, 4:5], center = T, scale T) model <- lmer(yield ~ rain + temp + (1|location) + (1|year), data = dat)
After I get this model and I want to use the model for prediction. Suppose I collect new data from different years or locations called
dat1 which has 4 columns: year, location, rainfall and temperature.
My confusion is since the fitted model takes in standardised rainfall and temperature, how do I standardise these two variables in the new data
dat1? Do I simple do:
dat1[,3:4] <- scale(dat1[,3:4], center = T, scale = T) predict(model, newdata = dat1)
Or do I have to standarise the new data using mean and standard deviation of the original data