[Rd] Proposed Patch for poly.Rd

Duncan Murdoch murdoch.duncan at gmail.com
Fri Jul 14 00:00:07 CEST 2017


On 13/07/2017 4:37 PM, Marc Schwartz wrote:
>
>> On Jul 13, 2017, at 3:22 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>>
>> On 13/07/2017 4:08 PM, Marc Schwartz wrote:
>>> Hi All,
>>>
>>> As per the discussion today on R-Help:
>>>
>>>  https://stat.ethz.ch/pipermail/r-help/2017-July/448132.html
>>>
>>> I am attaching a proposed patch for poly.Rd to provide clarifying wording relative to naming the 'degree' argument explicitly, in the case where the 'x' argument is a matrix, rather than a vector.
>>>
>>> This is based upon the svn trunk version of poly.Rd.
>>
>> I don't think this is the right fix.  The use of the unnamed 2nd arg as degree happens whether the first arg is a matrix or not.
>>
>> I didn't read the whole thread in detail, but it appears there's a bug somewhere, in the report or in the poly() code or in the plsr() code. That bug should be reported on the bug list if it turns out to be in base R, and to the package maintainer if it is in plsr().
>>
>> Duncan Murdoch
>
>
> Duncan,
>
> Thanks for your reply. You only really need to read that last post in the thread linked to above.
>
> I won't deny the possibility of a bug in poly(), relative to the handling of 'x' as a matrix. The behavior occurs in the poly() function in a pure stand alone fashion, without the need for plsr():
>
> x1 <- runif(20)
> x2 <- runif(20)
> mx <- cbind(x1, x2)
>
>> poly(mx, 2)
> Error in poly(dots[[i]], degree, raw = raw, simple = raw) :
>   'degree' must be less than number of unique points
>
> The above error occurs because of the way in which 'mx' is transformed internally in poly(), as per the R-Help post I linked to above.
>
>
> Compare that to:
>
>> poly(mx, degree = 2)
>               1.0          2.0         0.1          1.1         0.2
>  [1,] -0.11175349 -0.112802655  0.34729146 -0.038811031  0.29371194
>  [2,]  0.27620511 -0.102592711  0.27672559  0.076433023  0.10192546
>  [3,]  0.31709686 -0.000822981 -0.06017089 -0.019080000 -0.20283645
>  [4,] -0.05873472 -0.213373684  0.26314361 -0.015455666  0.07009778
>  [5,] -0.17389885  0.046175314  0.08393899 -0.014596893 -0.19610518
>  [6,] -0.07143282 -0.192226574  0.12931566 -0.009237383 -0.15572309
>  [7,] -0.20924410  0.156380030 -0.38783860  0.081152937  0.46977236
>  [8,]  0.09192574 -0.322960534 -0.13012298 -0.011961651 -0.13946871
>  [9,] -0.08030862 -0.176345544 -0.11855987  0.009521379 -0.15294790
> [10,]  0.26551532 -0.126030940 -0.09225246 -0.024494442 -0.17918115
> [11,] -0.16961102  0.033781845  0.23980484 -0.040673544  0.01924080
> [12,] -0.23503411  0.245845222  0.37898576 -0.089074579  0.39427472
> [13,]  0.44343189  0.434902694  0.19305658  0.085607445 -0.06804699
> [14,] -0.16429372  0.018706099 -0.04315970  0.007090868 -0.21166328
> [15,]  0.04616179 -0.317237087 -0.09818924 -0.004532591 -0.17379927
> [16,] -0.20148531  0.130959507 -0.32805340  0.066097939  0.27578123
> [17,] -0.25585213  0.323634018 -0.34406268  0.088029169  0.32460950
> [18,] -0.21168308  0.164513794 -0.10037452  0.021247587 -0.17173927
> [19,]  0.41817752  0.333143463 -0.04018127 -0.016802902 -0.21294380
> [20,]  0.08481772 -0.323649275 -0.16929688 -0.014359375 -0.08495871
> attr(,"degree")
> [1] 1 2 1 2 2
> attr(,"coefs")
> attr(,"coefs")[[1]]
> attr(,"coefs")[[1]]$alpha
> [1] 0.3596862 0.5799695
>
> attr(,"coefs")[[1]]$norm2
> [1]  1.000000 20.000000  1.898620  0.109334
>
>
> attr(,"coefs")[[2]]
> attr(,"coefs")[[2]]$alpha
> [1] 0.5123548 0.5290189
>
> attr(,"coefs")[[2]]$norm2
> [1]  1.0000000 20.0000000  1.5765605  0.1255148
>
>
> attr(,"class")
> [1] "poly"   "matrix"
>
>
>
> Thoughts?

I think based on this, there's a bug in poly():  poly(mx, 2) and 
poly(mx, degree = 2) should be the same.  I'll put in a bug report.

Duncan Murdoch



More information about the R-devel mailing list