Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
toarstats
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
toar-public
toarstats
Commits
3da1f6cf
Commit
3da1f6cf
authored
2 years ago
by
Niklas Selke
Browse files
Options
Downloads
Patches
Plain Diff
Added OLS and quantile regression.
parent
3b22c43e
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!5
Modified the test for the 'value_count' statistic. Now all available sampling...
,
!3
Niklas issue009 feat calculate quantile regression
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
toarstats/trends/interface.py
+20
-1
20 additions, 1 deletion
toarstats/trends/interface.py
toarstats/trends/ols.py
+22
-0
22 additions, 0 deletions
toarstats/trends/ols.py
toarstats/trends/quant_reg.py
+23
-0
23 additions, 0 deletions
toarstats/trends/quant_reg.py
with
65 additions
and
1 deletion
toarstats/trends/interface.py
+
20
−
1
View file @
3da1f6cf
...
...
@@ -4,7 +4,8 @@ This module contains the following function:
calculate_trend - calculate the trend using the requested method
"""
import
statsmodels.formula.api
as
smf
from
toarstats.trends.ols
import
ols
from
toarstats.trends.quant_reg
import
quant_reg
def
calculate_trend
(
method
,
data
,
formula
=
"
value ~ datetime
"
,
quantiles
=
None
):
...
...
@@ -22,4 +23,22 @@ def calculate_trend(method, data, formula="value ~ datetime", quantiles=None):
:param quantiles: a single quantile or a list of quantiles to
calculate, these must be between 0 and 1; only
needed when ``method=
"
quant
"
``
:raises ValueError: raised if the ``method`` parameter is not
recognized
:return: The result of the fit or a list of fit results if
``method=
"
quant
"
`` and multiple quantiles are given
"""
if
method
==
"
OLS
"
:
fit
=
ols
(
data
,
formula
)
elif
method
==
"
quant
"
:
try
:
fit
=
[
quant_reg
(
data
,
formula
,
quantile
)
for
quantile
in
quantiles
]
except
TypeError
:
fit
=
quant_reg
(
data
,
formula
,
quantiles
)
else
:
raise
ValueError
(
f
"
{
method
}
is not recognized, must be
'
OLS
'
or
"
"
'
quant
'"
)
return
fit
This diff is collapsed.
Click to expand it.
toarstats/trends/ols.py
0 → 100644
+
22
−
0
View file @
3da1f6cf
"""
Ordinary least squares (OLS) linear regression calculation.
This module contains the following function:
ols - calculate the OLS linear regression
"""
import
statsmodels.formula.api
as
smf
def
ols
(
data
,
formula
):
"""
Calculate the OLS linear regression.
:param data: data containing a list of date time values and
associated parameter values on which to calculate the
trend
:param formula: the formula specifying the model
:return: The result of the fit
"""
model
=
smf
.
ols
(
formula
,
data
)
fit
=
model
.
fit
()
return
fit
This diff is collapsed.
Click to expand it.
toarstats/trends/quant_reg.py
0 → 100644
+
23
−
0
View file @
3da1f6cf
"""
Quantile regression calculation.
This module contains the following function:
quant_reg - calculate the OLS linear regression
"""
import
statsmodels.formula.api
as
smf
def
quant_reg
(
data
,
formula
,
quantile
):
"""
Calculate the quantile regression.
:param data: data containing a list of date time values and
associated parameter values on which to calculate the
trend
:param formula: the formula specifying the model
:param quantile: a single quantile, must be between 0 and 1
:return: The result of the fit
"""
model
=
smf
.
quantreg
(
formula
,
data
)
fit
=
model
.
fit
(
q
=
quantile
)
return
fit
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment