Description Usage Arguments Details Examples
This function creates an F-statistic of the personalized kind described in Huntington-Klein (2019).
1 | ownPersonalSSEsus(co, excl, mpred, sse0, n, k)
|
co |
This is a vector of coefficients unique to one individual, containing only the coefficients that vary across the sample. For example, if the grouped regression model contains |
excl |
This is a data frame containing just the variable(s) over which the effects vary. So if the regression model contains |
mpred |
This is a vector containing the regression model prediction *if all variables in |
sse0, n, k |
These are the sum of squared errors, the number of observations, and the number of coefficients in the original regression model. |
In particular, it calculates (N-K)*Var(x-hat | individual coefficients)/Var(x-hat).
In Magnified IV this is raised to the power p to be used as a regression weight. This funciton is largely used internally for magnifiedIV()
but it is exported here for use in case you'd like to use it to create your own weights. It is perhaps not as user-friendly as it could be, but it is largely an internal function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | df <- data.frame(w1 = rnorm(1000),
w2 = rnorm(1000),
e1 = rnorm(1000),
e2 = rnorm(1000),
z = rnorm(1000),
groups = factor(floor(0:999/100)))
df$x <- df$w1+df$w2+df$z+df$e1
fsmodel <- lm(x ~ z*groups + w1 + w2, data = df)
sse0 <- sum((fsmodel$residuals)^2)
indivfx <- factorPull(fsmodel,
data = df,
factor = 'groups',
interaction = 'z',
addterm = 'z')
# Create prediction for each observation with just the coefficients that are the
# same for everyone
mpred <- rowSums(t(coef(fsmodel)[c('(Intercept)','w1','w2')]*
t(model.matrix(fsmodel)[,c('(Intercept)','w1','w2')])))
# Get a data frame of just the variables with effects that vary
excl <- data.frame(z = df[['z']])
# Get the relevant N and K
n <- nrow(df)
k <- length(fsmodel$coefficients)
# And finally produce that individualized F statistic
indiv.F <- sapply(indivfx, function(x)
ownPersonalSSEsus(x, excl, mpred, sse0, n, k))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.