-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
marginal values #8
Comments
Could you be a bit more specific? Does |
In R there's an |
I'm sorry. I haven't time right now for working on that PR :/ |
Then I'll try to have a look later. Shouldn't be hard. |
Thanks! There is no hurry. |
I have a similar usecase but rather for an equivalent of
How do you see it? |
As I said, I'd rather go with a wrapper function. We could also imagine providing a function, say |
Hi, has this issue been closed without fixing the issue? How to add marginals? Thanks, Nicolò |
see the referenced PR #19. You can use |
Thanks, I was using release 0.3.1 where it seems the keyword is not exported. Btw, maybe I'm doing it wrong. > table(dat$A, dat$B)
1 2 3 4
1 2 2 2 2
2 2 2 2 2
3 2 2 2 2
> addmargins(table(dat$A, dat$B))
1 2 3 4 Sum
1 2 2 2 2 8
2 2 2 2 2 8
3 2 2 2 2 8
Sum 6 6 6 6 24
addmargins(table(dat$A, dat$B), 1)
1 2 3 4
1 2 2 2 2
2 2 2 2 2
3 2 2 2 2
Sum 6 6 6 6
julia> freqtable(dat, :A, :B)
3×4 Named Array{Int64,2}
A ╲ B │ 1 2 3 4
──────┼───────────
1 │ 2 2 2 2
2 │ 2 2 2 2
3 │ 2 2 2 2
prop(freqtable(dat, :A, :B), margins = 1)
3×4 Named Array{Float64,2}
A ╲ B │ 1 2 3 4
──────┼───────────────────────
1 │ 0.25 0.25 0.25 0.25
2 │ 0.25 0.25 0.25 0.25
3 │ 0.25 0.25 0.25 0.25
prop(freqtable(dat, :A, :B), margins = (1,2))
3×4 Named Array{Float64,2}
A ╲ B │ 1 2 3 4
──────┼───────────────────
1 │ 1.0 1.0 1.0 1.0
2 │ 1.0 1.0 1.0 1.0
3 │ 1.0 1.0 1.0 1.0
|
Have a look at help of
|
Thanks, but none of those is similar to what R's addmargins does (what's asked here) |
I mean, return this: x = freqtable(dat, :A, :B)
vcat(hcat(x, sum(x, dims = 2)), hcat(sum(x, dims = 1)..., sum(x)))
4×5 Named Array{Int64,2}
A ╲ hcat │ 1 2 3 4 5
─────────┼───────────────────
1 │ 2 2 2 2 8
2 │ 2 2 2 2 8
3 │ 2 2 2 2 8
4 │ 6 6 6 6 24 preserving names and so on |
Ugly, but this: function addmargins(tab)
x, y = names(tab)
x = string.(x)
y = string.(y)
push!(x, "Sum")
push!(y, "Sum")
res = vcat(hcat(tab, sum(tab, dims = 2)), hcat(sum(tab, dims = 1)..., sum(tab)))
setnames!(res, x, 1)
setnames!(res, y, 2)
res.dimnames = tab.dimnames
res
end
|
Ah - understood. I do not think it is supported. Out of curiosity - in what situation would you need it (apart from the fact that R provides it)? |
In a report or a journal paper it's a nice way to present some data. In this specific case: I have an experiment with outliers. I want to show how many outliers are present for each condition, the sample size, the number of valid/invalid trials... I care about the proportion of valid/unvalid trials, but the raw numbers are more important (25% out of 4 or out of 10000 makes a big difference here). Those tables sumarize it well:
(the syntax here is emac's org mode, julia's code that's called is: For the three age groups you see |
Also, maybe conversion to string can be replaced by something like |
I agree with this use-case, but I would rather create a custom display function for this (that could e.g. automatically also use MIME-type to output HTML, LaTeX etc.) so that you have a separate Model from View. |
It might make sense, but you don't always want to display it with the marginals. So I don't know which is the best way to organize this. Any idea? |
I agree something like Something which is annoying in R is when you want to add margins to a table of proportions: |
Would be great to have the ability to show/calculate/store the marginal values of a table, when that is required.
Best,
The text was updated successfully, but these errors were encountered: