---
title: "warmthcompetence Vignette"
author: "Bushra Guenoun"
date: "`r Sys.Date()`"
output: 
  html_vignette
vignette: >
  %\VignetteIndexEntry{warmthcompetence Vignette}
  %\VignetteEngine{knitr::rmarkdown_notangle}
  %\VignetteEncoding{UTF-8}
bibliography: references.bib
link-citations: true
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  echo = TRUE,
  collapse = TRUE,
  comment = "#>"
)
```

# Warmth and Competence

Warmth and competence are the two main dimensions of social perception and judgment [@cuddy2008] . When individuals introduce or describe themselves, their audiences automatically make judgments about their warmth and competence. In the *warmthcompetence* package, we provide tools that estimate warmth and competence social perceptions from natural self-presentational language. We use pre-trained enet regression models to provide numerical representations of warmth and competence perceptions.

## Installation

To install *warmthcompetence* from CRAN, use the following code in your R session:

```{r, eval = FALSE}
install.packages("warmthcompetence")
```

To install the development version from GitHub, use the following code:

```{r, eval=F}
devtools::install_github("bushraguenoun/warmthcompetence")
```

First, we load the package into our environment.

```{r message = FALSE}
library("warmthcompetence")
```

Note that some features depend on *spacyr* which must be installed separately through Python. To install *spacyr*, follow the instructions [here](https://www.rdocumentation.org/packages/spacyr/). Then run the code below:

```{r eval = FALSE}
spacyr::spacy_initialize()
```

## Usage

*warmthcompetence* contains two main functions: `warmth()` and `competence()`. These functions can be used as described below:

```{r eval=FALSE}
competence_scores <- competence(text_vector, ID_vector, metrics = "scores")

warmth_scores <- warmth(text_vector, ID_vector, metrics = "scores")
```

In the code above, `text_vector` is the vector of texts that will be assessed for warmth or competence. `ID_vector` is a vector of IDs that will be used to identify the warmth or competence scores. The `metrics` argument allows users to decide what metrics to return. Users can return the warmth or competence scores (`metrics = "scores"`), the features that underlie the warmth or competence scores (`metrics = "features"`), or both the warmth or competence scores and the features (`metrics = "all"`). The default choice is to return the warmth or competence scores.

## Example: Warmth and Competence Signaling in Self Introductions

We ran a study in which 393 participants were randomly assigned to either the warmth or competence condition and asked to write a short introduction of themselves that presented them as a [warm/competent] person. Then, we had three independent judges blind to participant condition rate each of the introductions for warmth and competence on a scale of 1 to 10.

The study data can be accessed by calling `data("vignette_data")`. This command will return a data frame with all of the data collected from the study. The columns of this data frame are the following:

* `ResponseId`: participant identifiers
* `bio`: participant introductions
* `condition`: participant condition in the study (warmth versus competence).
* `RA_warm_AVG`: the average perceptions of warmth for each participant introduction on a scale of 1 (extremely low warmth) to 10 (extremely high warmth) across three independent judges ($\alpha = 0.76$). The individual RA ratings are in the following columns: `warm_1`, `warm_2`, and `warm_3`
* `RA_comp_AVG`: the average perceptions of warmth for each participant introduction on a scale of 1 (extremely low competence) to 10 (extremely high competence) across three independent judges ($\alpha = 0.79$). The individual RA ratings are in the following columns: `comp_1`, `comp_2`, and `comp_3`

### Predicting Warmth Perceptions

Can our warmth model predict the average warmth ratings of the independent judges?

First we run the functions on the study data.

```{r eval=FALSE}
data("vignette_data")

# Generate competence scores
competence_scores <- competence(vignette_data$bio, vignette_data$ResponseId)

# Generate warmth scores
warmth_scores <- warmth(vignette_data$bio, vignette_data$ResponseId)

# Merge scores together
both_scores <- dplyr::inner_join(competence_scores, warmth_scores,
                                 by = c("ID" = "ID"))

# Merge scores into participant data
all_data <- dplyr::left_join(vignette_data, both_scores,
                             by = c("ResponseId" = "ID"))
```

```{r include=FALSE}
# Note: for CRAN, we can't run warmth() or competence() because
# they require spacyr, which uses python. So we just load the
# vignette data scores instead.
data("vignette_data")
both_scores <- readRDS("vignette_data_scores.rds")
all_data <- dplyr::left_join(vignette_data, both_scores,
                             by = c("ResponseId" = "ID"))
```

Then, we explore whether the warmth model predicts the warmth ratings of the independent judges.

```{r}
warmth_model <- lm(RA_warm_AVG ~ warmth_predictions,
                   data = all_data)

summary(warmth_model)
```

As can be seen above, the predictions of the warmth model positively predict the independent judges' ratings.

### Predicting Competence Perceptions

Can our competence model predict the average competence ratings of the independent judges?

```{r}
competence_model <- lm(RA_comp_AVG ~ competence_predictions,
                       data = all_data)

summary(competence_model)
```

As can be seen above, the predictions of the warmth model positively predict the independent judges' ratings.

### Predicting Participant Condition

Are model predictions of competence higher for the participants asked to present themselves as a competent person compared to a warm person?

```{r}
t.test(competence_predictions ~ condition, data = all_data)
```

As can be seen above, the model significantly predicted that participants in the competence condition expressed more competence compared to those in the warmth condition.

Now, are model predictions of warmth higher for the participants asked to present themselves as a warm person compared to a competent person?

```{r}
t.test(warmth_predictions ~ condition, data = all_data)
```

As can be seen above, the model significantly predicted that participants in the warmth condition expressed more warmth compared to those in the competence condition.

## Conclusion

In this example, our pre-trained enet regression models predicted the ratings of independent human judges and participant judges. Feel free to use these models on your own data and reach out with any comments, questions, or concerns!

## References
