Learn R Programming

fixest (version 0.3.1)

r2: R2s of fixest models

Description

Reports different R2s for fixest estimations (e.g. feglm or feols).

Usage

r2(x, type = "all")

Arguments

x

A fixest object, e.g. obtained with function feglm or feols.

type

A character vector representing the R2 to compute. The R2 codes are of the form: "wapr2" with letters "w" (within), "a" (adjusted) and "p" (pseudo) possibly missing. E.g. to get the regular R2: use type = "r2", the within adjusted R2: use type = "war2", the pseudo R2: use type = "pr2", etc. Use "sq.cor" for the squared correlation. By default, all R2s are computed.

Value

Returns a named vector.

Details

For R2s with no theoretical justification, like e.g. regular R2s for maximum likelihood models -- or within R2s for models without fixed-effects, NA is returned. The single measure to possibly compare all kinds of models is the squared correlation between the dependent variable and the expected predictor.

Examples

Run this code
# NOT RUN {
# Load trade data
data(trade)

# We estimate the effect of distance on trade (with 3 fixed-effects)
est_pois = femlm(Euros ~ log(dist_km)|Origin+Destination+Product, trade)

# Squared correlation:
r2(est_pois, "sq.cor")

# "regular" r2:
r2(est_pois, "r2")

# pseudo r2
r2(est_pois, "pr2")

# within adjusted r2
r2(est_pois, "war2")

# all four at once
r2(est_pois, c("sq.cor", "r2", "pr2", "war2"))

# }

Run the code above in your browser using DataLab