r linear model predict code example

Example 1: how to make predictions in r

predict(object = your_model, newdata = your_test_data)

Example 2: predict in r

# Tmod, Tamb and GI are columns in the data frame data2
# Find the k coefficient to complete the equation
Model_Tmod <- nls(Tmod ~ Tamb + k * GI, data = data2, start=list(k=1))

k = coef(Model_Tmod)
And where ever there is an NA in Tmod column it gets filled with the predicted
data2$Tmod[is.na(data2$Tmod)] = data2$Tamb[is.na(data2$Tmod)] + k * data2$GI[is.na(data2$Tmod)]

Tags:

R Example