Skip to content

Fix weighted.mean(w =) argument's denominator#2

Open
zekiakyol wants to merge 1 commit intoSTAT-ATA-ASU:gh-pagesfrom
zekiakyol:gh-pages
Open

Fix weighted.mean(w =) argument's denominator#2
zekiakyol wants to merge 1 commit intoSTAT-ATA-ASU:gh-pagesfrom
zekiakyol:gh-pages

Conversation

@zekiakyol
Copy link

Thank your for your great post! It immensely helps to grasp the topic.

Even though R automatically re-weights if sum of the weights are not equal to 1, following fix makes is mathematically correct in my opinion:

Since folds object is a vector, sum(folds) is numeric sum of 1s, 2s, 3s, 4s, 5s which is greater than total sample size 1000.

sum(folds)
# [1] 2956

table(folds)/sum(folds)
# folds
#          1          2          3          4          5
# 0.07104195 0.07171854 0.06326116 0.06562923 0.06664411

I think the correct denominator and weight is:

sum(xtabs(~folds))
# [1] 1000

table(folds)/sum(xtabs(~folds))
# folds
#     1     2     3     4     5
# 0.210 0.212 0.187 0.194 0.197
  • The rest of the changes are just spacing.

Thank your for the great post!

Even though R automatically re-weights if sum of the weights are not equal to 1, following fix makes is mathematically correct in my opinion:

Since `folds` object is a vector, `sum(folds)` is sum of numerically 1s, 2s, 3s, 4s, 5s which is greater than total sample size 1000.
```
> sum(folds)
[1] 2956

> table(folds)/sum(folds)
folds
         1          2          3          4          5
0.07104195 0.07171854 0.06326116 0.06562923 0.06664411
```

I think the correct denominator and weight is

```
> sum(xtabs(~folds))
[1] 1000

> table(folds)/sum(xtabs(~folds))
folds
    1     2     3     4     5
0.210 0.212 0.187 0.194 0.197
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant