Github user actuaryzhang commented on the issue:
https://github.com/apache/spark/pull/17967
@felixcheung Thanks for the review. I fixed some typo.
Below is an example to show the difference in model estimates due to
different string ordering between R and RFormula.
```
val df = Seq((1.0, "foo", "a"), (2.0, "bar", "b"), (3.0, "bar", "b"), (4.0,
"aaz", "b"),
(4.2, "aaz", "b"), (1.6, "bar", "a")).toDF("id", "a", "b")
val formula = new RFormula().setFormula("id ~ a + b")
for (orderType <- Seq("frequencyDesc", "alphabetDesc")) {
val df2 = formula.setStringOrderType(orderType).fit(df).transform(df)
val model = new GeneralizedLinearRegression().fit(df2)
val estimate = (model.coefficients.toArray :+ model.intercept)
println(orderType + ": " + estimate.sortWith(_ < _).mkString(","))
}
frequencyDesc:
0.5999999999999952,0.8999999999999999,1.0000000000000042,2.1999999999999957
alphabetDesc:
-2.200000000000006,-1.6000000000000025,0.899999999999996,3.200000000000005
```
The following is the estimate from R, which is the same as `stringOrderType
= "alphabetDesc"`.
```
> df <- data.frame(id = c(1, 2, 3, 4, 4.2, 1.6),
+ a = c("foo", "bar", "bar", "aaz", "aaz", "bar"),
+ b = c("a", "b", "b", "b", "b", "a"))
> sort(coef(lm(id ~ a + b, data = df)))
afoo abar bb (Intercept)
-2.2 -1.6 0.9 3.2
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]