knitr::opts_chunk$set( fig.width = 6, fig.asp = 0.618, fig.align = "center", dpi = 300, collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "90%" )
The goal of happyr is to document the R codes and the dataset for the quantitative analyses in Rajeg's [-@rajeg_metaphorical_2018] PhD thesis (submitted for examination on 27 September 2018 and passed without amendments for the award of the degree on 1 April 2019). The study focuses on metaphors for happiness near-synonyms in Indonesian. The corpus data for the study mainly come from the Indonesian Leipzig Corpora Collection [@quasthoff_indonesian_2013; @goldhahn_building_2012; @biemann_leipzig_2007]. The Leipzig Corpora are freely available for download and their use is licensed under the Creative Common License CC-BY (see the Terms of Usage page for further details).
The happyr package is based on the core packages in the tidyverse, and is built under R version 4.0.5 (2021-03-31) -- "Shake and Throw" (see the Session Info section at the bottom of the page for further details on the dependencies).
The thesis was supervised by Associate Professor Alice Gaby (main), Dr. Howard Manns (associate), and Dr. Simon Musgrave (associate). The panel members during the author's candidature milestones consisted of Dr. Anna Margetts, Dr. Réka Benczes, and Prof. John Newman. The two external examiners of the thesis were Prof. Martin Hilpert (Université de Neuchâtel, Switzerland) and Dr. Karen Sullivan (The University of Queensland, Australia) The PhD research of the author was fully funded by Monash University, Australia through the International Graduate Research Scholarships schemes (i.e. Monash International Postgraduate Research Scholarships (MIPRS, now MITS) and Monash Graduate Scholarships (MGS)). The author also benefited from generous research and travel funding provided by the Monash Arts Graduate Research and the Monash Graduate Research Office.
The happyr package can be installed from GitHub with the remotes package:
# Install remotes if needed if(!require(remotes)) install.packages("remotes") # Then, install the happyr package from GitHub remotes::install_github("gederajeg/happyr")
citation("happyr")
First, load the happyr and tidyverse packages using the library()
function.
# load the required packages library(happyr) library(tidyverse)
All codes for the Kappa's calculation in the interrater agreement trial are presented in the Examples section of the documentation of the kappa_tidy()
function. Type ?kappa_tidy()
in the R console to see them or check the online documentation.
The ggplot2 codes for generating Figure 3.1 in Rajeg [-@rajeg_metaphorical_2018, Ch. 3] is wrapped into a function called plot_cxn_interrater()
. The input data frame is top_cxn_data
.
# prepare plot title and caption plot_title <- expression(paste("Distribution of the constructional patterns for the agreed cases (", N["patterns"] >= "5)", sep = "")) plot_caption <- "The values inside the bars are the token frequency of the patterns" plot_cxn_interrater(df = top_cxn_data) + # add plot title and caption labs(title = plot_title, caption = plot_caption) + # adjust the size of the plot title and caption theme(plot.title = element_text(size = 10), plot.caption = element_text(size = 7))
The main metaphor data for Chapter 5, 6, and 7 is stored as a tibble in phd_data_metaphor
. The relevant function for the token, type, and type/token ratio analyses in Chapter 5 and 6 is ttr()
.
# calculation for the token, type, and type/token ratio ttr_metaphor <- ttr(df = phd_data_metaphor, schema_var = "metaphors", # specify col.name of the metaphor variable lexunit_var = "lu", # specify col.name of the lexical unit variable float_digits = 2)
The following code retrieves the top-10 metaphors sorted according to their token frequencies [@rajeg_metaphorical_2018, Ch. 5, Table 5-1]. A function for rendering the metaphors strings as small-capital in the MS Word output is available in the package as scaps()
; keyboard shortcut to produce the so-called "pipe" %>%
in the code-chunk below is Ctrl + Shift + M
(on Windows) or Cmd + Shift + M
(on macOS).
top_n(x = ttr_metaphor, n = 10L, wt = token) %>% mutate(metaphors = scaps(metaphors)) %>% # render the metaphors into small capitals to be printed in MS Word output knitr::kable(caption = "Top-10 most frequent metaphors", row.names = TRUE)
The column token
shows the token frequency of a metaphor meanwhile the column type_lu
represents the number of different lexical-unit types evoking the source domain frames of the metaphor in the metaphorical expressions. The original values of the type_per_token_lu
are normalised into the number of type per 100 tokens [cf. @oster_emotions_2018, pp. 206-207]. Thus, the closer the TTR of a metaphor to 100, the higher the rate of different lexical-unit type per 100 tokens of the metaphor (see further below) [@stefanowitsch_corpus-based_2016, pp. 118-120; @stefanowitsch_corpus_2017, p. 282; @oster_emotions_2018, p. 206; @oster_using_2010, pp. 748-749].
Use get_lu_table()
to retrieve the source frame lexical units in the metaphorical expressions instantiating a given metaphor. It is illustrated here with the linguistic expressions for happiness is a desired goal metaphor [@rajeg_metaphorical_2018, Ch. 5, Table 5-3]:
# print the top-10 Lexical Units of the HAPPINESS IS A DESIRED GOAL metaphor get_lu_table(metaphor = "is a desired goal$", top_n_only = TRUE, top_n_limit = 10L, df = phd_data_metaphor) %>% knitr::kable(caption = paste("Top-10 most frequent lexical units for ", scaps("happiness is a desired goal."), sep = ""), row.names = TRUE)
The column Perc_overall
indicates the percentage of a given LU from the total tokens of the happiness is a desired goal metaphor. More linguistic citations for the metaphorical expressions are presented in the thesis.
From the output of ttr()
above, which is stored in the ttr_metaphor
table, we can retrieve the top-10 metaphors with high type frequencies with the following codes [@rajeg_metaphorical_2018, Ch. 6, Table 6-1]; the type frequency of a metaphor indicates the number of different lexical unit types expressing a given metaphor.
# sort by type frequency productive_metaphor <- ttr_metaphor %>% arrange(desc(type_lu)) %>% # sort in descending order for the type frequency top_n(10, type_lu) %>% # get the top-10 rows mutate(metaphors = scaps(metaphors)) # small-caps the metaphors texts # print as table productive_metaphor %>% select(Metaphors = metaphors, Token = token, `%Token` = perc_token, Type = type_lu, `%Type` = perc_type_lu) %>% knitr::kable(caption = 'Top-10 metaphors sorted on their type frequency.', row.names = TRUE)
The codes below generates Table 6-2 [@rajeg_metaphorical_2018, Ch. 6] that ranks metaphors with high type frequency above according to their type/token ratio.
productive_metaphor %>% arrange(desc(type_per_token_lu)) %>% select(Metaphors = metaphors, Token = token, Type = type_lu, `Type/token ratio` = type_per_token_lu) %>% knitr::kable(caption = 'Metaphors with high type frequency sorted by their Type/Token Ratio (TTR).', row.names = TRUE)
It is clear that the first two metaphors in the table above (i.e. r scaps("happiness is an imperilled entity")
and r scaps("happiness is light")
) have higher ratio for different types of linguistic instantiations per 100 tokens, despite the vast difference in their token frequencies compared to the remanining metaphors with high token frequencies in the table. This suggests that these two metaphors are expressed with relatively wider range of expressions with respect to their token frequencies, compared to the frequent metaphors.
Next, a helper function called get_creative_metaphors()
is available to retrieve the top-10 creative metaphors [@rajeg_metaphorical_2018, Ch. 6, Table 6-5]. I filter and discuss the metaphors with high type/token ratio and occurring at least three tokens in the sample, as shown in the codes below
min_freq <- 3L table_caption <- paste('Top-10 creative metaphors sorted based on the TTR value and occurring at least ', happyr::numbers2words(min_freq), ' tokens.', sep = "") creative_metahors <- ttr_metaphor %>% get_creative_metaphors(min_token = min_freq, top_n_limit = 10L) %>% mutate(metaphors = scaps(metaphors)) # print the table creative_metahors %>% select(Metaphors = metaphors, Token = token, Type = type_lu, `Type/token ratio` = type_per_token_lu) %>% knitr::kable(caption = table_caption, row.names = TRUE)
One way to interpret the values in the Type/token ratio
(TTR) column is to conceive them as representing the number of unique lexical-unit types per 100 tokens of a metaphor. The higher the ratio, the more creative a given metaphor is linguistically expressed. For instance, the TTR value of r happyr::scaps("happiness is an adversary")
(i.e. r unlist(ttr_metaphor[ttr_metaphor$metaphors=="happiness is an adversary", "type_per_token_lu"])
) indicates that there are about r unlist(ttr_metaphor[ttr_metaphor$metaphors=="happiness is an adversary", "type_per_token_lu"])
unique types per 100 tokens of the r happyr::scaps("happiness is an adversary")
, which is much higher than the TTR value of r scaps("happiness is a possessable object")
(i.e. r unlist(ttr_metaphor[ttr_metaphor$metaphors=="happiness is a possessable object", "type_per_token_lu"])
). The TTR value of a metaphor is used to represent the creativity ratio of a metaphor in its linguistic manifestation [cf. @oster_emotions_2018, p. 206; @oster_using_2010, pp. 748-749].
The data for retrieving the information on the submappings and the source frames of metaphors is contained within phd_data_metaphor
. Among the relevant functions for retrieving these information are get_submappings()
and get_frames()
. The illustration is based on data for the r happyr::scaps("happiness is liquid in a container")
metaphor.
# get the submappings for the liquid in a container get_submappings(metaphor = "liquid in a container", df = phd_data_metaphor) %>% mutate(submappings = scaps(submappings)) %>% knitr::kable(caption = paste("Submappings for ", scaps("happiness is liquid in a container."), sep = ""), row.names = TRUE)
Column n
shows the 'token frequency' of the submappings (with perc
indicates the token's percentage). Meanwhile type
shows the 'type frequency' of the submappings (i.e., the number of different lexical unit types evoking the corresponding submappings of a given metaphor).
Use get_frames()
to retrieve frequency profiles of the source frames for a given metaphor:
# get the source frames evoked by the metaphorical expressions for the liquid in a container get_frames(metaphor = "liquid in a container", df = phd_data_metaphor) %>% mutate(frames = scaps(frames)) %>% knitr::kable(caption = paste("Source frames for ", scaps("happiness is liquid in a container."), sep = ""), row.names = TRUE)
Based on the same data, it is also possible to retrieve a frequency table for the lexical units and the submappings they evoke for a given metaphor. Use get_lu_submappings_table()
for this purpose.
get_lu_submappings_table(metaphor = "liquid in a container", df = phd_data_metaphor) %>% mutate(submappings = scaps(submappings), # small-cap the submapping lu = paste("*", lu, "*", sep = "")) %>% # italicised the printed lexical units knitr::kable(caption = paste("Evoked submappings for the lexical units of the ", scaps("happiness is liquid in a container"), " metaphor.", sep = ""), row.names = TRUE)
The column perc_expr_overall
indicates the percentages of the token frequencies of the lexical units for the given metaphor. Meanwhile perc_expr_by_submappings
indicates the percentages of the lexical units for each submapping of the given metaphor.
The function for generating Figure 5.1 in Chapter 5 is plot_body_part()
with phd_data_metaphor
as the only input argument:
plot_body_part(df = phd_data_metaphor)
The barplot shows the distribution of the body-part terms that are explicitly mentioned in metaphorical expressions about happiness in the sample.
The following codes are used to generate Table 5-12 in Chapter 5 for the top-10 most frequent co-occurrence of body-part terms and the metaphors:
# body-part gloss bp_gloss <- tibble(gloss = c('chest/bosom', 'self', 'liver', 'eyes', 'face', 'body', 'face', 'face', 'deepest part of the heart', 'lips', 'mouth', 'body; bodily'), body_part_terms = c('dada', 'diri', 'hati', 'mata', 'muka', 'tubuh', 'wajah', 'paras', 'lubuk kalbu', 'bibir', 'mulut', 'jasmani')) # generate the table phd_data_metaphor %>% filter(body_part_inclusion %in% c('y')) %>% count(body_part_terms, metaphors) %>% arrange(desc(n)) %>% left_join(bp_gloss, by = 'body_part_terms') %>% # join the glossing tibble select(metaphors, body_part_terms, gloss, n) %>% mutate(metaphors = scaps(metaphors), body_part_terms = paste("*", body_part_terms, "* '", gloss, "'", sep = "")) %>% select(Body_parts = body_part_terms, Metaphors = metaphors, N = n) %>% top_n(10, N) %>% knitr::kable(caption = 'The ten most frequent <span style="font-variant:small-caps;">Body-part</span>`*`<span style="font-variant:small-caps;">Metaphors</span> co-occurrence for <span style="font-variant:small-caps;">Happiness</span> in Indonesian.', row.names = TRUE)
The distinctiveness of a given metaphor and collocate with each happiness synonym is measured using one-tailed, Binomial Test implemented in the Multiple Distinctive Collexeme Analysis (MDCA) [cf., e.g., @hilpert_distinctive_2006; @hoffmann_collostructional_2013, pp. 299-300]. The function to perform MDCA is mdca()
.
# MDCA for metaphor * synonyms mdca_res <- mdca(df = phd_data_metaphor, cxn_var = "synonyms", # `cxn_var` = constructions column coll_var = "metaphors") # `coll_var` = collexeme/collocates column
The input data frame for performing MDCA for the distinctive collocates are available as colloc_input_data
. The English gloss/translation for the distinctive collocates are stored in dist_colloc_gloss
.
# mdca for window-span collocational data mdca_colloc <- mdca(df = colloc_input_data, cxn_var = "synonyms", coll_var = "collocates")
The package also provides two related functions to retrieve the attracted/distinctive and the repelled items from the results of MDCA. They are mdca_attr()
and mdca_repel()
. The following example shows how to get the distinctive metaphors for kesenangan 'pleasure; happiness' having the association strength of equal to, or greater than, two (i.e. p~binomial~ < 0.01) [@rajeg_metaphorical_2018, Ch. 7, Table 7-5]:
mdca_res %>% mdca_attr(filter_by = "cxn", cxn_type = "kesenangan", min_assocstr = 2) %>% mutate(exp = round(exp, 3L), # round the expected co-occurrence frequency metaphors = scaps(metaphors)) %>% select(-synonyms) %>% as.data.frame() %>% knitr::kable(caption = "Distinctive metaphors for *kesenangan* 'pleasure'", row.names = TRUE)
The p_holm
column provides the Holm's corrected significance level [@gries_statistics_2009, pp. 249, 251] of the Binomial Test p-value (p_binomial
). The Binomial p-value is used as the basis for the association strength value (assocstr
) [cf. @hoffmann_collostructional_2013, p. 305], which is derived via the log-transformed p~Binomial~-value to the base of 10. The dec
column indicates the significane of the association between the metaphor and kesenangan 'pleasure' at the corrected level. Column exp
shows the 'expected' co-occurrence frequency of the metaphor with kesenangan while n
is the 'observed' co-occurrence frequency in the sample.
The following code shows the use of mdca_repel()
for retrieving metaphors strongly dissociated with kesenangan 'pleasure' [@rajeg_metaphorical_2018, Ch. 7, Table 7-6]:
mdca_res %>% mdca_repel(filter_by = "cxn", cxn_type = "kesenangan", min_assocstr = -2) %>% mutate(exp = round(exp, 3L), metaphors = scaps(metaphors)) %>% select(-synonyms) %>% knitr::kable(caption = "Repelled metaphors for *kesenangan* 'pleasure'", row.names = TRUE)
Finally, the codes below show how to retrieve the top-20 most distinctive collocates co-occurring with kesenangan 'pleasure' within the span of 4 words to the left and right of kesenangan [@rajeg_metaphorical_2018, Ch. 7, Table 7-7].
# present the result table for collocational analysis of *kesenangan* mdca_attr(mdca_colloc, cxn_type = '^kesenangan') %>% top_n(20, assocstr) %>% left_join(dist_colloc_gloss, by = "collocates") %>% # left-join the gloss for the distinctive collocates select(-synonyms) %>% select(collocates, gloss, everything()) %>% mutate(exp = round(exp, 3), collocates = paste("*", collocates, "*", sep = "")) %>% knitr::kable(caption="The 20 most distinctive, 4-window span collocates for *kesenangan* 'pleasure' in the whole Indonesian Leipzig Corpora collection.", row.names = TRUE)
It appears that kesenangan 'pleasure' is strongly associated with negative nuance as it more frequently co-occurs with words, such as dosa 'sin', hawa nafsu 'lust', nafsu 'lust', seksual 'sexual', and duniawi 'worldly; earthly'.
devtools::session_info()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.