gesistsa / sweater

👚 Speedy Word Embedding Association Test & Extras using R
GNU General Public License v3.0
28 stars 4 forks source link

plotting error #26

Closed cmaimone closed 2 years ago

cmaimone commented 2 years ago
> S4 <- c("math", "algebra", "geometry", "calculus", "equations", "computation", "numbers", "addition")
> T4 <- c("poetry", "art", "dance", "literature", "novel", "symphony", "drama", "sculpture")
> A4 <- c("male", "man", "boy", "brother", "he", "him", "his", "son")
> B4 <- c("female", "woman", "girl", "sister", "she", "her", "hers", "daughter")
> sw <- query(glove_math, S4, T4, A4, B4)
> 
> names(sw)
[1] "S_diff"  "T_diff"  "S_words" "T_words" "A_words" "B_words"
> class(sw)
[1] "sweater" "weat"    "list"   
> plot(sw)
Error in plot_bias(x) : No P slot in the input object x.FALSE

^ I ran the example, then tried to plot. Should this be giving this error?

re: https://github.com/openjournals/joss-reviews/issues/4036

chainsawriot commented 2 years ago

@cmaimone Thanks for raising this.

weat S3 object is not plottable. plot is not an available S3 method (which is still a function) for this object and it is reflected by printing the object (cf. rnd).

require(sweater)
#> Loading required package: sweater

S4 <- c("math", "algebra", "geometry", "calculus", "equations", "computation", "numbers", "addition")
T4 <- c("poetry", "art", "dance", "literature", "novel", "symphony", "drama", "sculpture")
A4 <- c("male", "man", "boy", "brother", "he", "him", "his", "son")
B4 <- c("female", "woman", "girl", "sister", "she", "her", "hers", "daughter")
sw <- query(glove_math, S4, T4, A4, B4)
sw
#> 
#> ── sweater object ──────────────────────────────────────────────────────────────
#> Test type:  weat 
#> Effect size:  1.055015
#> 
#> ── Functions ───────────────────────────────────────────────────────────────────
#> • <calculate_es()>: Calculate effect size
#> • <weat_resampling()>: Conduct statistical test

sw2 <- query(glove_math, S_words = S4, A_words = A4, B_words = B4)
sw2
#> 
#> ── sweater object ──────────────────────────────────────────────────────────────
#> Test type:  rnd 
#> Effect size:  -1.147534
#> 
#> ── Functions ───────────────────────────────────────────────────────────────────
#> • <calculate_es()>: Calculate effect size
#> • <plot()>: Plot the bias of each individual word

Created on 2022-01-27 by the reprex package (v2.0.1)

But the error message can be better, e.g. object of type 'weat' is not plottable. [^JOKE] I will amend the error message to something more useful.

[^JOKE]: OK, this is an in-joke. object of type 'closure' is not subsettable

chainsawriot commented 2 years ago

@cmaimone I think this error message is more useful.

require(sweater)
#> Loading required package: sweater

S4 <- c("math", "algebra", "geometry", "calculus", "equations", "computation", "numbers", "addition")
T4 <- c("poetry", "art", "dance", "literature", "novel", "symphony", "drama", "sculpture")
A4 <- c("male", "man", "boy", "brother", "he", "him", "his", "son")
B4 <- c("female", "woman", "girl", "sister", "she", "her", "hers", "daughter")
sw <- query(glove_math, S4, T4, A4, B4)
sw
#> 
#> ── sweater object ──────────────────────────────────────────────────────────────
#> Test type:  weat 
#> Effect size:  1.055015
#> 
#> ── Functions ───────────────────────────────────────────────────────────────────
#> • <calculate_es()>: Calculate effect size
#> • <weat_resampling()>: Conduct statistical test
plot(sw)
#> Error: Plotting the result of this test type (weat) is not supported.
plot_bias(sw)
#> Error: Plotting the result of this test type (weat) is not supported.

Created on 2022-01-27 by the reprex package (v2.0.1)

Also it is now explicitly documented in the man page.

https://github.com/chainsawriot/sweater/blob/68fa64af1d7a8bf547da7df5e6681365b57787a4/man/plot_bias.Rd#L21

cmaimone commented 2 years ago

That helps