Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

team cool #4

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
language: python

# ===== Linux ======
dist: xenial
python:
- 3.7
matrix:
include:
- name: "Python 3.7 on linux"
os: linux
language: python
before_install:
- cd Projects/project_2_packages/Team_cool
- pip install -U pip
- pip install -r requirements.txt
- pip install .
script: python -m unittest -v
# ======= OSX ========
- name: "Python 3.7.3 on macOS 10.14"
os: osx
osx_image: xcode10.2 # Python 3.7.3 running on macOS 10.14.3
language: shell # 'language: python' is an error on Travis CI macOS
before_install:
- cd Projects/project_2_packages/Team_cool
- python3 --version
- pip3 install -U pip
- pip3 install -r requirements.txt
- pip3 install .
script: python3 -m unittest -v
# ====== WINDOWS =========
- name: "Python 3.7.4 on Windows"
os: windows # Windows 10.0.17134 N/A Build 17134
language: shell # 'language: python' is an error on Travis CI Windows
before_install:
- cd Projects/project_2_packages/Team_cool
- choco install python --version 3.7.4
- python -m pip install --upgrade pip
- pip3 install -r requirements.txt
- pip install .
env: PATH=/c/Python37:/c/Python37/Scripts:$PATH
script: python -m unittest -v
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Metadata-Version: 2.1
Name: OLS-team-cool
Version: 0.0.31
Summary: A small example package for OLS.
Home-page: https://github.com/pypa/sampleproject
Author: Team Cool
Author-email: [email protected]
License: UNKNOWN
Project-URL: NYU Predoctoral repo, https://github.com/nyupredocs
Description: # README



This is simple OLS package made by Team Cool.

© Team Cool








Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
README.md
setup.py
OLS_team_cool/__init__.py
OLS_team_cool/logit.py
OLS_team_cool/ols.py
OLS_team_cool.egg-info/PKG-INFO
OLS_team_cool.egg-info/SOURCES.txt
OLS_team_cool.egg-info/dependency_links.txt
OLS_team_cool.egg-info/top_level.txt
test/__init__.py
test/test_ols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OLS_team_cool
test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import ols

from .ols import OLS
67 changes: 67 additions & 0 deletions Projects/project_2_packages/Team_cool/OLS_team_cool/logit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import numpy as np
import scipy.stats as st
import statsmodels as sm
from scipy import optimize

y = np.random.randint(2, size=(100,1))
x = np.random.normal(0,1,(100,2))

res_correct = sm.discrete.discrete_model.Logit(y,x).fit()
res_correct.params


def Logit(b,y,x):
# y = np.random.randint(2, size=(100,1))
# x = np.random.normal(0,1,(100,2))
n = x.shape[0]
# b = np.zeros((s,1))
# log_likelihood = (y.T @ x @ b)[0] - np.log(1 + np.exp(x.T @ b))
log_likelihood = -y.T @ np.log(1 + np.exp(-x @ b)) + (np.ones((n,1)) - y).T @ np.log(1 - 1 / (1 + np.exp(- x @ b)))

return -log_likelihood[0]

Logit(y,x,np.array((2,1)))

s = x.shape[1]
b_0 = np.array((0,0))

optimize.minimize(Logit,x0=b_0,args=(y,x))


optimize.fmin_bfgs(Logit, b_0,args=(y,x,))

y.shape


# def OLS(y,x,cf=0.95):
# """
# OLS estimation.
#
# Parameters
# −−−−−−−−−−
# y : Dependent variable
# x : Explanatory variable
# cf: Confidence level
#
# Returns
# −−−−−−−
# beta : Beta
# se: Standard Error
# confidence: Confidence Interval
#
# See Also
# −−−−−−−−
# other_function : This is a related function
# """
#
# beta = np.linalg.inv(x.T @ x) @ (x.T @ y)
#
# se_term1 = ((y - x @ beta).T @ (y - x @ beta)) / (x.shape[0] - 1)
# se_term2 = x.T @ x
# cov_matrix = se_term1 * se_term2
# se = np.sqrt(np.diag(cov_matrix))
#
# confidence = [beta - st.norm.ppf(1 - (1-0.95)/2) * se, beta \
# + st.norm.ppf(1 - (1-0.95)/2) * se]
#
# return {"Beta":beta, "Standard Error":se, "Confidence Interval":confidence}
41 changes: 41 additions & 0 deletions Projects/project_2_packages/Team_cool/OLS_team_cool/ols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import numpy as np
import scipy.stats as st
import statsmodels.api as sm

# x = np.random.randn(100,2)
# eps = np.random.normal(0,1,(100,1))
# y = (np.array([5, 10]) @ x.T).reshape(100,1) + eps
# cf = 0.95

def OLS(y,x,cf=0.95):
"""
OLS estimation.

Parameters
−−−−−−−−−−
y : Dependent variable
x : Explanatory variable
cf: Confidence level

Returns
−−−−−−−
beta : Beta
se: Standard Error
confidence: Confidence Interval

See Also
−−−−−−−−
other_function : This is a related function
"""

beta = np.linalg.inv(x.T @ x) @ (x.T @ y)

