# Using contrast variables in Regression train & test datasets

I had created contrast variables for few categorical variables in the data set. I split the data into Training and Test data. The contrast levels are dropped when the model is run. I could not proceed with the predict because the model is failed. Below is the code. Month & day are categorical variables and I have contrasted them using Simple coding method.

# Split the data
Train <- dat[1:80,] #First 80 records - Training data
Test <- dat[81:111,] # Rest of the records - Test data

# Regression
fit <- lm(Ozone~Wind+Solar.R+Month+Day+Temp, data=Train)
summary(fit)


When I run the model with Train data set, I get the error 'contrasts dropped from factor Month due to missing levels'. Can you please clarify how do we train the model with the contrast variable present and predict for the test set?

But looking at your concrete model, you are modeling a physical measurement Ozone and say "Month & day are categorical variables". That is strange! Modeling time as categorical variables that way doesn't look right for a physical measurement! So in your case, the solution seems to be to represent time in a physically meaningful way.