[R] non-conformable arrays

peter dalgaard pd@|gd @end|ng |rom gm@||@com
Wed Sep 11 18:41:02 CEST 2024


Hum... Two points: You are using |> a lot and tcrossprod() is a primitive, so ignores argnames. This makes me suspicious that things like 

... ) |>  tcrossprod(x = mm)

might not do what you think it does.

E.g., 

> a <- matrix(1,10,2)
> b <- matrix(1,3,2)
> tcrossprod(y=b, x=a)
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    2    2    2    2    2    2    2    2    2     2
[2,]    2    2    2    2    2    2    2    2    2     2
[3,]    2    2    2    2    2    2    2    2    2     2
> tcrossprod(x=a, y=b)
      [,1] [,2] [,3]
 [1,]    2    2    2
 [2,]    2    2    2
 [3,]    2    2    2
 [4,]    2    2    2
 [5,]    2    2    2
 [6,]    2    2    2
 [7,]    2    2    2
 [8,]    2    2    2
 [9,]    2    2    2
[10,]    2    2    2

-pd

> On 11 Sep 2024, at 17:55 , Thierry Onkelinx <thierry.onkelinx using inbo.be> wrote:
> 
> Dear all,
> 
> I'm puzzled by this error. When running tcrossprod() within the function it
> returns the error message. The code also outputs the object a and b.
> Running the tcrossprod() outside of the function works as expected.
> 
>        cat("a <-")
>        dput(a)
>        cat("b <-")
>        dput(b)
>        cat("tcrossprod(a, b)")
>        tcrossprod(a, b)
> 
> a <-structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 1), dim = c(10L, 2L), dimnames = list(c("9", "13", "21",
> "29", "30", "37", "52", "53", "56", "70"),
> c("tmp2028c70ae152b4c63bb7ab902158b408366217581",
> "tmp2028c70ae152b4c63bb7ab902158b408366217582")), assign = c(1L,
> 1L), contrasts = list(tmp2028c70ae152b4c63bb7ab902158b40836621758 =
> "contr.treatment"))
> b <-structure(c(-0.916362039446752, -0.849801808879291, -0.744535398206787,
> 0.875896407785924, 0.822587420283086, 0.894210774042389), dim = 3:2)
> tcrossprod(a, b)
> 
> For those how like a fully reproducible example:
> the offending line in the code:
> https://github.com/inbo/multimput/blob/e1cd0cdff7d2868e4101c411f7508301c7be7482/R/impute_glmermod.R#L65
> a (failing) unit test for the code:
> https://github.com/inbo/multimput/blob/e1cd0cdff7d2868e4101c411f7508301c7be7482/tests/testthat/test_ccc_hurdle_impute.R#L10
> 
> Best regards,
> 
> ir. Thierry Onkelinx
> Statisticus / Statistician
> 
> Vlaamse Overheid / Government of Flanders
> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
> FOREST
> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
> thierry.onkelinx using inbo.be
> Havenlaan 88 bus 73, 1000 Brussel
> *Postadres:* Koning Albert II-laan 15 bus 186, 1210 Brussel
> *Poststukken die naar dit adres worden gestuurd, worden ingescand en
> digitaal aan de geadresseerde bezorgd. Zo kan de Vlaamse overheid haar
> dossiers volledig digitaal behandelen. Poststukken met de vermelding
> ‘vertrouwelijk’ worden niet ingescand, maar ongeopend aan de geadresseerde
> bezorgd.*
> www.inbo.be
> 
> ///////////////////////////////////////////////////////////////////////////////////////////
> To call in the statistician after the experiment is done may be no more
> than asking him to perform a post-mortem examination: he may be able to say
> what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does not
> ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
> ///////////////////////////////////////////////////////////////////////////////////////////
> 
> <https://www.inbo.be>
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com



More information about the R-help mailing list