
Extract Fitted Values, Residuals, and Predictions
fitted.fracregmlogit.RdExtract Fitted Values, Residuals, and Predictions
Arguments
- object
A "fracregmlogit" object.
- ...
Additional arguments.
- newdata
A new X matrix to perform model prediction. If NULL, defaults to the original dataset. X can be a vector with length k, or a matrix with k columns, where k is the number of explanatory variables in the original model.
- newbeta
A new augmented matrix of coefficients that can be used to predict outcome variables. Feeds into
object$coefficient, which contains the baseline coefficient. Useful for constructing confidence intervals via simulation or bootstrapping.
Value
An object of class data.frame containing numeric values where each column corresponds to one of the choice alternatives in the response variable matrix and each row corresponds to an observation. Specifically:
fitted: Returns the estimated fitted fractional response values (choice shares or predicted conditional probabilities).residuals: Returns the response residuals (the actual observed shares minus the estimated fitted shares).predict: Returns the predicted choice shares or conditional probabilities computed from the specified model object andnewdataornewbeta.
Examples
data("fracreg_spending")
df <- na.omit(fracreg_spending)
X = df[,2:5]
y = df[,6:11]
results1 = fracregmlogit(y, X)
# Extract fitted values
fit = fitted(results1)
# Extract residuals
res = residuals(results1)
# Predict using the first observation from the original dataset
pred = predict(results1, newdata = X[1,])