You’re using the incorrect X variable name in your call to predict
(it should be called the same as the X variable you used when you created the initial model)
Although not necessary, its typical to have meanValuesHeatingPower
and meanValuesOutsideTemperature
as columns in the same dataframe, and then pass that dataframe in to data
when creating the model
The following works for me:
df <- data.frame(meanValuesHeatingPower = c(1,4,3,7), meanValuesOutsideTemperature = c(4,3,4,7)) linearModel<-lm(meanValuesHeatingPower ~ meanValuesOutsideTemperature, data = df) pred<-predict(linearModel, data.frame(meanValuesOutsideTemperature = c(1))) print(pred)