se_term1 = ((y - x @ beta).T @ (y - x @ beta)) / (x.shape[0] - (x.shape[1]))
se_term2 = x.T @ x
cov_matrix = se_term1 * np.linalg.inv(se_term2)
se = np.sqrt(np.diag(cov_matrix))

confidence = [beta - st.norm.ppf(1 - (1-0.95)/2) * se, beta \
+ st.norm.ppf(1 - (1-0.95)/2) * se]

return {"Beta":beta, "Standard Error":se, "Confidence Interval":confidence}
14 changes: 14 additions & 0 deletions Projects/project_2_packages/Team_cool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# README



This is simple OLS package made by Team Cool.

© Team Cool







Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import ols

from .ols import OLS
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import numpy as np
import scipy.stats as st
import randrange
irand = randrange (0,1)
x = np.random.randn(100,2)
# eps = np.random.normal(0,1,(100,1))
y = (np.array([5, 10]) @ x.T).reshape(100,1) + eps
# cf = 0.95
-y.T
def OLS(y,x,cf=0.95):
"""
OLS estimation.

Parameters
−−−−−−−−−−
y : Dependent variable
x : Explanatory variable
cf: Confidence level

Returns
−−−−−−−
beta : Beta
se: Standard Error
confidence: Confidence Interval

See Also
−−−−−−−−
other_function : This is a related function
"""

beta = np.linalg.inv(x.T @ x) @ (x.T @ y)

se_term1 = ((y - x @ beta).T @ (y - x @ beta)) / (x.shape[0] - 1)
se_term2 = x.T @ x
cov_matrix = se_term1 * se_term2
se = np.sqrt(np.diag(cov_matrix))

confidence = [beta - st.norm.ppf(1 - (1-0.95)/2) * se, beta \
+ st.norm.ppf(1 - (1-0.95)/2) * se]

return {"Beta":beta, "Standard Error":se, "Confidence Interval":confidence}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import numpy as np
import scipy.stats as st
import statsmodels.api as sm

# x = np.random.randn(100,2)
# eps = np.random.normal(0,1,(100,1))
# y = (np.array([5, 10]) @ x.T).reshape(100,1) + eps
# cf = 0.95

def OLS(y,x,cf=0.95):
"""
OLS estimation.

Parameters
−−−−−−−−−−
y : Dependent variable
x : Explanatory variable
cf: Confidence level

Returns
−−−−−−−
beta : Beta
se: Standard Error
confidence: Confidence Interval

See Also
−−−−−−−−
other_function : This is a related function
"""

beta = np.linalg.inv(x.T @ x) @ (x.T @ y)

se_term1 = ((y - x @ beta).T @ (y - x @ beta)) / (x.shape[0] - (x.shape[1]))
se_term2 = x.T @ x
cov_matrix = se_term1 * np.linalg.inv(se_term2)
se = np.sqrt(np.diag(cov_matrix))

confidence = [beta - st.norm.ppf(1 - (1-0.95)/2) * se, beta \
+ st.norm.ppf(1 - (1-0.95)/2) * se]

return {"Beta":beta, "Standard Error":se, "Confidence Interval":confidence}
Empty file.
43 changes: 43 additions & 0 deletions Projects/project_2_packages/Team_cool/build/lib/test/test_ols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import numpy as np
import scipy.stats as st
import unittest
import statsmodels.api as sm
from OLS_team_cool import ols

# x = np.random.randn(100,2)
# eps = np.random.normal(0,1,(100,1))
# y = (np.array([5, 10]) @ x.T).reshape(100,1) + eps
# cf = 0.95

#We are creating a class to define the variables we are testing.
class TestOLS(unittest.TestCase):

def setUp(self):
self.x = np.random.randn(100,2)
self.eps = np.random.normal(0,1,(100,1))
self.y = (np.array([5, 10]) @ (self.x).T).reshape(100,1) + self.eps
self.cf = 0.95
self.model = sm.OLS(self.y,self.x)
self.result = self.model.fit()
self.ourmodel = ols.OLS(self.y,self.x)

# This is checking the OLS model that comes with python
def test_beta(self):
betacrt = self.result.params.reshape(-1,1)

# assertAlmostEqual accounts for float errors
ourbeta = self.ourmodel['Beta'].reshape(-1,1)
testresults =np.testing.assert_almost_equal(betacrt,ourbeta)
self.assertIsNone(testresults)

def test_se(self):
se_correct = self.result.bse.reshape(-1,1)
our_se = self.ourmodel.get("Standard Error").reshape(-1,1)
test_se_res =np.testing.assert_almost_equal(se_correct,our_se)
self.assertIsNone(test_se_res)


# #This is checking the OLS model that team_cool has created
# # def test_example2(self):
if __name__ == '__main__':
unittest.main()
Binary file not shown.
20 changes: 20 additions & 0 deletions Projects/project_2_packages/Team_cool/docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 8817f0fe47cd223d4e8a37b9abaaac61
tags: 645f666f9bcd5a90fca523b33c5a78b7
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. OLS_team_cool documentation master file, created by
sphinx-quickstart on Fri Dec 6 15:10:41 2019.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to OLS_team_cool's documentation!
=========================================

.. toctree::
:maxdepth: 2
:caption: Contents:



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Loading