Git Product home page Git Product logo

rendo's People

Contributors

mmeierer avatar pschil avatar rgui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rendo's Issues

Allow users access to the Pstar vectors in copulaCorrection so users can use panel data methods with them

(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!

latentIV: support for multiple endogenous instruments

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

Problems with intercept estimation with the Copula correction method

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))

copulaEndo class

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:

  • coefEndovar
  • coefExoVar
  • value
  • convCode

when function copulaMethod2 is called, the returned slots should be:

  • coefEndovar
  • coefExoVar
  • coefPStar
  • seCoefficients

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?

Sample weights

  1. I want to use sample weights for the observations. Will the package allows to incorporate the sampling weights.

liv call

Call of the liv function of the type:
liv(yp)
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
P) gives the following error:

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

generic function for S3 class "copulaEndo"

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

summary.copulaEndo

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.

variable names

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!

failed R CMD check for Windows

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 :

  • installing source package 'REndo' ...
    ** R
    ** data
    ** preparing package for lazy loading
    Error in makePrototypeFromClassDef(properties, ClassDef, immediate, where) :
    in making the prototype for class "liv" elements of the prototype failed to match the corresponding slot class: formula (class "formula" )
    Error : unable to load R code in package 'REndo'
    ERROR: lazy loading failed for package 'REndo'
  • removing 'd:/RCompile/CRANguest/R-devel/lib/REndo'

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...

Rd files need updates for HTML5

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 HTML5
REndo::hetErrorsIV.Rd: Warning: element removed from HTML5
REndo::higherMomentsIV.Rd: Warning: element removed from HTML5
REndo::higherMomentsIV.Rd: Warning:
attribute "align" not allowed for HTML5
REndo::latentIV.Rd: Warning: element removed from HTML5
REndo::multilevelIV.Rd: Warning: element removed from HTML5
REndo::vcov.rendo.boots.Rd: Warning: element removed from HTML5
REndo::vcov.rendo.boots.Rd: Warning: unescaped & or unknown entity "̅-"

Can you please fix as necessary?

The problems reported are one of

Warning:

element removed from HTML5
Warning: element removed from HTML5
Warning: element removed from HTML5

Warning:

attribute "align" not allowed for HTML5
Warning:
attribute "align" not allowed for HTML5
Warning:

attribute "align" not allowed for HTML5
Warning:

attribute "align" not allowed for HTML5

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.

Add Rcpp implementation of ecdf

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.

Questions regarding copula correction method

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

  1. Are there acceptable guidelines to the implementation of copula correction methods for panel data? As a work around, I had been mean differencing/first differencing the data on my own prior to running the copula correction, but I was curious if there were better methods? Should the generated regressor used to deal with endogeneity be generated in level (undifferenced) space or first or mean differenced space? Or does it matter?
    2)I noticed the ML implementation vastly improves the efficiency of the estimates (e.g. the standard errors shrink) compared to the OLS implementation. Is this normal? Do you know of a way to improve the efficiency of the OLS estimate? Further, I took a peak at the Park’s paper that formulates copula correction methods, and I was curious if you knew of a log likelihood written out for multiple endogenous covariates?

Any help you would be able to provide would be greatly appreciated. Thanks once again!

add multilevelIV back

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.

Non-matching matrix dimensions

Discussed in #62

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?

Verify model assumptions

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.

Enhanced OLS for copulaCorrection single continuous endogenous regressor

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.

NOTES when compiling iwth Windows

After I fixed the Windows compiling error regarding the "formula" definition, I get now the following two notes:

  • checking R code for possible problems ... NOTE
    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').

and

  • checking top-level files ... NOTE
    File
    LICENSE
    is not mentioned in the DESCRIPTION file.

I attache you the file that made this errors...

REndo_1.0.tar.gz

problems summary function class ivreg

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?

Still NOTES when compiling on Windows

  • checking R code for possible problems ... NOTE

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

Compatibility with R 4.0.2

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?

Add support for interactions terms in Copula method

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(),

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.