This function obtains prediction from a fitted model estimated with femlm, feols or feglm.

# S3 method for fixest
predict(object, newdata, type = c("response", "link"), na.rm = TRUE, ...)



A fixest object. Obtained using the functions femlm, feols or feglm.


A data.frame containing the variables used to make the prediction. If not provided, the fitted expected (or linear if type = "link") predictors are returned.


Character either equal to "response" (default) or "link". If type="response", then the output is at the level of the response variable, i.e. it is the expected predictor \(E(Y|X)\). If "link", then the output is at the level of the explanatory variables, i.e. the linear predictor \(X\cdot \beta\).


Logical, default is TRUE. Only used when the argument newdata is missing. If FALSE the number of observation returned will be the number of observations in the original data set, otherwise it will be the number of observations used in the estimation.


Not currently used.


It returns a numeric vector of length equal to the number of observations in argument newdata.

See also

See also the main estimation functions femlm, feols or feglm. update.fixest, summary.fixest, vcov.fixest, fixef.fixest.


Laurent Berge


# Estimation on iris data res = femlm(Sepal.Length ~ Petal.Length | Species, iris) # what would be the prediction if the data was all setosa? newdata = data.frame(Petal.Length = iris$Petal.Length, Species = "setosa") pred_setosa = predict(res, newdata = newdata) # Let's look at it graphically plot(c(1, 7), c(3, 11), type = "n", xlab = "Petal.Length", ylab = "Sepal.Length")
newdata = iris[order(iris$Petal.Length), ] newdata$Species = "setosa" lines(newdata$Petal.Length, predict(res, newdata))
# versicolor newdata$Species = "versicolor" lines(newdata$Petal.Length, predict(res, newdata), col=2)
# virginica newdata$Species = "virginica" lines(newdata$Petal.Length, predict(res, newdata), col=3)
# The original data points(iris$Petal.Length, iris$Sepal.Length, col = iris$Species, pch = 18)
legend("topleft", lty = 1, col = 1:3, legend = levels(iris$Species))