diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index db52493..881b9ed 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -47,47 +47,4 @@ jobs: name: python-package-distributions path: dist/ - name: Publish distribution 📦 to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - - github-release: - name: >- - Sign the Python 🐍 distribution 📦 with Sigstore - and upload them to GitHub Release - needs: - - publish-to-pypi - runs-on: ubuntu-latest - - permissions: - contents: write # IMPORTANT: mandatory for making GitHub Releases - id-token: write # IMPORTANT: mandatory for sigstore - - steps: - - name: Download all the dists - uses: actions/download-artifact@v3 - with: - name: python-package-distributions - path: dist/ - - name: Sign the dists with Sigstore - uses: sigstore/gh-action-sigstore-python@v1.2.3 - with: - inputs: >- - ./dist/*.tar.gz - ./dist/*.whl - - name: Create GitHub Release - env: - GITHUB_TOKEN: ${{ github.token }} - run: >- - gh release create - '${{ github.ref_name }}' - --repo '${{ github.repository }}' - --notes "" - - name: Upload artifact signatures to GitHub Release - env: - GITHUB_TOKEN: ${{ github.token }} - # Upload to GitHub Release using the `gh` CLI. - # `dist/` contains the built packages, and the - # sigstore-produced signatures and certificates. - run: >- - gh release upload - '${{ github.ref_name }}' dist/** - --repo '${{ github.repository }}' + uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..124910a --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,35 @@ +# Read the Docs configuration file for Sphinx projects +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Set the OS, Python version and other tools you might need +build: + os: ubuntu-22.04 + tools: + python: "3.12" + # You can also specify other tool versions: + # nodejs: "20" + # rust: "1.70" + # golang: "1.20" + +# Build documentation in the "docs/" directory with Sphinx +sphinx: + configuration: docs/conf.py + # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs + # builder: "dirhtml" + # Fail on all warnings to avoid broken references + # fail_on_warning: true + +# Optionally build your docs in additional formats such as PDF and ePub +# formats: +# - pdf +# - epub + +# Optional but recommended, declare the Python requirements required +# to build your documentation +# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html +# python: +# install: +# - requirements: docs/requirements.txt \ No newline at end of file diff --git a/HLR/regression.py b/HLR/regression.py index 69b6052..cf952b0 100644 --- a/HLR/regression.py +++ b/HLR/regression.py @@ -18,13 +18,15 @@ class HierarchicalLinearRegression: """Class for performing hierarchical linear regression analysis.""" - def __init__(self, df, ivs_dict, dv): + def __init__(self, df, ivs_dict, dv, missing_data=None, ols_params=None): """Initializes the HierarchicalLinearRegression class. Args: df (pd.DataFrame): The dataset to be used in the regression. ivs_dict (dict): Dictionary mapping model levels to lists of independent variables. dv (str): The dependent variable. + missing_data (str, optional): Handling of missing data in OLS + ols_params (dict, optional): Optional parameters to pass to the OLS fit method. """ if not isinstance(df, pd.DataFrame): raise ValueError("Data is not a pandas DataFrame.") @@ -42,6 +44,16 @@ def __init__(self, df, ivs_dict, dv): raise ValueError(f"{dv} is not a column in the DataFrame.") self.outcome_var = dv + if missing_data is not None: + if missing_data not in ['none', 'drop', 'raise']: + raise ValueError("missing_data must be either 'none', 'drop', or 'raise'.") + self.missing_data = missing_data if missing_data is not None else 'none' + + if ols_params is not None: + if not isinstance(ols_params, dict): + raise ValueError("ols_params must be a dictionary.") + self.ols_params = ols_params if ols_params is not None else {} + def fit_models(self): """Fits OLS models for each level of independent variables. @@ -53,7 +65,7 @@ def fit_models(self): X = self.data[predictors] X_const = sm.add_constant(X) y = self.data[self.outcome_var] - model = sm.OLS(y, X_const).fit() + model = sm.OLS(y, X_const, missing=self.missing_data).fit(**self.ols_params) results[level] = model return results diff --git a/README.md b/README.md index aaaf610..bed836d 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,11 @@ X = {1: ['PTS'], # Define the outcome variable y = 'W' -# Initiate the HLR object -hreg = HierarchicalLinearRegression(df, X, y) +# Initiate the HLR object (missing_data and ols_params are optional parameters) +hreg = HierarchicalLinearRegression(df, X, y, missing_data='drop', ols_params=None) -# Generate a summarised report as a dataframe which shows all linear regression models parameters and difference between the models -summary_report = hreg.summary() -display(summary_report) +# Generate a summarised report of HLR +hreg.summary() # Run diagnostics on all the models (displayed output below only shows the first model) hreg.diagnostics(verbose=True) @@ -119,7 +118,8 @@ Model Level 2 Diagnostics: :-------------------------:|:-------------------------: #### Documentation (WIP) -Docs is currently outdated - it currently displays the old version of the package. See the Usage above for all available functionality. +Documentation is currently work in progress. + ## Citation @@ -129,16 +129,15 @@ Please use Zenodo DOI for citing the package in your work. #### Example -Toomas Erik Anijärv, & Rory Boyle. (2023). teanijarv/HLR: v0.2.0 (v0.2.0). Zenodo. https://doi.org/10.5281/zenodo.7683808 +Anijärv, T. E., Mitchell, J. and Boyle, R. (2024) ‘teanijarv/HLR: v0.2.1’. Zenodo. https://doi.org/10.5281/zenodo.7683808 ``` @software{toomas_erik_anijarv_2024_7683808, - author = {Toomas Erik Anijärv and - Rory Boyle}, - title = {teanijarv/HLR: v0.2.0}, + author = {Toomas Erik Anijärv, Jules Mitchell, Rory Boyle}, + title = {teanijarv/HLR: v0.2.1}, month = mar, year = 2024, publisher = {Zenodo}, - version = {v0.2.0}, + version = {v0.2.1}, doi = {10.5281/zenodo.7683808}, url = {https://doi.org/10.5281/zenodo.7683808} } @@ -152,7 +151,6 @@ This program is provided with no warranty of any kind and it is still under deve #### To-do Would be great if someone with more experience with packages would contribute with testing and the whole deployment process. Also, if someone would want to write documentation, that would be amazing. - docs -- testing - dict valus within df hard to read - ability to change OLS parameters - add t stats for coefficients diff --git a/setup.py b/setup.py index 99fd481..21c2837 100644 --- a/setup.py +++ b/setup.py @@ -44,6 +44,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/teanijarv/HLR', - version='0.2.0', + version='0.2.1', zip_safe=False, )