Package for multiple correlation? - python

Is there any easy to use python package that helps in calculating multiple correlation? Its definition is as follows:
https://en.wikipedia.org/wiki/Multiple_correlation

Very similar question here: What to use to do multiple correlation?
The answer given is an implementation using pandas.
Alternatively you could look at Numpy/Scipy, they likely have something you could use. numpy.corrcoef or numpy.correlate might get you started.

Related

How to include a (matrix) constraint using statsmodels DynamicFactor? python

I am using tsa.DynamicFactor of statsmodels with multiple Factors. I would like to include some contraints that impose that some factors can affect only some series. How can I do that?
I couldn't find anything online.
thanks a lot!
Best
Instead of DynamicFactor you need to use DynamicFactorMQ which allows to specify which observed variables load on which factors via a combination of factors, factor_orders and factor_multiplicities arguments. The docs have some usage examples.

Computing log of integral in terms of log of integrand

This question may be half computational math, half programming.
I'm trying to estimate log[\int_0^\infty\int_0^\infty f(x,y)dxdy] [actually thousands of such integrals] in Python. The function f(x,y) involves some very large/very small numbers that are bound to cause overflow/underflow errors; so I'd really prefer to work with log[f(x,y)] instead of f(x,y).
Thus my question is two parts:
1) Is there a way to estimate log[\int_0^\infty\int_0^\infty f(x,y)dxdy] using the log of the function instead of the function itself?
2) Is there an implementation of this in Python?
Thanks
I would be surprised if the math and/or numpy libraries or perhaps some more specific third party libraries would not be able to solve a problem like this. Here are some of their log functions:
math.log(x[, base]), math.log1p(x), math.log2(x), math.log10(x) (https://docs.python.org/3.3/library/math.html)
numpy.log, numpy.log10, numpy.log2, numpy.log1p, numpy.logaddexp, numpy.logaddexp2 (https://numpy.org/doc/stable/reference/routines.math.html#exponents-and-logarithms)
Generally, Just google: "logarithm python library" and try to identify similar stackoverflow problems, which will allow you to find the right libraries and functions to try out. Once you do that, then you can follow this guide, so that someone can try to help you get from input to expected output: How to make good reproducible pandas examples

Two-way repeated measures ANOVA python function

Thanks in advance for any answers. I want to conduct a 2-way repeated measures ANOVA in python where one IV has 5 levels and the other 4 levels, with one DV. I've tried looking around in scipy documentation and a few online blogs but can't seem to find anything.
You can use the rm_anova function in the Pingouin package (of which I am the creator) that works directly with pandas DataFrame, e.g.:
import pingouin as pg
# Compute the 2-way repeated measures ANOVA. This will return a dataframe.
pg.rm_anova(dv='dv', within=['iv1', 'iv2'], subject='id', data=df)
# Optional post-hoc tests
pg.pairwise_ttests(dv='dv', within=['iv1', 'iv2'], subject='id', data=df)
this is an old question but I will provide an answer.
You could take a look at pyvttbl. Using this library (can be installed via Pip) you can carry out n-way ANOVA for both independent and repeated measures (and mixed designs). Note that it seems like that you will have to use Pyvttbl own data frame method to handle your data.
It is pretty simple:
dataframe.anova('dv', sub='id', wfactors=['iv1', 'iv2'])
You can see my blog post for a more elaborated example on how to carry out a 2-way ANOVA for repeated measures.

3RSSH smoothing in Python

I'm looking for running median smoothing implementations for Python. 3RSSH in particular.
There is an implementation for Excel that works fine:
http://www.quantdec.com/Excel/smoothing.htm
Also, R's smooth function has 3RSSH: http://exploratorydataanalysis.blogspot.com/2009/03/smoothing-on-r.html
But I want a Python version, preferably working with numpy/scipy and can't find one.
So far, I've had no luck with googling.
Are there any libraries implementing such smoothing functions? Or am I destined to write one? :)
Don't think I saw a 3RSSH implementation, but you could try using scipy.signal to try and make one.
Maybe these will be enough for your application?
scipy.signal.medfilt
scipy.signal.medfilt2d
scipy.ndimage.filters.median_filter

Orthogonalize in Python. Which package?

I need to orthogonalize vectors in Python. I have found so far only algorithms.orthogonalize.
Nevertheless, it looks like "algorithms" is a kind of a package (module?) I cannot find to install. Has anybody done an orthogonalization? Please, advice me a nice package/module for this procedure. I am quite new in Python.
numpy.linalg.qr turns out to be the best option to orthogonalize vectors, since the vectors I consider vectors with complex components. And if one does it with the orthogonalize method mentioned above, then one LOSES the complex parts!
That package is part of the Spectral Python project.
The orthogonalize method is documented here:
Performs Gram-Schmidt Orthogonalization on a set of vectors
It is installable via pip and easy_install.

Categories

Resources