Discussion:
[Math | Statistics] looking for an equivalent of both the R class "lm" and intrcept
Jonathan MERCIER
2018-10-30 11:22:46 UTC
Permalink
Dear,

Firstly thanks for your amazing libraries.

Currently I am working to port some R code to Java, and I encounter some
difficulties.


What is the equivalent of:

- the R class "lm" ?

*description*:
https://www.rdocumentation.org/packages/stats/versions/3.5.1/topics/lm

- of intercept: Z ~ y-1 or z ~ 1

*R examples:*
Y ~ A          |  Y = βo + β1A     | Straight-line with an implicit
y-intercept
Y ~ -1 + A    | Y = β1A| Straight-line with no y-intercept; that is, a
fit forced through (0,0)
Y ~ A + I(A^2)| Y = βo+ β1A + β2A2| Polynomial model; note that the
identity function I( ) allows terms in the model to include normal
mathematical symbols.


Thanks for your help
--
Jonathan MERCIER
Centre National de Recherche en Génomique Humaine (CNRGH)

Researcher computational biology

PhD, Jonathan MERCIER

Bioinformatics (LBI)

2, rue Gaston Crémieux

91057 Evry Cedex

Tel :(33) 1 60 87 83 44

Email :***@cng.fr <mailto:***@cng.fr>
Gilles
2018-10-30 11:42:27 UTC
Permalink
Hello.
Post by Jonathan MERCIER
Dear,
Firstly thanks for your amazing libraries.
Currently I am working to port some R code to Java, and I encounter
some difficulties.
- the R class "lm" ?
https://www.rdocumentation.org/packages/stats/versions/3.5.1/topics/lm
- of intercept: Z ~ y-1 or z ~ 1
*R examples:*
Y ~ A          |  Y = βo + β1A     | Straight-line with an implicit
y-intercept
Y ~ -1 + A    | Y = β1A| Straight-line with no y-intercept; that is,
a fit forced through (0,0)
Y ~ A + I(A^2)| Y = βo+ β1A + β2A2| Polynomial model; note that the
identity function I( ) allows terms in the model to include normal
mathematical symbols.
I can guess that some of the equivalent functionality is provided
by the "o.a.c.math4.stat.regression" package:

http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math4/stat/regression/package-summary.html


Regards,
Gilles
Post by Jonathan MERCIER
Thanks for your help
--
Jonathan MERCIER
Centre National de Recherche en Génomique Humaine (CNRGH)
Researcher computational biology
PhD, Jonathan MERCIER
Bioinformatics (LBI)
2, rue Gaston Crémieux
91057 Evry Cedex
Tel :(33) 1 60 87 83 44
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@commons.apache.org
For additional commands, e-mail: user-***@commons.apache.org
Eric Barnhill
2018-10-30 16:11:39 UTC
Permalink
Post by Jonathan MERCIER
*R examples:*
Y ~ A | Y = βo + β1A | Straight-line with an implicit
y-intercept
Y ~ -1 + A | Y = β1A | Straight-line with no y-intercept;
that is, a fit forced through (0,0)
SimpleRegression should take care of these first cases.
http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math4/stat/regression/SimpleRegression.html

Construct the SimpleRegression() object, then pass data using the
addObservations() method. You can either call regress() and inspect the
RegressionResults object returned, or after calling results, use the
SimpleRegression methods getSlope() and getIntercept() . The results
returned by RegressionResults are more exhaustive. The boolean
includeIntercept should toggle whether the model fits an intercept.


Y ~ A + I(A^2) | Y = βo+ β1A + β2A2| Polynomial model; note that the
Post by Jonathan MERCIER
identity function I( ) allows terms in the model to include normal
mathematical symbols.
I don't think we have such a compact syntax for this. I think you'll have
to do it the old-fashioned way and create the appropriate model matrix,
then solve using the OLS regression package
http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math4/stat/regression/OLSMultipleLinearRegression.html
which uses a QR factorization.

Add data with the newSampleData() method, then get your regression
coefficients by calling calculateBeta() .
Post by Jonathan MERCIER
Thanks for your help
--
[image: Jonathan MERCIER]
[image: Centre National de Recherche en Génomique Humaine (CNRGH)]
Researcher computational biology
PhD, Jonathan MERCIER
Bioinformatics (LBI)
2, rue Gaston Crémieux
91057 Evry Cedex
Tel :(33) 1 60 87 83 44
Jonathan MERCIER
2018-11-07 12:41:02 UTC
Permalink
Thanks  Eric and Gilles for your help

Best regards
--
Jonathan MERCIER
Centre National de Recherche en Génomique Humaine (CNRGH)

Researcher computational biology

PhD, Jonathan MERCIER

Bioinformatics (LBI)

2, rue Gaston Crémieux

91057 Evry Cedex

Tel :(33) 1 60 87 83 44

Email :***@cng.fr <mailto:***@cng.fr>
Loading...