is.estimable | R Documentation |
Verify that a function you have written for getfe()
is indeed
estimable.
is.estimable(
ef,
fe,
R = NULL,
nowarn = FALSE,
keepdiff = FALSE,
threshold = 500 * getOption("lfe.eps")
)
ef |
function. The function to be verified. |
fe |
list of factors. |
R |
numeric. Vector of residuals, if |
nowarn |
logical. Set to |
keepdiff |
logical. Return differences between two different runs of the Kaczmarz method. |
threshold |
numeric. Threshold for determining estimability. |
When writing custom estimable functions for getfe()
, the
function is.estimable
can be used to test it for estimability.
is.estimable()
solves the sparse residual system with the Kaczmarz
method, using two different initial values. Then ef()
is applied to
the two solutions. If the value of ef()
differs by more than
1e-5
in any coordinate, FALSE
is returned, otherwise
TRUE
is returned. If keepdiff=TRUE
, the vector of differences
is attached as an attribute 'diff'
to the returned logical value. If
you have problems with estimability, it is a fair guess that those entries
with a difference in absolute values smaller than, say, 1e-5
are
estimable, whereas the others are not.
Returns a logical.
getfe()
oldopts <- options("lfe.threads")
options(lfe.threads = 2)
## create individual and firm
id <- factor(sample(5000, 50000, replace = TRUE))
firm <- factor(sample(3000, 50000, replace = TRUE))
## create some estimable functions. It's faster to
## use numerical indices in ef rather than strings, and the input v
## to ef has no names, we have to add them when requested
ef <- function(v, addnames) {
w <- c(v[6] - v[5], v[7000] + v[5], v[7000] - v[6000])
if (addnames) names(w) <- c("id6-id5", "f2k+id5", "f2k-f1k")
w
}
is.estimable(ef, list(id = id, firm = firm))
## Then make an error; in the last coordinate, sum two firms
ef <- function(v, addnames) {
w <- c(v[6] - v[5], v[7000] + v[5], v[7000] + v[6000])
if (addnames) names(w) <- c("id6-id5", "f2k+id5", "f2k-f1k")
w
}
is.estimable(ef, list(id = id, firm = firm), keepdiff = TRUE)
options(oldopts)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.