I apologize in advance if this question is too esoteric. I am using the Zelig package in R with a log-log regression model:
z.out <- zelig(lnDONATIONS ~ lnPRICE + lnFUNDRAISING + lnAGE, model = "ls", data = mydata)
x.out <- setx(z.out)
s.out <- sim(z.out, x = x.out)
summary(s.out)
plot(s.out)
This works fine, but I am trying to implement something that is allowed in the Stata-based 'precursor' to Zelig (clarify); specifically, in the clarify package, after the 'setx' command, you can type in simqi, tfunc(exp) in order to get the expected values based on the exponential transformation of the dependent variable (the simqi command in Stata is analogous to the sim comamnd in R/Zelig). My question is, can this post-setx exponential transformation be done in R with the Zelig package, and if so, how? The very extensive Zelig documentation does not seem to have an analogue to the 'tfunc' command in the clarify package.
Thanks in advance for any insights.
Related
I'm a beginner with R, and I have a vector distributed according to Beta distribution. I would like to fit a regression using this data and two explanatory variables.
I don't know the appropriate syntax though.
You can use the betareg package. Below is an example, with two explanatory variables batch and temp:
install.packages("betareg")
library(betareg)
data("GasolineYield", package = "betareg")
gy <- betareg(yield ~ batch + temp, data = GasolineYield)
summary(gy)
There's a paper on how it works here:
https://cran.r-project.org/web/packages/betareg/vignettes/betareg.pdf
And full documentation, including examples here:
https://cran.r-project.org/web/packages/betareg/betareg.pdf
This question already has an answer here:
Summarize plm model as an equation in r [closed]
(1 answer)
Closed 2 years ago.
In my thesis i estimated different "within" and "pooling" models using plm() of the plm package. Additionally, i modified some models by using a time lag. All the models work well and i got my results. Now i would like to visualize the models by showing their equation. So my question is:
Is there a way to extract the equation from the model?
I would need it in the most basic way, before any calculation is done.... more or less like this because it is not about showing my results, but the math i use.
For my models i use a panel dataset and my models look more less like this (just more control variables).
model1 <- plm (a ~ b + c, model = "within", data)
Thank you
Yeah. The formula is embedded in the model object.
mod <- plm(mpg ~ hp,mtcars)
mod$call
data("Grunfeld", package="plm")
grun.fe <- plm(inv~value+capital, data = Grunfeld, model = "within")
grun.fe$call
Also, check out equatiomatic to show the formula in latex:
https://datalorax.github.io/equatiomatic/index.html
Good luck!
Let´s suppose I have a simple AR(1) panel data model I estimate with the pgmm command in R - data available :
library(plm)
library(Ecdat)
data(Airline)
reg.gmm = pgmm(output ~ lag(output, 1)| lag(output, 2:99), data= Airline, Robust=TRUE)
With Robust=TRUE I use the Windmeijer(2005) correction to the variance-covariance matrix. Now I want to test for second order autocorrelation using Arrelano-Bond:
mtest(reg.gmm, order = 2, vcov = reg.gmm$vcov)
Am I using the Windmeijer-corrected variance-covariance matrix, as I intend to? If not, how can I implement it? The documentation is quite tight-lipped on that topic. Thanks for any help in advance!
Unfortunately the example with the Airline data throws an error which seems to be related to too many instruments in your GMM formula. If you are using different data which does not exhibit this problem you can use robust standard errors by using the vcovHC option in mtest. In your example the last call could then be:
mtest(reg.gmm, order = 2, vcov = vcovHC)
I'm trying to find out how well my mixed model with family effect fits the data. Is it possible to extract r squared values from lmekin functions? And if so, is it possible to extract partial r squared values for each of the covariables?
Example:
model= lmekin(formula = height ~ score + sex + age + (1 | IID), data = phenotype_df, varlist = kinship_matrix)
I have tried the MuMin package but it doesn't seem to work with lmekin models. Thanks.
I am able to use the r.squaredLR() function,
library(coxme)
library(MuMIn)
data(ergoStool, package="nlme") # use a data set from nlme
fit1 <- lmekin(effort ~ Type + (1|Subject), data=ergoStool)
r.squaredLR(fit1)
(I am pretty sure that works, but one thing that is great to do is to create a reproducible example so I can run your code to double check, for example I am not exactly sure what phenotype_df looks like, and I am not able to run your code as it is, a great resource for this is the reprex package).
My data frame looks like something as follows:
unique.groups<- letters[1:5]
unique_timez<- 1:20
groups<- rep(unique.groups, each=20)
my.times<-rep(unique_timez, 5)
play.data<- data.frame(groups, my.times, y= rnorm(100), x=rnorm(100), POP= 1:100)
I would like to run the following weighted regression:
plm(y~x + factor(my.times) ,
data=play.data,
index=c('groups','my.times'), model='within', weights= POP)
But I do not believe the plm package allows for weights. The answer I'm looking for the coefficient from the model below:
fit.regular<- lm(y~x + factor(my.times) + factor(my.groups),
weights= POP, data= play.data)
desired.answer<- coefficients(fit.regular)
However, I am looking for an answer with the plm package because it is much faster to get the coefficient of the within estimator with plm with larger datasets and many groups.
Edit: This problem does not exist anymore since plm features a weight function now (see #Helix123 comment above).
Even though I know of no solution with the plm package, the felmfunction in the lfe package handles weights correctly in the context of fixed effects (which seems what you need from the syntax of your example code). It is particularly written with a focus on speed in the presence of many observations and groups.
The lfe package focuses on fixed effects only, so if you need random effects the lme4 package might be more suited to your needs.
I am looking for exactly this information. I found this answer http://r.789695.n4.nabble.com/Longitudinal-Weights-in-PLM-package-td3298823.html by one of the author of the packages, which seems to suggest there is no way of using weights directly within the plm package.