GithubHelp home page GithubHelp logo

ipca's Introduction

Instrumented Principal Components Analysis

Build Status

This is a Python implementation of the Instrumtented Principal Components Analysis framework by Kelly, Pruitt, Su (2017).

Usage

Exemplary use of the ipca package. The data is the seminal Grunfeld data set as provided on statsmodels. Note, the fit method takes a panel of data, X, with the following columns:

  1. entity id (numeric)
  2. time (numeric)
  3. and following columns contain characteristics.

as well as a series of dependent variables, y, of the same length as X.

import numpy as np
from statsmodels.datasets import grunfeld
data = grunfeld.load_pandas().data
data.year = data.year.astype(np.int64)

# Establish unique IDs to conform with package
N = len(np.unique(data.firm))
ID = dict(zip(np.unique(data.firm).tolist(),np.arange(1,N+1)))
data.firm = data.firm.apply(lambda x: ID[x])

# use multi-index for panel groups
data = data.set_index(['firm', 'year'])
y = data['invest']
X = data.drop('invest', axis=1)

# Call ipca
from ipca import InstrumentedPCA
regr = InstrumentedPCA(n_factors=1, intercept=False)
regr = regr.fit(X=X, y=y)
Gamma, Factors = regr.get_factors(label_ind=True)

Installing

The latest release can be installed using pip

pip install ipca

The master branch can be installed by cloning the repo and running setup

git clone https://github.com/bkelly-lab/ipca.git
cd ipca
python setup.py install

Documenation

The lastest documenation is published HERE.

Requirements

Running

With the exception of Python 3.6+, which is a hard requirement, the others are the version that are being used in the test environment. It is possible that older versions work.

  • Python 3.7+:
  • NumPy (1.19+)
  • SciPy (1.6+)
  • Numba (0.53+)
  • progressbar (2.5+)
  • joblib (1.0.1+)

Testing

  • pandas (1.2.3+)
  • scikit-learn (0.24+)
  • pytest (4.3+)
  • statsmodels (0.11+)

Acknowledgements

The implementation is inspired by the MATLAB code for IPCA made available on Seth Pruitt's website.

References

  1. Kelly, Pruitt, Su (2017). "Instrumented Principal Components Analysis" SSRN

The package is still in the development phase, hence please share your comments and suggestions with us.

Contributions welcome!

- Matthias Buechner, Leland Bybee

ipca's People

Contributors

matbuechner avatar lbybee avatar steffenwindmueller avatar

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.