# Problems with tuples in Statistics function

**URL:** <https://discourse.julialang.org/t/problems-with-tuples-in-statistics-function/60754>\
**Category:** Statistics\
**Created:** [May 8, 2021, 2:19am UTC](https://discourse.julialang.org/t/problems-with-tuples-in-statistics-function/60754 "2021-05-08T02:19:24Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 10, 2021, 7:59pm UTC](https://discourse.julialang.org/t/problems-with-tuples-in-statistics-function/60754/21 "2021-05-10T19:59:26Z")

</div>

Got it, that actually makes sense. Now I’m back to the problem that I have an Integer Matrix, when I need an Abstract Matrix.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [May 10, 2021, 9:27pm UTC](https://discourse.julialang.org/t/problems-with-tuples-in-statistics-function/60754/22 "2021-05-10T21:27:48Z")

</div>

Do you really?

```julia
julia> typeof(zeros(Integer,2,2))
Matrix{Integer} (alias for Array{Integer, 2})

julia> function kandinsky(a::AbstractMatrix)
       "far out"
       end
kandinsky (generic function with 1 method)

julia> kandinsky(zeros(Integer,2,2))
"far out"

```

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 11, 2021, 3:08am UTC](https://discourse.julialang.org/t/problems-with-tuples-in-statistics-function/60754/23 "2021-05-11T03:08:02Z")

</div>

> [@Jeff\_Emanuel](#):
>
> `kandinsky(zeros(Integer,2,2))`

I can’t tell if you’re playing, I just want one working example of Holltelling’s T^2 Tests, then I can play around and make it do what I need to do.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [May 11, 2021, 4:45am UTC](https://discourse.julialang.org/t/problems-with-tuples-in-statistics-function/60754/24 "2021-05-11T04:45:26Z")

</div>

I’m trying to demonstrate that an Integer Matrix is accepted by a function that expects an AbstractMatrix.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [May 11, 2021, 7:52am UTC](https://discourse.julialang.org/t/problems-with-tuples-in-statistics-function/60754/25 "2021-05-11T07:52:27Z")

</div>

I think more generally people are looking to encourage you to develop the knowledge and toolset required to figure these things out by yourself - which would include some basic knowledge of Julia as a programming language (i.e. not specific packages) so that you, for example, know what `AbstractMatrix` is and how it relates to concrete types such as `Matrix{Integer}`.

For this specific case, a good starting point is the docstring:

```julia
help?> OneSampleHotellingT2Test
search: OneSampleHotellingT2Test OneSampleHotellingT2

  OneSampleHotellingT2Test(X::AbstractMatrix, μ₀=<zero vector>)

  Perform a one sample Hotelling's T^2 test of the hypothesis that the vector of column means of X is equal to μ₀.      

  ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────  

  OneSampleHotellingT2Test(X::AbstractMatrix, Y::AbstractMatrix, μ₀=<zero vector>)

  Perform a paired Hotelling's T^2 test of the hypothesis that the vector of mean column differences between X and Y    
  is equal to μ₀.

```

Okay so this tells us that if we pass two matrices to the function, it will test the hypothesis that the mean of each column of `X` is equal to the mean of the corresponding column in `Y`. Let’s try this - generate some test data:

```julia
julia> xs = hcat([rand(Normal(), 20) for _ ∈ 1:5]...);

julia> ys = hcat([rand(Normal(1.0, 1.0), 20) for _ ∈ 1:5]...);

```

So here we have five columns each, with means of 0 for `xs`, and 1 for `ys`. Let’s test whether they are actually equal:

```julia
julia> OneSampleHotellingT2Test(xs, ys)
One sample Hotelling's T² test
------------------------------
Population details:
    parameter of interest: Mean vector
    value under h_0: [0.0, 0.0, 0.0, 0.0, 0.0]
    point estimate: [-1.33398, -0.95276, -1.19897, -1.28494, -0.853853]

Test summary:
    outcome with 95% confidence: reject h_0
    one-sided p-value: <1e-05

```

Turns out they’re not! You see from the output that `value under h_0` is a vector of five zeros - this is the “zero vector”, and it just says that our null hypothesis is that the means for each of the five columns are the same, or put differently, the difference in their means is zero.

Here of course we know that the real (expected) difference is 1, so let’s test that:

```julia
julia> OneSampleHotellingT2Test(xs, ys, fill(-1.0, 5))
One sample Hotelling's T² test
------------------------------
Population details:
    parameter of interest: Mean vector
    value under h_0: [-1.0, -1.0, -1.0, -1.0, -1.0]
    point estimate: [-1.33398, -0.95276, -1.19897, -1.28494, -0.853853]

Test summary:
    outcome with 95% confidence: fail to reject h_0
    one-sided p-value: 0.5410

```

(Note I’ve tested for a difference of -1, as we are testing x-y, not y-x).

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 11, 2021, 4:54pm UTC](https://discourse.julialang.org/t/problems-with-tuples-in-statistics-function/60754/26 "2021-05-11T16:54:19Z")

</div>

Yes, you are right, I do need to build a skillset. Thank you for reminding me to use help?\> that is a habit I need to develop. Part of the problem is that I’m not in a CompSci class, so I’ve learned the basics in bits and pieces.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 11, 2021, 5:20pm UTC](https://discourse.julialang.org/t/problems-with-tuples-in-statistics-function/60754/27 "2021-05-11T17:20:16Z")

</div>

> [@nilshg](#):
>
> `OneSampleHotellingT2Test(xs, ys, fill(-1.0, 5))`

So, if I’m using a Likert Scale for a sociology survey, I would set the zero vector to [3,3], since the scale goes from 1 to 5, and if they both deviate from the same amount, in the same direction, I fail to reject the null hypothesis?

---

<div class="post-metadata">

**Author:** ![Wei\_Yang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wei_yang/32/23951_2.png) [@Wei\_Yang](https://discourse.julialang.org/u/Wei_Yang)\
**Post date:** [May 11, 2021, 5:28pm UTC](https://discourse.julialang.org/t/problems-with-tuples-in-statistics-function/60754/28 "2021-05-11T17:28:58Z")

</div>

I believe many of us here don’t have a formal Computer Science background, we all learn as we go.

And it appears that you are having trouble with both the codes and statistics.

It probably is a good idea to know a bit more about the statistics portion of your problem, at-least know what to expect, before attempting to solve it in Julia.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 11, 2021, 5:31pm UTC](https://discourse.julialang.org/t/problems-with-tuples-in-statistics-function/60754/29 "2021-05-11T17:31:21Z")

</div>

OK, thanks, yes, I’m thinking of holding back a bit and doing more reading, since I’ve realised I’ve got a bit over my head. I took statistics, and linear algebra, but I realise I don’t remember as much as I thought.

[Previous page](https://discourse.julialang.org/t/problems-with-tuples-in-statistics-function/60754.md?page=1)
