mmeierer / rendo Goto Github PK
View Code? Open in Web Editor NEWREndo - A R package to control for endogeneity by using internal instrumental variable models
REndo - A R package to control for endogeneity by using internal instrumental variable models
(1) Please export the functions copulaCorrectionDiscrete_pstar and copulaCorrectionContinuous_pstar so users can call them to generate Pstar vectors.
(2) Please return the pstar vectors with the return object of the copulaCorrection() function (summary function does not need to show them by default)
(3) Also please return the generated moments (g, gp, gy, etc) for the higherMomentsIV() function with the return object or provide access to functions to that generate them.
This will allow users to use pstar vectors with further panel data analysis using the plm package, or conduct further tests that may require the pstar vector that was used in the copula regression.
Thank you!
As part a research project, I've extended the latentIV log-likelihood function to support multiple endogenous regressors with multiple levels. It's quite fast.
Is this something you'd be potentially interested in integrating?
I'm a bit weary throwing out yet another package with incremental functionality, while you guys have already made tackling endogeneity more accessible.
Let me know about your interest, and then I can check how the function may fit in the existing structure of the package.
Cheers,
Hannes
Does the copula correction method work for models where an intercept is estimated with an intercept? After skimming the Park and Gupta paper proposing the copula correction method, I noticed the data generating process does not add an intercept into the data generating process. I tried imitating their data generating process without an intercept and with an intercept and got less than satisfying results (see the code below) which makes me think the data has to be mean centered and estimated with without an intercept.
Any feedback you all have would be appreciated!
Thanks!
## create an endogenous regressor
Sigma <- matrix(c(1.8,1.65,1.65,2),2,2)
x1 <-mvtnorm::rmvnorm(n = 100, c(2, 0), Sigma)
cor(x1)## check correlation
error <- x1[,2]
x1<- x1[,1]
## create an exogenous regressor
x2 <- rnorm(100, 2, 3)
## generate some data
y <-3*x1 + 4*x2 + error
#mle methodd
model <- REndo::copulaCorrection(y ~0+ x1+x2| continuous(x1),
data=data.frame(y, x1, x2))
summary(model)
## ols method
p_star <- REndo:::copulaCorrectionContinuous_pstar(x1)
summary(lm(y ~ 0+x1+x2))
summary(lm(y ~ 0+x1+x2+p_star))
### allow the models to estimate an intercept
#mle methodd
model <- REndo::copulaCorrection(y ~ x1+x2| continuous(x1),
data=data.frame(y, x1, x2))
summary(model)
## ols method
p_star <- REndo:::copulaCorrectionContinuous_pstar(x1)
summary(lm(y ~ x1+x2))
summary(lm(y ~ x1+x2+p_star))
### add intercept to the data
y <- y + 3
#mle methodd
model <- REndo::copulaCorrection(y ~ x1+x2| continuous(x1),
data=data.frame(y, x1, x2))
summary(model)
## ols method
p_star <- REndo:::copulaCorrectionContinuous_pstar(x1)
summary(lm(y ~ x1+x2))
summary(lm(y ~ x1+x2+p_star))
I want to create a "copulaEndo" class for the copulaEndo function. I already tried something, as you can see in the commented lines in the copulaEndo.R file.
The problem is that copulaEndo function calls 3 other functions, each of them returning a different type of result, as follows:
when function copulaCont1 is called, the returned slots should be:
when function copulaMethod2 is called, the returned slots should be:
when copulaDiscrete is called, the object returned should be of "lm" class, since copulaDiscrete returns the result of a "lm" call.
Would something like that be possible to implement? Or what solution would you suggest?
Call of the liv function of the type:
liv(yp)P) gives the following error:
should work as well (meaning without param and data). When param = NULL, default values are given, as programmed already in liv.R
At the moment the call liv(y
Error in model.frame.default(formula = y ~ P, drop.unused.levels = TRUE) :
invalid type (list) for variable 'y'.
Patrick, could you please have a look at this. Thank you
I have incorporated your comments regarding the S3 class "copulaEndo". But I do not know how to create a generics function for this class. Currently I get the following warning message when I run devtools::document():
Warning message:
S3 methods ‘coef.copulaEndo’, ‘print.copulaEndo’, ‘summary.copulaEndo’ were declared in NAMESPACE but not found
Thanks
Hi Patrik,
It has been a while... Could you please have a look at the syntax of the copulaEndo class. Does it make sense that the class declaration is S4 format but then the summary and coef methods are in S3? Will that be acceptable by CRAN?
Also, at this moment the summary.copulaEndo method does not function well. Could you have a look ? Thank you very much.
Set up REndo homepage based on GitHub Actions instead of Travis.
in hmlewbel.R the names of the variables returned are not the ones given in "formula" - see example below (the formula was y1~ M + P1, where M has two columns X1 and X2):
AER::ivreg(formula = y~ X + P | X + IV, x = TRUE)
Coefficients:
(Intercept) XX1 XX2 P
3.4331 0.9484 3.1407 0.5571
could you please indicate how could I change that.
Thanks!
I have just submitted to CRAN a first version of the package with only two functions: liv and hmlewbel.
However, when I am asked to check if the package can be installed on Windows as well, the check gives me the following error :
Do you have any idea what can be wrong ? I see it has smth to do with the liv function....but what can be changed? The package passes the CRAN check on MAC...
The current development version of R has recently switched to use HTML5
for documentation pages (PR#18149). Now validation using HTML tidy
finds the following problems in your Rd files (problems only shown once
per Rd file):
REndo::copulaCorrection.Rd: Warning:
element removed from HTML5Can you please fix as necessary?
The problems reported are one of
Warning:
element removed from HTML5Warning:
attribute "align" not allowed for HTML5 attribute "align" not allowed for HTML5
Warning:
See https://html.spec.whatwg.org/#obsolete-but-conforming-features for
info on these: in principle, all can be fixed by using style attributes,
e.g.
style='text-align: right;'
instead of align='right' etc., which will work for both the new and old
ways of converting Rd to HTML.
Please fix before 2022-03-15 to safely retain your package on CRAN.
When I include more than 1 endogenous variables in the copulaCorrection(), it shows the following message and runs much faster: "Warning: Additional parameters given in the ... argument are ignored because they are not needed". What does this message mean?
Currently, bootstrapping for the copulaCorrection can be very slow. Profiling reveals that the base::ecdf function makes up about half the required computing time. To speed up computation, it could be implemented in Rcpp.
Various implementation of the ecdf exist, such as https://github.com/dmbates/ecdfExample.
However, it will require to setup the package accordingly. Currently, correct functionality is more of a priority and it is therefore left for later.
First off, I wanted to thank you for taking the time to write and maintain the REndo package on CRAN. This was my first introduction to instrument free methods and am interested/excited to learn more! Specifically, I took an interest in the implementation of your copula correction method and had a couple of questions that I was wondering if you could answer
Any help you would be able to provide would be greatly appreciated. Thanks once again!
Add again support for the multilevelIV function which is currently defunct.
Implement the paper by Kim & Frees (2007) and generalize their example code.
Possibly use data.table for the grouping and sparse matrices from Matrix package to deal with the large cov matrices.
Originally posted by pinson06 August 18, 2021
Hi everyone,
I'm trying to use this very nice package but I obtain a error message for which I have no clue how to solve. Here's what i obtain in R when using the MultiLevelIV with my dataset and this code :
formula <- y ~ e + a + f + w + l + w2 + w_l + f_l + e_l + e_w + a_w + a_l + a_e + e_w_l + f_w_l + f_a_l + f_e_l + a_w_l + f_a_e_l + v + pr + t + (1 | album_id) | endo(e,a,f)
multilevel <- multilevelIV(formula = formula, data = data, verbose=TRUE)
Message obtained via R's console:
"Detected multilevel model with 2 levels.
For album_id (Level 2), 181 groups were found.
Error: Matrices must have same dimensions in diag2Tsmart(e1, e2, "d") - e2"
Any ideas?
hmlewbel.R should return an object of class ivreg
Thanks
For any method, it should be checked whether the assumptions underlying the theoretical model are met for the given data.
If the assumptions are violated, the user should be warned about it.
Currently, the case of a single continuous endogenous regressor in copulaCorrection can only be estimated using LL. Because bootstrapping with LL takes much longer it would be convenient to also provide the possibility to use enhanced OLS. As by Raluca, this would theoretically be correct as shown in the paper by Park and Gupta.
Suggested syntax: use continuousLL()
and continuousOLS()
to mark the regressors in favour of continuous()
which should be depreciated.
This is not expected to be implemented in the near future.
After I fixed the Windows compiling error regarding the "formula" definition, I get now the following two notes:
and
I attache you the file that made this errors...
When I am applying hmlewbel and then trying to run a summary on it, it gives me the error below:
h1 <- hmlewbel(y ~ X1 + X2 + P, IIV = "yp")
summary(h1)
Error in UseMethod("coeftest") :
no applicable method for 'coeftest' applied to an object of class "ivreg"
h1 is of class "ivreg" so summary(h1) should be working. Can you point me to where is the error?
liv: no visible global function definition for ‘get_all_vars’
liv: no visible global function definition for ‘model.frame’
liv: no visible global function definition for ‘coefficients’
liv: no visible global function definition for ‘lm’
liv: no visible global function definition for ‘sd’
liv: no visible global function definition for ‘new’
liv: no visible global function definition for ‘slot<-’
print.liv: no visible global function definition for ‘str’
summary.liv: no visible global function definition for ‘printCoefmat’
Undefined global functions or variables:
coefficients get_all_vars lm model.frame new printCoefmat sd slot<-
str
Consider adding
importFrom("methods", "new", "slot<-")
importFrom("stats", "coefficients", "get_all_vars", "lm",
"model.frame", "printCoefmat", "sd")
importFrom("utils", "str")
to your NAMESPACE (and ensure that your DESCRIPTION Imports field
contains 'methods').
I will try to fix it, but if you have time, I would appreciate if you have a look too.
Best
Recently upgraded from R 3.6.3 and the multilevelIV function has stopped working. The only message returned is "Error: The above errors were encountered!" Are you aware of any compatibility issues?
Implement panel data extension of Park/Gupta (2012)'s copula method proposed by Haschka (2021)
If an endogenous variable is included in an interaction with an exogenous variable, an additional instrument has to included for the interaction term. The procedure is analogous to regular IV estimation. This could be handled automatically by copulaCorrection()
,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.