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, ...)

Arguments

object

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

newdata

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.

type

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\).

na.rm

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.

Value

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.

Author

Laurent Berge

Examples

# 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))