---
title: "Code: Benefits of humanlike chatbots for the social and mental health of users"
author: "Rose Guingrich"
date: "1/30/2023"
output:
  word_document: default
  pdf_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```



# Phase 1 Part 1: Replika (chatbot user group)



## NOTES:
### Prior to analysis:
Check column numbers - have been adjusted!

Check XP column and fix it to display only numbers




# Load packages and data
```{r}
rm(list=ls())
library(tidyverse)
library(gridExtra)
# load Cronbach's alpha library:
library(ltm)

# import data
dat <- read.csv("/location/dat_users.csv", header=TRUE)

```



# Clean stuff up
```{r}
# Rename columns
dat <- dat %>% rename(social_health_socialinteractions = Social_health._1, 
                      social_health_relatfamilyfriends = Social_health._2,
                      social_health_selfesteem = Social_health._3,
                      personality = Consciousness_5, XP = Q109, natural = Q99_1, 
                      Conscious = Q110_1, humanlike = Q102_1, lifelike = Q103_1,
                      alive = Q104_1, lively = Q105_1, responsive = Q106_1,
                      if_emotions = Q111_1, if_livingbeing = Q112_1,
                      if_depended = Q113_1)

###### NOTES FOR SCORING

# social_health 7 = very helpful, 1 = very harmful
# experience/consciousness/personality/agency 7 = strongly agree / it has those things, 1 = strongly disagree
# natural/conscious/humanlike, etc. 7 = as much that as possible (7 = natural, 1 = fake, e.g.)
# if_emotions 7 = very comfortable 
# if_livingbeing / dependent 7 = very good



### Make all blanks = NA

dat <- data.frame(dat)
dat <- dat %>% mutate_all(na_if,"")

### Make all rows except country write-in and free response numeric

numericColumns <- names(dat)
numericColumns <- numericColumns[!(numericColumns %in% c("Country", "Race", "Gender", "Country_2_TEXT", "Gender_4_TEXT"))]
dat[, numericColumns] <- lapply(dat[, numericColumns], as.numeric)

```



# Demographics
```{r}
### Collect demographics and percentages

# Country: USA (1) or OTHER (2) (removing NAs)

demographics_country <- dat %>% filter(!is.na(Country)) %>% group_by(Country) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Country: what is filled in with OTHER + NA's = USA (minus 7 NA's from not selecting anything)
# ****************do later once I have something
demographics_country_other <- dat %>% group_by(Country_2_TEXT) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Ethnicity: Hispanic (1) or Not hispanic (2) (removing NAs)

demographics_ethnicity <- dat %>% filter(!is.na(Ethnicity.)) %>% group_by(Ethnicity.) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Race: (makes separate categories for multiple races chosen)

demographics_race <- dat %>% filter(!is.na(Race)) %>% group_by(Race) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Education: (1) some high school or less, (2) High school diploma or GED, (3) Some college, but no degree, (4) associates or technical degree, (5) Bachelor's degree, (6) Graduate or professional degree, (7) Prefer not to say

demographics_education <- dat %>% filter(!is.na(Education)) %>% group_by(Education) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# INCOME: (1) less than 25k, (2) 25-49k, (3) 50-74k, (4) 75-99k, (5) 100-149k, (6) 150k+, (7) Prefer not to say

demographics_income <- dat %>% filter(!is.na(Income)) %>% group_by(Income) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# AGE: (1) 18-24, (2) 25-34, (3) 35-44, (4) 45-54, (5) 55-64, (6) 65+

demographics_age <- dat %>% filter(!is.na(Age)) %>% group_by(Age) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# GENDER: (1) male, (2) female, (3) non-binary/third gender, (4) prefer to self-describe, (5) Prefer not to say

demographics_gender <- dat %>% filter(!is.na(Gender)) %>% group_by(Gender) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# RELATIONSHIP STATUS: (1) married, (2) living with a partner, (3) widowed, (4) divorced/separated, (5) never been married

demographics_relationshipstatus <- dat %>% filter(!is.na(Relationship_status)) %>% group_by(Relationship_status) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)
```



# Data Distributions + Averages

## Social health
```{r}
### Notes for scoring
### 1 = very harmful, 2 = moderately harmful, 3 = slightly harmful, 4 = neutral, 5 = slightly helpful, 6 = moderately helpful, 7 = very helpful

#################### Social health counts: data distributions + data for histogram visualization 
# social interactions
count_social_health_socialinteractions <- dat %>% filter(!is.na(social_health_socialinteractions)) %>% group_by(social_health_socialinteractions) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# relationships with family and friends
count_social_health_relatfamilyfriends <- dat %>% filter(!is.na(social_health_relatfamilyfriends)) %>% group_by(social_health_relatfamilyfriends) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# self-esteem
count_social_health_selfesteem <- dat %>% filter(!is.na(social_health_selfesteem)) %>% group_by(social_health_selfesteem) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

################### Social health means
mean_social_health_socialinteractions <- mean(dat$social_health_socialinteractions, na.rm = TRUE)
mean_social_health_relatfamilyfriends <- mean(dat$social_health_relatfamilyfriends, na.rm = TRUE)
mean_social_health_selfesteem <- mean(dat$social_health_selfesteem, na.rm = TRUE)
### combined (all 3)
mean_social_health_all <- ((mean_social_health_relatfamilyfriends + mean_social_health_socialinteractions + mean_social_health_selfesteem)/3)

################# TABLE (of mean only, social health counts are different sizes)
social_health_means <- tibble(mean_social_health_socialinteractions, mean_social_health_relatfamilyfriends,
                            mean_social_health_selfesteem, mean_social_health_all)

## add new Social Health average (across rows from 1-3) to main dataframe

####### USED FOR REGRESSION

dat$mean_social_health_for_reg <- rowMeans(dat[,c("social_health_socialinteractions","social_health_relatfamilyfriends","social_health_selfesteem")], na.rm = TRUE)
```
## Theory of Mind: Experience, Agency, and Consciousness
```{r}
### Regression means only, no distributions
### Notes for scoring
### 1 = strongly disagree, it does not have those things, 7 = strongly agree, it has those things

##################### Means

############ Experience
##find the mean each of columns Experience_1 to _6
mean_tom_exp <- colMeans(dat[ , c(18:23)], na.rm = TRUE)
## find mean of all columns together
mean_tom_exp <- mean(mean_tom_exp)

## add new Experience average (across rows from 1-6) to dat

dat$mean_tom_exp_for_reg <- rowMeans(dat[,c("Experience_1","Experience_2","Experience_3","Experience_4","Experience_5","Experience_6")])

############ Agency
##find the mean each of columns Agency_1 to _5
mean_tom_agency <- colMeans(dat[ , c(29:33)], na.rm = TRUE)
## find mean of all columns together
mean_tom_agency <- mean(mean_tom_agency)

## add new Agency average (across rows from 1-5) to dat

dat$mean_tom_agency_for_reg <- rowMeans(dat[,c("Agency_1","Agency_2","Agency_3","Agency_4","Agency_5")])

############ Consciousness
##find the mean each of columns Consciousness_1 to _4
mean_tom_consc <- colMeans(dat[ , c(24:27)], na.rm = TRUE)
## find mean of all columns together
mean_tom_consc <- mean(mean_tom_consc)

## add new Consciousness average (across rows from 1-4) to dat

dat$mean_tom_consciousness_for_reg <- rowMeans(dat[,c("Consciousness_1","Consciousness_2","Consciousness_3","Consciousness_4")], na.rm = TRUE)
```
## Personality
```{r}
mean_personality <- mean(dat$personality, na.rm = TRUE)
```
## Human-likeness
```{r}
### Data distributions for histograms + means for regressions
### Notes for scoring
### 1 = fake, not conscious, machinelike, 7 = natural, conscious, humanlike (7 = natural, 1 = fake, e.g.)

############# FAKE----NATURAL
mean_natural <- mean(dat$natural, na.rm = TRUE)

count_natural <- dat %>% filter(!is.na(natural)) %>% group_by(natural) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Create a histogram using the "natural" column from the "dat" dataframe
histogram_humanlikeness_natural <- ggplot(dat, aes(x = natural)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "Fake -> Natural", y = "Count", title = "Humanlikeness: Natural (slider scale)")


############# NOT CONSICOUS----CONSCIOUS
mean_conscious <- mean(dat$Conscious, na.rm = TRUE)

count_conscious <- dat %>% filter(!is.na(Conscious)) %>% group_by(Conscious) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Create a histogram using the "conscious" column from the "dat" dataframe
histogram_humanlikeness_conscious <- ggplot(dat, aes(x = Conscious)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "Not Conscious -> Conscious", y = "Count", title = "Humanlikeness: Conscious (slider scale)")


############# MACHINELIKE----HUMANLIKE
mean_humanlike <- mean(dat$humanlike, na.rm = TRUE)

count_humanlike <- dat %>% filter(!is.na(humanlike)) %>% group_by(humanlike) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)
# mode: 5/7

# Create a histogram using the "humanlike" column from the "dat" dataframe
histogram_humanlikeness_humanlike <- ggplot(dat, aes(x = humanlike)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "Machinelike -> Humanlike", y = "Count", title = "Humanlikeness: Humanlike (slider scale)")


############# ARTIFICIAL----LIFELIKE
mean_lifelike <- mean(dat$lifelike, na.rm = TRUE)

count_lifelike <- dat %>% filter(!is.na(lifelike)) %>% group_by(lifelike) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Create a histogram using the "lifelike" column from the "dat" dataframe
histogram_humanlikeness_lifelike <- ggplot(dat, aes(x = lifelike)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "Artificial -> Lifelike", y = "Count", title = "Humanlikeness: Lifelike (slider scale)")


############# DEAD----ALIVE
mean_alive <- mean(dat$alive, na.rm = TRUE)

count_alive <- dat %>% filter(!is.na(alive)) %>% group_by(alive) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Create a histogram using the "alive" column from the "dat" dataframe
histogram_humanlikeness_alive <- ggplot(dat, aes(x = alive)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "Dead -> Alive", y = "Count", title = "Humanlikeness: Alive (slider scale)")


############# STAGNANT----LIVELY
mean_lively <- mean(dat$lively, na.rm = TRUE)

count_lively <- dat %>% filter(!is.na(lively)) %>% group_by(lively) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Create a histogram using the "lively" column from the "dat" dataframe
histogram_humanlikeness_lively <- ggplot(dat, aes(x = lively)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "Stagnant -> Lively", y = "Count", title = "Humanlikeness: Lively (slider scale)")


############# APATHETIC----RESPONSIVE
mean_responsive <- mean(dat$responsive, na.rm = TRUE)

count_responsive <- dat %>% filter(!is.na(responsive)) %>% group_by(responsive) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Create a histogram using the "responsive" column from the "dat" dataframe
histogram_humanlikeness_responsive <- ggplot(dat, aes(x = responsive)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "Apathetic -> Responsive", y = "Count", title = "Humanlikeness: Responsive (slider scale)")


############# TABLE

human_likeness <- tibble(mean_natural, mean_conscious, mean_humanlike, mean_lifelike, mean_alive, mean_lively, mean_responsive)

## add new Humanlikeness average (across rows from natural to responsive) to dat

dat$mean_human_likeness_for_reg <- rowMeans(dat[,c("natural","Conscious","humanlike","lifelike", "alive", "lively", "responsive")], na.rm = TRUE)
```
## Feelings about Replika advancement
```{r}
## Data distributions for histograms + means

### Notes for scoring
### if_emotions 7 = very comfortable 
### if_livingbeing / dependent 7 = very good

############# if Replika really had emotions, I would feel:
mean_if_emotions <- mean(dat$if_emotions, na.rm = TRUE)

############# if Replika developed into a living being, I think that would be:
mean_if_livingbeing <- mean(dat$if_livingbeing, na.rm = TRUE)

############# if I depended on my Replika a lot, it would be:
mean_if_depended <- mean(dat$if_depended, na.rm = TRUE)

#### table with all 3 means
replika_advancement <- tibble(mean_if_emotions, mean_if_livingbeing, mean_if_depended)
```








# Phase 1 Part 2, Control Comparison group (non-users)



# Load data
```{r}
# import data
dat2 <- read.csv("/location/dat_control.csv", header=TRUE)
```



# Clean stuff up
```{r}
# Rename columns
dat2 <- dat2 %>% rename(Ethnicity = Ethnicity., XP = XP._4, social_health_socialinteractions = Social_health._1, 
                      social_health_relatfamilyfriends = Social_health._2,
                      social_health_selfesteem = Social_health._3,
                      personality = Consciousness_5, natural = Q99_1, 
                      Conscious = Q110_1, humanlike = Q136_1, lifelike = Q103_1,
                      alive = Q104_1, lively = Q105_1, responsive = Q106_1,
                      if_emotions = Q111_1, if_livingbeing = Q112_1,
                      if_depended = Q113_1)

### Make all blanks = NA

dat2 <- data.frame(dat2)
dat2 <- dat2 %>% mutate_all(na_if,"")

### Make all rows except country write-in and free response numeric

numericColumns2 <- names(dat2)
numericColumns2 <- numericColumns2[!(numericColumns2 %in% c("Country", "Race", "Gender", "Country_2_TEXT", "Gender_4_TEXT"))]
dat2[, numericColumns2] <- lapply(dat2[, numericColumns2], as.numeric)
```



# Demographics
```{r}
### Collect demographics and percentages

# Country: USA (1) or OTHER (2) (removing NAs)

demographics_country2 <- dat2 %>% filter(!is.na(Country)) %>% group_by(Country) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Country: what is filled in with OTHER + NA's = USA (minus 7 NA's from not selecting anything)
# ****************do later once I have something
demographics_country_other2 <- dat2 %>% group_by(Country_2_TEXT) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Ethnicity: Hispanic (1) or Not hispanic (2) (removing NAs)

demographics_ethnicity2 <- dat2 %>% filter(!is.na(Ethnicity)) %>% group_by(Ethnicity) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Race: (makes separate categories for multiple races chosen)

demographics_race2 <- dat2 %>% filter(!is.na(Race)) %>% group_by(Race) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# Education: (1) some high school or less, (2) High school diploma or GED, (3) Some college, but no degree, (4) associates or technical degree, (5) Bachelor's degree, (6) Graduate or professional degree, (7) Prefer not to say

demographics_education2 <- dat2 %>% filter(!is.na(Education)) %>% group_by(Education) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# INCOME: (1) less than 25k, (2) 25-49k, (3) 50-74k, (4) 75-99k, (5) 100-149k, (6) 150k+, (7) Prefer not to say

demographics_income2 <- dat2 %>% filter(!is.na(Income)) %>% group_by(Income) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# AGE: (1) 18-24, (2) 25-34, (3) 35-44, (4) 45-54, (5) 55-64, (6) 65+

demographics_age2 <- dat2 %>% filter(!is.na(Age)) %>% group_by(Age) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# GENDER: (1) male, (2) female, (3) non-binary/third gender, (4) prefer to self-describe, (5) Prefer not to say

demographics_gender2 <- dat2 %>% filter(!is.na(Gender)) %>% group_by(Gender) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# RELATIONSHIP STATUS: (1) married, (2) living with a partner, (3) widowed, (4) divorced/separated, (5) never been married

demographics_relationshipstatus2 <- dat2 %>% filter(!is.na(Relationship_status)) %>% group_by(Relationship_status) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)
```


# Data Distributions + Averages

## Social health
```{r}
#################### Social health counts: data distributions + data for histogram visualization 

# social interactions
count_social_health_socialinteractions2 <- dat2 %>% filter(!is.na(social_health_socialinteractions)) %>% group_by(social_health_socialinteractions) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)

# relationships with family and friends
count_social_health_relatfamilyfriends2 <- dat2 %>% filter(!is.na(social_health_relatfamilyfriends)) %>% group_by(social_health_relatfamilyfriends) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)
######## mostly neutral

# self esteem
count_social_health_selfesteem2 <- dat2 %>% filter(!is.na(social_health_selfesteem)) %>% group_by(social_health_selfesteem) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)
######## most found it neutral or slighty helpful

################### Social health means: averages
mean_social_health_socialinteractions2 <- mean(dat2$social_health_socialinteractions, na.rm = TRUE)
mean_social_health_relatfamilyfriends2 <- mean(dat2$social_health_relatfamilyfriends, na.rm = TRUE)
mean_social_health_selfesteem2 <- mean(dat2$social_health_selfesteem, na.rm = TRUE)
### combined (all 3)
mean_social_health_all2 <- ((mean_social_health_relatfamilyfriends2 + mean_social_health_socialinteractions2 + mean_social_health_selfesteem2)/3)

################# TABLE (of mean only, social health counts are different sizes)
social_health_means2 <- tibble(mean_social_health_socialinteractions2, mean_social_health_relatfamilyfriends2,
                            mean_social_health_selfesteem2, mean_social_health_all2)

## add new Social Health average (across rows from 1-3) to main dataframe

dat2$mean_social_health_for_reg <- rowMeans(dat2[,c("social_health_socialinteractions","social_health_relatfamilyfriends","social_health_selfesteem")], na.rm = TRUE)
```
## Theory of Mind: Experience, Agency, and Consciousness
```{r}
### Regression means only, no distributions

##################### Means

############ Experience
##find the mean each of columns Experience_1 to _6
mean_tom_exp2 <- colMeans(dat2[ , c(18:23)], na.rm = TRUE)
## find mean of all columns together
mean_tom_exp2 <- mean(mean_tom_exp2)

## add new Experience average (across rows from 1-6) to dat

dat2$mean_tom_exp_for_reg <- rowMeans(dat2[,c("Experience_1","Experience_2","Experience_3","Experience_4","Experience_5","Experience_6")])

############ Agency
##find the mean each of columns Agency_1 to _5
mean_tom_agency2 <- colMeans(dat2[ , c(29:33)], na.rm = TRUE)
## find mean of all columns together
mean_tom_agency2 <- mean(mean_tom_agency2)

## add new Agency average (across rows from 1-5) to dat

dat2$mean_tom_agency_for_reg <- rowMeans(dat2[,c("Agency_1","Agency_2","Agency_3","Agency_4","Agency_5")])

############ Consciousness
##find the mean each of columns Consciousness_1 to _4
mean_tom_consc2 <- colMeans(dat2[ , c(24:27)], na.rm = TRUE)
## find mean of all columns together
mean_tom_consc2 <- mean(mean_tom_consc2)

## add new Consciousness average (across rows from 1-4) to dat

dat2$mean_tom_consciousness_for_reg <- rowMeans(dat2[,c("Consciousness_1","Consciousness_2","Consciousness_3","Consciousness_4")], na.rm = TRUE)
```
## Personality
```{r}
mean_personality2 <- mean(dat2$personality, na.rm = TRUE)
```
## Human-likeness
```{r}
### Data distributions for histograms + means for regressions

############# FAKE----NATURAL

mean_natural2 <- mean(dat2$natural, na.rm = TRUE)

count_natural2 <- dat2 %>% filter(!is.na(natural)) %>% group_by(natural) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)
# mode: 5/7


############# NOT CONSICOUS----CONSCIOUS
mean_conscious2 <- mean(dat2$Conscious, na.rm = TRUE)

count_conscious2 <- dat2 %>% filter(!is.na(Conscious)) %>% group_by(Conscious) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)
# mode: 2/3 out of 7, then 4/5 out of 7


############# MACHINELIKE----HUMANLIKE

mean_humanlike2 <- mean(dat2$humanlike, na.rm = TRUE)

count_humanlike2 <- dat2 %>% filter(!is.na(humanlike)) %>% group_by(humanlike) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)
# mode: 5/7


############# ARTIFICIAL----LIFELIKE

mean_lifelike2 <- mean(dat2$lifelike, na.rm = TRUE)

count_lifelike2 <- dat2 %>% filter(!is.na(lifelike)) %>% group_by(lifelike) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)


############# DEAD----ALIVE
mean_alive2 <- mean(dat2$alive, na.rm = TRUE)

count_alive2 <- dat2 %>% filter(!is.na(alive)) %>% group_by(alive) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)


############# STAGNANT----LIVELY

mean_lively2 <- mean(dat2$lively, na.rm = TRUE)

count_lively2 <- dat2 %>% filter(!is.na(lively)) %>% group_by(lively) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)


############# APATHETIC----RESPONSIVE
mean_responsive2 <- mean(dat2$responsive, na.rm = TRUE)

count_responsive2 <- dat2 %>% filter(!is.na(responsive)) %>% group_by(responsive) %>% summarise(n = n()) %>% mutate(percent = n / sum(n) * 100)


############# TABLE

human_likeness2 <- tibble(mean_natural2, mean_conscious2, mean_humanlike2, mean_lifelike2, mean_alive2, mean_lively2, mean_responsive2)

## add new Humanlikeness average (across rows from natural to responsive) to dat

dat2$mean_human_likeness_for_reg <- rowMeans(dat2[,c("natural","Conscious","humanlike","lifelike", "alive", "lively", "responsive")], na.rm = TRUE)
```
## Feelings about Replika advancement
```{r}
## Data distributions for histograms + means

############# if Replika really had emotions, I would feel:

mean_if_emotions2 <- mean(dat2$if_emotions, na.rm = TRUE)

############# if Replika developed into a living being, I think that would be:

mean_if_livingbeing2 <- mean(dat2$if_livingbeing, na.rm = TRUE)

############# if I depended on my Replika a lot, it would be:

mean_if_depended2 <- mean(dat2$if_depended, na.rm = TRUE)

replika_advancement2 <- tibble(mean_if_emotions2, mean_if_livingbeing2, mean_if_depended2)
```








# Relationships between variables + Comparisons between groups



# T-tests: Compare social health + replika advancement means between groups Replika and Control
```{r}
# Test significance between Replika and Control groups for:

### social health
#1. Social health - social interactions:
t.test(dat$social_health_socialinteractions, dat2$social_health_socialinteractions)
#2. Social health - relat with family and friends:
t.test(dat$social_health_relatfamilyfriends, dat2$social_health_relatfamilyfriends)
#3. Social health - self-esteem:
t.test(dat$social_health_selfesteem, dat2$social_health_selfesteem)

### thoughts on replika advancement
#1. If replika really had emotions:
t.test(dat$if_emotions, dat2$if_emotions)
#2. If replika developed into living being
t.test(dat$if_livingbeing, dat2$if_livingbeing)
#3. If depended on replika a lot
t.test(dat$if_depended, dat2$if_depended)
```


# Data Regressions (MAIN analyses for both groups)

## Step 1: Make sure scales (ex. all 6 "experience" variables) have internal validity using Cronbach's alpha
### Replika:
```{r}
####### FIRST: see is social health measures correlate, see if experience measures correlate, etc.

################################################### Social health
data_cronbach_alpha <- data.frame(dat$social_health_socialinteractions, dat$social_health_relatfamilyfriends, dat$social_health_selfesteem)

data_cronbach_alpha <- na.omit(data_cronbach_alpha)

cronbach.alpha(data_cronbach_alpha)

################################################## Theory of mind
# Experience
data_cronbach_alpha <- data.frame(dat$Experience_1, dat$Experience_2, dat$Experience_3, dat$Experience_4, dat$Experience_5, dat$Experience_6)

data_cronbach_alpha <- na.omit(data_cronbach_alpha)

cronbach.alpha(data_cronbach_alpha)

# Agency
data_cronbach_alpha <- data.frame(dat$Agency_1, dat$Agency_2, dat$Agency_3, dat$Agency_4, dat$Agency_5)

data_cronbach_alpha <- na.omit(data_cronbach_alpha)

cronbach.alpha(data_cronbach_alpha)

# Consciousness
data_cronbach_alpha <- data.frame(dat$Consciousness_1, dat$Consciousness_2, dat$Consciousness_3, dat$Consciousness_4, dat$Conscious)

data_cronbach_alpha <- na.omit(data_cronbach_alpha)

cronbach.alpha(data_cronbach_alpha)

# All 3 ToM
data_cronbach_alpha <- data.frame(dat$Experience_1, dat$Experience_2, dat$Experience_3, dat$Experience_4, dat$Experience_5, dat$Experience_6, dat$Agency_1, dat$Agency_2, dat$Agency_3, dat$Agency_4, dat$Agency_5, dat$Consciousness_1, dat$Consciousness_2, dat$Consciousness_3, dat$Consciousness_4, dat$Conscious)

data_cronbach_alpha <- na.omit(data_cronbach_alpha)

cronbach.alpha(data_cronbach_alpha)

################################################### Human-likeness
data_cronbach_alpha <- data.frame(dat$natural, dat$humanlike, dat$lifelike, dat$alive, dat$lively, dat$responsive, dat$Conscious)

data_cronbach_alpha <- na.omit(data_cronbach_alpha)

cronbach.alpha(data_cronbach_alpha)
```
### Control:
```{r}
################################################### Social health
data_cronbach_alpha <- data.frame(dat2$social_health_socialinteractions, dat2$social_health_relatfamilyfriends, dat2$social_health_selfesteem)

data_cronbach_alpha <- na.omit(data_cronbach_alpha)

cronbach.alpha(data_cronbach_alpha)

################################################## Theory of mind

# Experience
data_cronbach_alpha <- data.frame(dat2$Experience_1, dat2$Experience_2, dat2$Experience_3, dat2$Experience_4, dat2$Experience_5, dat2$Experience_6)

data_cronbach_alpha <- na.omit(data_cronbach_alpha)

cronbach.alpha(data_cronbach_alpha)

# Agency
data_cronbach_alpha <- data.frame(dat2$Agency_1, dat2$Agency_2, dat2$Agency_3, dat2$Agency_4, dat2$Agency_5)

data_cronbach_alpha <- na.omit(data_cronbach_alpha)

cronbach.alpha(data_cronbach_alpha)

# Consciousness
data_cronbach_alpha <- data.frame(dat2$Consciousness_1, dat2$Consciousness_2, dat2$Consciousness_3, dat2$Consciousness_4, dat2$Conscious)

data_cronbach_alpha <- na.omit(data_cronbach_alpha)

cronbach.alpha(data_cronbach_alpha)

# All 3 ToM
data_cronbach_alpha <- data.frame(dat2$Experience_1, dat2$Experience_2, dat2$Experience_3, dat2$Experience_4, dat2$Experience_5, dat2$Experience_6, dat2$Agency_1, dat2$Agency_2, dat2$Agency_3, dat2$Agency_4, dat2$Agency_5, dat2$Consciousness_1, dat2$Consciousness_2, dat2$Consciousness_3, dat2$Consciousness_4, dat2$Conscious)

data_cronbach_alpha <- na.omit(data_cronbach_alpha)

cronbach.alpha(data_cronbach_alpha)

################################################### Human-likeness

data_cronbach_alpha <- data.frame(dat2$natural, dat2$humanlike, dat2$lifelike, dat2$alive, dat2$lively, dat2$responsive, dat2$Conscious)

data_cronbach_alpha <- na.omit(data_cronbach_alpha)

cronbach.alpha(data_cronbach_alpha)
```

## Step 2: Regressions (Social health + ToM/human-likeness)
### Replika:
```{r}
#### remove one variable at a time from full variable model and see what happens

# full model
model_full <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg + mean_tom_agency_for_reg + mean_tom_consciousness_for_reg + mean_human_likeness_for_reg, data = dat)
summary(model_full)

# without human-likeness
model <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg + mean_tom_agency_for_reg + mean_tom_consciousness_for_reg, data = dat)
summary(model)

# without agency
model <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg  + mean_tom_consciousness_for_reg + mean_human_likeness_for_reg, data = dat)
summary(model)

# without experience
model <- lm(mean_social_health_for_reg ~ mean_tom_agency_for_reg + mean_tom_consciousness_for_reg + mean_human_likeness_for_reg, data = dat)
summary(model)

# without consciousness
model <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg + mean_tom_agency_for_reg + mean_human_likeness_for_reg, data = dat)
summary(model)

######## one variable at a time with social health

# agency
model <- lm(mean_social_health_for_reg ~ mean_tom_agency_for_reg, data = dat)
summary(model)

# experience
model <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg, data = dat)
summary(model)

# consciousness
model <- lm(mean_social_health_for_reg ~ mean_tom_consciousness_for_reg, data = dat)
summary(model)

# human-likeness
model <- lm(mean_social_health_for_reg ~ mean_human_likeness_for_reg, data = dat)
summary(model)

```
### Control:
```{r}
#### remove one variable at a time from full variable model and see what happens

# full model
model_full <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg + mean_tom_agency_for_reg + mean_tom_consciousness_for_reg + mean_human_likeness_for_reg, data = dat2)
summary(model_full)

# without human-likeness
model <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg + mean_tom_agency_for_reg + mean_tom_consciousness_for_reg, data = dat2)
summary(model)

# without agency
model <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg  + mean_tom_consciousness_for_reg + mean_human_likeness_for_reg, data = dat2)
summary(model)

# without experience
model <- lm(mean_social_health_for_reg ~ mean_tom_agency_for_reg + mean_tom_consciousness_for_reg + mean_human_likeness_for_reg, data = dat2)
summary(model)

# without consciousness
model <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg + mean_tom_agency_for_reg + mean_human_likeness_for_reg, data = dat2)
summary(model)

######## one variable at a time with social health

# agency
model <- lm(mean_social_health_for_reg ~ mean_tom_agency_for_reg, data = dat2)
summary(model)

# experience
model <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg, data = dat2)
summary(model)

# consciousness
model <- lm(mean_social_health_for_reg ~ mean_tom_consciousness_for_reg, data = dat2)
summary(model)

# human-likeness
model <- lm(mean_social_health_for_reg ~ mean_human_likeness_for_reg, data = dat2)
summary(model)
```



# Other exploratory tests

# Additional analyses for both groups: duration and intensity with social health
## Replika
```{r}
# Replika

# duration: 0.0922, p = 0.006
model_duration <- lm(mean_social_health_for_reg ~ Duration, data = dat)
summary(model_duration)

# XP: 0.0844, p = 0.018
model_XP <- lm(mean_social_health_for_reg ~ XP, data = dat)
summary(model_XP)

```
## Control
```{r}
# Prolific

# duration: 0.1594, p = 0.00000
model_duration <- lm(mean_social_health_for_reg ~ Duration, data = dat2)
summary(model_duration)

# XP: 0.08329, p = 0.0008
model_XP <- lm(mean_social_health_for_reg ~ XP, data = dat2)
summary(model_XP)

```

## Replika:
### Regress social health outcomes against ToM measures + Human-likeness
```{r}
######## GOAL: regress social health with ToM (to look at whether ToM or consciousness ascription moderates social consequences)

###### VARIABLES to be used for regressions:

# # Social health - all three averaged column
# dat$mean_social_health_for_reg
# # Theory of Mind - Experience averaged column
# dat$mean_tom_exp_for_reg
# # Theory of Mind - Agency averaged column
# dat$mean_tom_agency_for_reg
# # Theory of Mind - Consciousness averaged column
# dat$mean_tom_consciousness_for_reg
# # Humanlikeness
# dat$mean_human_likeness_for_reg

####### REGRESS social health + 3 ToM measures
model_social_health_tom <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg + mean_tom_agency_for_reg + mean_tom_consciousness_for_reg, data = dat)
summary(model_social_health_tom)

###### add in human-likeness
model_social_health_tom_humanlikeness <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg + mean_tom_agency_for_reg + mean_tom_consciousness_for_reg + mean_human_likeness_for_reg, data = dat)
summary(model_social_health_tom_humanlikeness)

####### look at humanlikeness and consciousness with social health
model_social_health_consciousness_humanlikeness <- lm(mean_social_health_for_reg ~ mean_tom_consciousness_for_reg + mean_human_likeness_for_reg, data = dat)
summary(model_social_health_consciousness_humanlikeness)


####### exploratory

###### look at human-likeness and social health alone
model_test_1 <- lm(mean_social_health_for_reg ~ mean_human_likeness_for_reg, data = dat)
summary(model_test_1)

###### look at consciousness and social health alone
model_test_2 <- lm(mean_social_health_for_reg ~ mean_tom_consciousness_for_reg, data = dat)
summary(model_test_2)

###### look at agency and social health alone
model_test_3 <- lm(mean_social_health_for_reg ~ mean_tom_agency_for_reg, data = dat)
summary(model_test_3)

###### look at experience and social health alone
model_test_4 <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg, data = dat)
summary(model_test_4)

###### does humanlikeness predict consciousness?
model_tom_consciousness_human_likeness <- lm(mean_human_likeness_for_reg ~ mean_tom_consciousness_for_reg, data = dat)
summary(model_tom_consciousness_human_likeness)

### does XP predict social health outcomes?
### 1: social health: yes, significant weak correlation
model_social_health_XP <- lm(mean_social_health_for_reg ~ XP, data = dat)
summary(model_social_health_XP)

#### 2: consciousness ascription: not at all
model_tom_consciousness_XP <- lm(XP ~ mean_tom_consciousness_for_reg, data = dat)
summary(model_tom_consciousness_XP)

### how about duration?
### 1: social health: yes, significant weak correlation
model_social_health_duration <- lm(mean_social_health_for_reg ~ Duration, data = dat)
summary(model_social_health_duration)

#### 2: consciousness ascription: not at all
model_tom_consciousness_duration <- lm(Duration ~ mean_tom_consciousness_for_reg, data = dat)
summary(model_tom_consciousness_duration)

### Education on consciousness?
model_tom_consciousness_education <- lm(Education ~ mean_tom_consciousness_for_reg, data = dat)
summary(model_tom_consciousness_education)
```
### Test for differences between groups with demographics on social health
```{r}
###### GENDER

# Run linear regression without gender
model1 <- lm(mean_social_health_for_reg ~ mean_human_likeness_for_reg + mean_tom_consciousness_for_reg, data = dat)
summary(model1)

# Run linear regression with gender
model2 <- lm(mean_social_health_for_reg ~ mean_human_likeness_for_reg + mean_tom_consciousness_for_reg + Gender, data = dat)
summary(model2)

# Perform F-test to compare the two models
anova(model1, model2)


###### explore: do these other demographic variables correlate with social health?

###### let's look at gender alone on social health:
model1 <- lm(mean_social_health_for_reg ~ Gender, data = dat)
summary(model1)

###### let's look at education alone on social health:
model1 <- lm(mean_social_health_for_reg ~ Education, data = dat)
summary(model1)

###### let's look at age alone on social health:
model1 <- lm(mean_social_health_for_reg ~ Age, data = dat)
summary(model1)
```

## Control:
### Regress social health outcomes against ToM measures + Human-likeness
```{r}
###### VARIABLES to be used for regressions:

# # Social health - all three averaged column
# dat2$mean_social_health_for_reg
# 
# 
# # Theory of Mind - Experience averaged column
# dat2$mean_tom_exp_for_reg
# # Theory of Mind - Agency averaged column
# dat2$mean_tom_agency_for_reg
# # Theory of Mind - Consciousness averaged column
# dat2$mean_tom_consciousness_for_reg
# # Humanlikeness
# dat2$mean_human_likeness_for_reg

####### REGRESS
# Fit the linear model
model_social_health_tom2 <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg + mean_tom_agency_for_reg + mean_tom_consciousness_for_reg, data = dat2)

###### however, if you add in humanlikeness, the model becomes more predictive 0.4 

model_social_health_tom_humanlikeness2 <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg + mean_tom_agency_for_reg + mean_tom_consciousness_for_reg + mean_human_likeness_for_reg, data = dat2)
summary(model_social_health_tom_humanlikeness2)

####### to compare to Replika group:

####### look at humanlikeness and consciousness with social health
model_social_health_consciousness_humanlikeness2 <- lm(mean_social_health_for_reg ~ mean_tom_consciousness_for_reg + mean_human_likeness_for_reg, data = dat2)
summary(model_social_health_consciousness_humanlikeness2)
############
### less good model than the other ^

#other pairwise regression tests:


###### look at human-likeness and social health alone
model_test_1 <- lm(mean_social_health_for_reg ~ mean_human_likeness_for_reg, data = dat2)
summary(model_test_1)

###### look at consciousness and social health alone
model_test_2 <- lm(mean_social_health_for_reg ~ mean_tom_consciousness_for_reg, data = dat2)
summary(model_test_2)
###### look at agency and social health alone
model_test_3 <- lm(mean_social_health_for_reg ~ mean_tom_agency_for_reg, data = dat2)
summary(model_test_3)

###### look at experience and social health alone
model_test_4 <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg, data = dat2)
summary(model_test_4)


###### does humanlikeness predict consciousness? Yes - 0.32 v. significant
model_tom_consciousness_human_likeness2 <- lm(mean_human_likeness_for_reg ~ mean_tom_consciousness_for_reg, data = dat2)
summary(model_tom_consciousness_human_likeness)


### does XP predict?
### 1: social health: yes, significant weak correlation
model_social_health_XP2 <- lm(mean_social_health_for_reg ~ XP, data = dat2)
summary(model_social_health_XP)

#### 2: consciousness ascription: YES!
model_tom_consciousness_XP2 <- lm(XP ~ mean_tom_consciousness_for_reg, data = dat2)
summary(model_tom_consciousness_XP)



### how about duration?
### 1: social health: yes, significant correlation
model_social_health_duration2 <- lm(mean_social_health_for_reg ~ Duration, data = dat2)
summary(model_social_health_duration)



#### 2: consciousness ascription: yes, somewhat
model_tom_consciousness_duration2 <- lm(Duration ~ mean_tom_consciousness_for_reg, data = dat2)
summary(model_tom_consciousness_duration)


### Education on consciousness? Nope
model_tom_consciousness_education2 <- lm(Education ~ mean_tom_consciousness_for_reg, data = dat2)
summary(model_tom_consciousness_education)

```
### Test for differences between groups with demographics on social health
```{r}

###### GENDER

# Run linear regression without gender
model1 <- lm(mean_social_health_for_reg ~ mean_human_likeness_for_reg + mean_tom_consciousness_for_reg, data = dat2)
summary(model1)

# Run linear regression with gender
model2 <- lm(mean_social_health_for_reg ~ mean_human_likeness_for_reg + mean_tom_consciousness_for_reg + Gender, data = dat2)
summary(model2)

# Perform F-test to compare the two models
anova(model1, model2)

# not significantly different


###### let's look at gender alone on social health:
model1 <- lm(mean_social_health_for_reg ~ Gender, data = dat2)
summary(model1)
# not significant

```








# Graphs and Histograms


## Histograms


## Social Health histograms
### Replika: Social Health
```{r}
# Create a histogram using the "social_interactions" column from the "dat" dataframe
histogram_social_health_socialinteractions <- ggplot(dat, aes(x = social_health_socialinteractions)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "very harmful -> very helpful", y = "N", title = "Users: impact on social interactions") +
  scale_x_continuous(breaks = 1:7, labels = 1:7, limits = c(0, 8)) +
  scale_y_continuous(limits = c(0, 40), breaks = seq(0, 40, 10)) +
  theme_classic()

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Users_social interactions.png"), width = 7, height = 5, dpi = 300)



# Create a histogram using the "relatfamilyfriends" column from the "dat" dataframe
histogram_social_health_relatfamilyfriends <- ggplot(dat, aes(x = social_health_relatfamilyfriends)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "very harmful -> very helpful", y = "N", title = "Users: impact on relationship with family and friends") +
   scale_x_continuous(breaks = 1:7, labels = 1:7, limits = c(0, 8)) +
  scale_y_continuous(limits = c(0, 40), breaks = seq(0, 40, 10)) +
  theme_classic()

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Impact on relationship with family and friends.png"), width = 7, height = 5, dpi = 300)





# Create a histogram using the "social_health_selfesteem" column from the "dat" dataframe
histogram_social_health_selfesteem <- ggplot(dat, aes(x = social_health_selfesteem)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "very harmful -> very helpful", y = "N", title = "Users: impact on self-esteem") +
  scale_x_continuous(breaks = 1:7, labels = 1:7, limits = c(0, 8)) +
  scale_y_continuous(limits = c(0, 40), breaks = seq(0, 40, 10)) +
  theme_classic()

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Impact on self-esteem.png"), width = 7, height = 5, dpi = 300)

```
### Control: Social Health
```{r}
# # Create a histogram using the "social_interactions" column from the "dat2" dataframe
histogram_social_health_socialinteractions2 <- ggplot(dat2, aes(x = social_health_socialinteractions)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "very harmful -> very helpful", y = "N", title = "Control: impact on social interactions") +
  scale_x_continuous(breaks = 1:7, labels = 1:7, limits = c(0, 8)) +
  scale_y_continuous(limits = c(0, 70), breaks = seq(0, 70, 10)) +
  theme_classic()

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Control_social interactions.png"), width = 7, height = 5, dpi = 300)




# Create a histogram using the "social_health_relatfamilyfriends" column from the "dat2" dataframe
histogram_social_health_relatfamilyfriends2 <- ggplot(dat2, aes(x = social_health_relatfamilyfriends)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "very harmful -> very helpful", y = "N", title = "Control: impact on relationships with family and friends") +
  scale_x_continuous(breaks = 1:7, labels = 1:7, limits = c(0, 8)) +
  scale_y_continuous(limits = c(0, 70), breaks = seq(0, 70, 10)) +
  theme_classic()

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Impact on relationships with family and friends.png"), width = 7, height = 5, dpi = 300)





# Create a histogram using the "social_health_selfesteem" column from the "dat2" dataframe
histogram_social_health_selfesteem2 <- ggplot(dat2, aes(x = social_health_selfesteem)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "very harmful -> very helpful", y = "N", title = "Control: impact on self-esteem") +
  scale_x_continuous(breaks = 1:7, labels = 1:7, limits = c(0, 8)) +
  scale_y_continuous(limits = c(0, 70), breaks = seq(0, 70, 10)) +
  theme_classic()

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Impact on self-esteem.png"), width = 7, height = 5, dpi = 300)


```
### Put social health histograms for both groups into a single image
```{r}
# Combine histograms into two rows
row1 <- grid.arrange(histogram_social_health_socialinteractions, 
                     histogram_social_health_relatfamilyfriends, 
                     histogram_social_health_selfesteem, 
                     ncol = 3)

row2 <- grid.arrange(histogram_social_health_socialinteractions2, 
                     histogram_social_health_relatfamilyfriends2, 
                     histogram_social_health_selfesteem2, 
                     ncol = 3)

# Combine rows into a single image file
final_plot <- grid.arrange(row1, row2, nrow = 2)

# Save the image to desktop
ggsave(file.path("~/Desktop/histograms.png"), final_plot, width = 10, height = 8, dpi = 300)

```

## Replika advancement histograms
### Replika
```{r}
# Create a histogram using the "if_emotions" column from the "dat" dataframe
histogram_if_emotions <- ggplot(dat, aes(x = if_emotions)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "Very uncomfortable -> Very comfortable", y = "N", title = "If Replika really had emotions, I would feel:") +
  scale_x_continuous(breaks = 1:7, labels = 1:7, limits = c(0, 8)) +
  scale_y_continuous(limits = c(0, 30), breaks = seq(0, 30, 10)) +
  theme_classic()

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_If Replika really had emotions, I would feel.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "if_livingbeing" column from the "dat" dataframe
histogram_if_livingbeing <- ggplot(dat, aes(x = if_livingbeing)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "Very bad -> Very good", y = "N", title = "If Replika developed into a living being, I think that would be:")+
  scale_x_continuous(breaks = 1:7, labels = 1:7, limits = c(0, 8)) +
  scale_y_continuous(limits = c(0, 30), breaks = seq(0, 30, 10)) +
  theme_classic()

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_If Replika developed into a living being, I think that would be.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "if_depended" column from the "dat" dataframe
histogram_if_depended <- ggplot(dat, aes(x = if_depended)) +
  geom_histogram(binwidth = 1, color = "black", fill = "lightblue") +
  labs(x = "Very bad -> Very good", y = "N", title = "If I depended on my Replika a lot, it would be:")+
  scale_x_continuous(breaks = 1:7, labels = 1:7, limits = c(0, 8)) +
  scale_y_continuous(limits = c(0, 30), breaks = seq(0, 30, 10)) +
  theme_classic()

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_If I depended on my Replika a lot, it would be.png"), width = 7, height = 5, dpi = 300)
```
### Control
```{r}
# Create a histogram using the "if_emotions" column from the "dat2" dataframe
histogram_if_emotions2 <- ggplot(dat2, aes(x = if_emotions)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Very uncomfortable -> Very comfortable", y = "N", title = "If Replika really had emotions, I would feel:")+
  scale_x_continuous(breaks = 1:7, labels = 1:7, limits = c(0, 8)) +
  scale_y_continuous(limits = c(0, 40), breaks = seq(0, 40, 10)) +
  theme_classic()

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_If Replika really had emotions, I would feel.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "if_livingbeing" column from the "dat2" dataframe
histogram_if_livingbeing2 <- ggplot(dat2, aes(x = if_livingbeing)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Very bad -> Very good", y = "N", title = "If Replika developed into a living being, I think that would be:")+
  scale_x_continuous(breaks = 1:7, labels = 1:7, limits = c(0, 8)) +
  scale_y_continuous(limits = c(0, 50), breaks = seq(0, 50, 10)) +
  theme_classic()

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_If Replika developed into a living being, I think that would be:.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "if_depended" column from the "dat2" dataframe
histogram_if_depended2 <- ggplot(dat2, aes(x = if_depended)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Very bad -> Very good", y = "N", title = "If I depended on my Replika a lot, it would be:")+
  scale_x_continuous(breaks = 1:7, labels = 1:7, limits = c(0, 8)) +
  scale_y_continuous(limits = c(0, 50), breaks = seq(0, 50, 10)) +
  theme_classic()

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_If I depended on my Replika a lot, it would be.png"), width = 7, height = 5, dpi = 300)
```
### PutReplika advancement histograms for both groups into a single image
```{r}
# Combine histograms into two rows
part1 <- grid.arrange(histogram_if_emotions, 
                     histogram_if_livingbeing, 
                    histogram_if_depended, 
                     ncol = 3)

part2 <- grid.arrange(histogram_if_emotions2, 
                     histogram_if_livingbeing2, 
                    histogram_if_depended2, 
                     ncol = 3)

# Combine rows into a single image file
replikaadvancement_plot <- grid.arrange(part1, part2, nrow = 2)

# Save the image to desktop
ggsave(file.path("~/Desktop/replikaadvancement_histograms.png"), replikaadvancement_plot, width = 10, height = 8, dpi = 300)
```

## Theory of Mind histograms
## Replika
```{r}
# Create a histogram using the "mean_tom_exp_for_reg" column from the "dat" dataframe
histogram_mean_tom_exp_for_reg <- ggplot(dat, aes(x = mean_tom_exp_for_reg)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Experience", y = "Count", title = "Experience")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Experience.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "mean_tom_agency_for_reg" column from the "dat" dataframe
histogram_mean_tom_agency_for_reg <- ggplot(dat, aes(x = mean_tom_agency_for_reg)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Agency", y = "Count", title = "Agency")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Agency.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "mean_tom_consciousness_for_reg" column from the "dat" dataframe
histogram_mean_tom_consciousness_for_reg <- ggplot(dat, aes(x = mean_tom_consciousness_for_reg)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Consciousness", y = "Count", title = "Consciousness")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Consciousness.png"), width = 7, height = 5, dpi = 300)
```
## Control
```{r}
# Create a histogram using the "mean_tom_exp_for_reg" column from the "dat2" dataframe
histogram_mean_tom_exp_for_reg2 <- ggplot(dat2, aes(x = mean_tom_exp_for_reg)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Experience", y = "Count", title = "Experience")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Experience.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "mean_tom_agency_for_reg" column from the "dat2" dataframe
histogram_mean_tom_agency_for_reg2 <- ggplot(dat2, aes(x = mean_tom_agency_for_reg)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Agency", y = "Count", title = "Agency")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Agency.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "mean_tom_consciousness_for_reg" column from the "dat2" dataframe
histogram_mean_tom_consciousness_for_reg2 <- ggplot(dat2, aes(x = mean_tom_consciousness_for_reg)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Consciousness", y = "Count", title = "Consciousness")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Consciousness.png"), width = 7, height = 5, dpi = 300)
```

## Human-Likeness histograms
## Replika
```{r}
# Create a histogram using the "natural" column from the "dat" dataframe
histogram_humanlikeness_natural <- ggplot(dat, aes(x = natural)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Fake -> Natural", y = "N", title = "Humanlikeness: Natural")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Humanlikeness: Natural.png"), width = 7, height = 5, dpi = 300)



# Create a histogram using the "conscious" column from the "dat" dataframe
histogram_humanlikeness_conscious <- ggplot(dat, aes(x = Conscious)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Not Conscious -> Conscious", y = "Count", title = "Humanlikeness: Conscious")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Humanlikeness: Conscious.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "humanlike" column from the "dat" dataframe
histogram_humanlikeness_humanlike <- ggplot(dat, aes(x = humanlike)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Machinelike -> Humanlike", y = "Count", title = "Humanlikeness: Humanlike")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Humanlikeness: Humanlike.png"), width = 7, height = 5, dpi = 300)



# Create a histogram using the "lifelike" column from the "dat" dataframe
histogram_humanlikeness_lifelike <- ggplot(dat, aes(x = lifelike)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Artificial -> Lifelike", y = "Count", title = "Humanlikeness: Lifelike")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Humanlikeness: Lifelike.png"), width = 7, height = 5, dpi = 300)



# Create a histogram using the "alive" column from the "dat" dataframe
histogram_humanlikeness_alive <- ggplot(dat, aes(x = alive)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Dead -> Alive", y = "Count", title = "Humanlikeness: Alive")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Humanlikeness: Alive.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "lively" column from the "dat" dataframe
histogram_humanlikeness_lively <- ggplot(dat, aes(x = lively)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Stagnant -> Lively", y = "Count", title = "Humanlikeness: Lively")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Humanlikeness: Lively.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "responsive" column from the "dat" dataframe
histogram_humanlikeness_responsive <- ggplot(dat, aes(x = responsive)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Apathetic -> Responsive", y = "Count", title = "Humanlikeness: Responsive")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Humanlikeness: Responsive.png"), width = 7, height = 5, dpi = 300)
```
## Control
```{r}
# Create a histogram using the "natural" column from the "dat2" dataframe
histogram_humanlikeness_natural2 <- ggplot(dat2, aes(x = natural)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Fake -> Natural", y = "N", title = "Humanlikeness: Natural")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Humanlikeness: Natural.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "conscious" column from the "dat2" dataframe
histogram_humanlikeness_conscious2 <- ggplot(dat2, aes(x = Conscious)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Not Conscious -> Conscious", y = "Count", title = "Humanlikeness: Conscious")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Humanlikeness: Conscious.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "humanlike" column from the "dat2" dataframe
histogram_humanlikeness_humanlike2 <- ggplot(dat2, aes(x = humanlike)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Machinelike -> Humanlike", y = "Count", title = "Humanlikeness: Humanlike")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Humanlikeness: Humanlike.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "lifelike" column from the "dat2" dataframe
histogram_humanlikeness_lifelike2 <- ggplot(dat2, aes(x = lifelike)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Artificial -> Lifelike", y = "Count", title = "Humanlikeness: Lifelike")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Humanlikeness: Lifelike.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "alive" column from the "dat2" dataframe
histogram_humanlikeness_alive2 <- ggplot(dat2, aes(x = alive)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Dead -> Alive", y = "Count", title = "Humanlikeness: Alive")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Humanlikeness: Alive.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "lively" column from the "dat2" dataframe
histogram_humanlikeness_lively2 <- ggplot(dat2, aes(x = lively)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Stagnant -> Lively", y = "Count", title = "Humanlikeness: Lively")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Humanlikeness: Lively.png"), width = 7, height = 5, dpi = 300)


# Create a histogram using the "responsive" column from the "dat2" dataframe
histogram_humanlikeness_responsive2 <- ggplot(dat2, aes(x = responsive)) +
  geom_histogram(binwidth = 1, color = "black", fill = "gray") +
  labs(x = "Apathetic -> Responsive", y = "Count", title = "Humanlikeness: Responsive")

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Humanlikeness: Responsive.png"), width = 7, height = 5, dpi = 300)
```



## MAIN regression plots
### Replika: each piece regressed with social health
```{r}
#### copied from MAIN regression part

# agency
model <- lm(mean_social_health_for_reg ~ mean_tom_agency_for_reg, data = dat)

#create scatter plot (this code doubles the size of the dots on plot and doubles size of tick mark labels)
graph <- ggplot(data = dat, aes(x = mean_tom_agency_for_reg)) +
  geom_point(aes(y = mean_social_health_for_reg), color = "dark gray", size = 4) +   # Add scatter plot for y1
  geom_smooth(aes(y = mean_social_health_for_reg), color = "black", method = "lm") +  # Add linear regression line for y1
  scale_x_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  scale_y_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  theme_classic() +
  theme(axis.text = element_text(size = 36)) +
  labs(x = NULL, y = NULL) +
  guides(color = FALSE)

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_social health and agency regression.png"), width = 7, height = 5, dpi = 300)


# experience
model <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg, data = dat)

#create scatter plot (this code doubles the size of the dots on plot and doubles size of tick mark labels)
graph <- ggplot(data = dat, aes(x = mean_tom_exp_for_reg)) +
  geom_point(aes(y = mean_social_health_for_reg), color = "dark gray", size = 4) +   # Add scatter plot for y1
  geom_smooth(aes(y = mean_social_health_for_reg), color = "black", method = "lm") +  # Add linear regression line for y1
  scale_x_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  scale_y_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  theme_classic() +
  theme(axis.text = element_text(size = 36)) +
  labs(x = NULL, y = NULL) +
  guides(color = FALSE)

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_social health and experience regression.png"), width = 7, height = 5, dpi = 300)


# consciousness
model <- lm(mean_social_health_for_reg ~ mean_tom_consciousness_for_reg, data = dat)
summary(model)

#create scatter plot (this code doubles the size of the dots on plot and doubles size of tick mark labels)
graph <- ggplot(data = dat, aes(x = mean_tom_consciousness_for_reg)) +
  geom_point(aes(y = mean_social_health_for_reg), color = "dark gray", size = 4) +   # Add scatter plot for y1
  geom_smooth(aes(y = mean_social_health_for_reg), color = "black", method = "lm") +  # Add linear regression line for y1
  scale_x_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  scale_y_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  theme_classic() +
  theme(axis.text = element_text(size = 36)) +
  labs(x = NULL, y = NULL) +
  guides(color = FALSE)

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_social health and Consciousness regression.png"), width = 7, height = 5, dpi = 300)


# human-likeness
model <- lm(mean_social_health_for_reg ~ mean_human_likeness_for_reg, data = dat)
summary(model)

#create scatter plot (this code doubles the size of the dots on plot and doubles size of tick mark labels)
graph <- ggplot(data = dat, aes(x = mean_human_likeness_for_reg)) +
  geom_point(aes(y = mean_social_health_for_reg), color = "dark gray", size = 4) +   # Add scatter plot for y1
  geom_smooth(aes(y = mean_social_health_for_reg), color = "black", method = "lm") +  # Add linear regression line for y1
  scale_x_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  scale_y_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  theme_classic() +
  theme(axis.text = element_text(size = 36)) +
  labs(x = NULL, y = NULL) +
  guides(color = FALSE)

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_social health and humanlikeness regression.png"), width = 7, height = 5, dpi = 300)
```
### Prolific: each piece regressed with social health
```{r}
# agency
model <- lm(mean_social_health_for_reg ~ mean_tom_agency_for_reg, data = dat2)

#create scatter plot (this code doubles the size of the dots on plot and doubles size of tick mark labels)
graph <- ggplot(data = dat2, aes(x = mean_tom_agency_for_reg)) +
  geom_point(aes(y = mean_social_health_for_reg), color = "dark gray", size = 4) +   # Add scatter plot for y1
  geom_smooth(aes(y = mean_social_health_for_reg), color = "black", method = "lm") +  # Add linear regression line for y1
  scale_x_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  scale_y_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  theme_classic() +
  theme(axis.text = element_text(size = 36)) +
  labs(x = NULL, y = NULL) +
  guides(color = FALSE)

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_social health and agency regression.png"), width = 7, height = 5, dpi = 300)


# experience
model <- lm(mean_social_health_for_reg ~ mean_tom_exp_for_reg, data = dat2)

#create scatter plot (this code doubles the size of the dots on plot and doubles size of tick mark labels)
graph <- ggplot(data = dat2, aes(x = mean_tom_exp_for_reg)) +
  geom_point(aes(y = mean_social_health_for_reg), color = "dark gray", size = 4) +   # Add scatter plot for y1
  geom_smooth(aes(y = mean_social_health_for_reg), color = "black", method = "lm") +  # Add linear regression line for y1
  scale_x_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  scale_y_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  theme_classic() +
  theme(axis.text = element_text(size = 36)) +
  labs(x = NULL, y = NULL) +
  guides(color = FALSE)

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_social health and experience regression.png"), width = 7, height = 5, dpi = 300)


# consciousness
model <- lm(mean_social_health_for_reg ~ mean_tom_consciousness_for_reg, data = dat2)
summary(model)

#create scatter plot (this code doubles the size of the dots on plot and doubles size of tick mark labels)
graph <- ggplot(data = dat2, aes(x = mean_tom_consciousness_for_reg)) +
  geom_point(aes(y = mean_social_health_for_reg), color = "dark gray", size = 4) +   # Add scatter plot for y1
  geom_smooth(aes(y = mean_social_health_for_reg), color = "black", method = "lm") +  # Add linear regression line for y1
  scale_x_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  scale_y_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  theme_classic() +
  theme(axis.text = element_text(size = 36)) +
  labs(x = NULL, y = NULL) +
  guides(color = FALSE)

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_social health and Consciousness regression.png"), width = 7, height = 5, dpi = 300)


# human-likeness
model <- lm(mean_social_health_for_reg ~ mean_human_likeness_for_reg, data = dat2)
summary(model)

#create scatter plot (this code doubles the size of the dots on plot and doubles size of tick mark labels)
graph <- ggplot(data = dat2, aes(x = mean_human_likeness_for_reg)) +
  geom_point(aes(y = mean_social_health_for_reg), color = "dark gray", size = 4) +   # Add scatter plot for y1
  geom_smooth(aes(y = mean_social_health_for_reg), color = "black", method = "lm") +  # Add linear regression line for y1
  scale_x_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  scale_y_continuous(limits = c(1, 7), breaks = c(1, 4, 7), 
                     expand = c(0.02, 0)) +
  theme_classic() +
  theme(axis.text = element_text(size = 36)) +
  labs(x = NULL, y = NULL) +
  guides(color = FALSE)

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_social health and humanlikeness regression.png"), width = 7, height = 5, dpi = 300)
```



## Full model (exploratory) regression plots
## Replika
```{r}
### Regression model for social health +TOM

# Get the adjusted R-squared value from the model summary
adj_r_squared <- round(summary(model_social_health_tom)$adj.r.squared, 2)

# Create plot for model: social health on TOM
graph_regression_social_health_tom <- ggplot(data = dat, aes(x = mean_social_health_for_reg)) +
  geom_point(aes(y = mean_tom_exp_for_reg, color = "Experience")) +
  geom_point(aes(y = mean_tom_agency_for_reg, color = "Agency")) +
  geom_point(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness")) +
  geom_smooth(aes(y = mean_tom_exp_for_reg, color = "Experience"), method = "lm", fullrange = TRUE) +
  geom_smooth(aes(y = mean_tom_agency_for_reg, color = "Agency"), method = "lm", fullrange = TRUE) +
  geom_smooth(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness"), method = "lm", fullrange = TRUE) +
  labs(x = "Social health", y = "Mind perception",
       title = "Mind Perception moderates social health outcomes",
       subtitle = paste0("Adjusted R-squared = ",
                         round(summary(model_social_health_tom)$adj.r.squared, 2))) +
  scale_color_manual(values = c("Experience" = "red", "Agency" = "blue", "Consciousness" = "green")) +
  scale_x_continuous(limits = c(0, 8), expand = c(0, 0), breaks = c(1, 4, 7)) +
  scale_y_continuous(limits = c(0, 8), breaks = c(1, 4, 7), expand = c(0, 0))

# Save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Mind perception moderates social health outcomes.png"), width = 7, height = 5, dpi = 300)


#### Regression plot for social health + TOM + humanlikeness
# Get the adjusted R-squared value from the model summary
adj_r_squared <- round(summary(model_social_health_tom_humanlikeness)$adj.r.squared, 2)

# Create plot for model: social health on TOM
graph_regression_social_health_tom_humanlikeness <- ggplot(data = dat, aes(x = mean_social_health_for_reg)) +
  geom_point(aes(y = mean_tom_exp_for_reg, color = "Experience")) +
  geom_point(aes(y = mean_tom_agency_for_reg, color = "Agency")) +
  geom_point(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness")) +
    geom_point(aes(y = mean_human_likeness_for_reg, color = "Human-likeness")) +
  geom_smooth(aes(y = mean_tom_exp_for_reg, color = "Experience"), method = "lm", fullrange = TRUE) +
  geom_smooth(aes(y = mean_tom_agency_for_reg, color = "Agency"), method = "lm", fullrange = TRUE) +
  geom_smooth(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness"), method = "lm", fullrange = TRUE) +
  geom_smooth(aes(y = mean_human_likeness_for_reg, color = "Human-likeness"), method = "lm", fullrange = TRUE) +
  labs(x = "Social health", y = "Mind perception",
       title = "Mind perception + Human-likeness moderate social health benefits",
       subtitle = paste0("Adjusted R-squared = ",
                         round(summary(model_social_health_tom_humanlikeness)$adj.r.squared, 2))) +
  scale_color_manual(values = c("Experience" = "red", "Agency" = "blue", "Consciousness" = "green", "Human-likeness" = "orange")) + scale_x_continuous(limits = c(0, 8), expand = c(0, 0), breaks = c(1, 4, 7)) +
  scale_y_continuous(limits = c(0, 8), breaks = c(1, 4, 7), expand = c(0, 0))

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Mind perception + Humanlikeness moderate social health benefits.png"), width = 7, height = 5, dpi = 300)


#### Consciousness and humanlikeness moderate social health benefits

# Create a scatter plot with a linear regression line for two y variables
graph_regression_social_health_tom <- ggplot(data = dat, aes(x = mean_social_health_for_reg)) +
  geom_point(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness")) +   # Add scatter plot for y1
   geom_point(aes(y = mean_human_likeness_for_reg, color = "Human-likeness")) +   # Add scatter plot for y2
  geom_smooth(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness"), method = "lm") +  # Add linear regression line for y1
  geom_smooth(aes(y = mean_human_likeness_for_reg, color = "Human-likeness"), method = "lm") + # Add linear regression line for y2
  labs(x = "Social health", y = "Consciousness & Human-likeness",
       title = "Consciousness + Humanlikeness moderate social health benefits") +
  scale_color_manual(values = c("Human-likeness" = "orange", "Consciousness" = "green")) # Add custom color scheme

# save plot to Desktop 
ggsave(file.path("~/Desktop/p1_Consciousness + Human-likeness moderate social health benefits.png"), width = 7, height = 5, dpi = 300)


##### Humanlikness predicts Consciousness

# Create a scatter plot with a linear regression line
graph_regression_humanlikeness_consciousness <- ggplot(data = dat, aes(x = mean_human_likeness_for_reg)) +
  geom_point(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness")) +  # Add scatter plot for y1
  geom_smooth(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness"), method = "lm") +  # Add linear regression line for y1
  labs(x = "Human-likeness", y = "Consciousness",
       title = "Human-likeness moderates Consciousness-Perception") +
  scale_color_manual(values = c("Consciousness" = "green")) # Add custom color scheme

ggsave(file.path("~/Desktop/Human-likeness moderates Consciousness-Perception.png"), width = 7, height = 5, dpi = 300)
```
## Control
```{r}
### create plot for model: social health on TOM

# Get the adjusted R-squared value from the model summary
adj_r_squared2 <- round(summary(model_social_health_tom2)$adj.r.squared, 2)

# Create plot for model: social health on TOM
graph_regression_social_health_tom2 <- ggplot(data = dat2, aes(x = mean_social_health_for_reg)) +
  geom_point(aes(y = mean_tom_exp_for_reg, color = "Experience")) +
  geom_point(aes(y = mean_tom_agency_for_reg, color = "Agency")) +
  geom_point(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness")) +
  geom_smooth(aes(y = mean_tom_exp_for_reg, color = "Experience"), method = "lm", fullrange = TRUE) +
  geom_smooth(aes(y = mean_tom_agency_for_reg, color = "Agency"), method = "lm", fullrange = TRUE) +
  geom_smooth(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness"), method = "lm", fullrange = TRUE) +
  labs(x = "Social health", y = "Mind perception",
       title = "Mind Perception moderates social health outcomes",
       subtitle = paste0("Adjusted R-squared = ",
                         round(summary(model_social_health_tom2)$adj.r.squared, 2))) +
  scale_color_manual(values = c("Experience" = "red", "Agency" = "blue", "Consciousness" = "green")) +
  scale_x_continuous(limits = c(0, 8), expand = c(0, 0), breaks = c(1, 4, 7)) +
  scale_y_continuous(limits = c(0, 8), breaks = c(1, 4, 7), expand = c(0, 0))

# Save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Mind perception moderates social health outcomes.png"), width = 7, height = 5, dpi = 300)


#### Regression plot for social health + TOM + humanlikeness
# Get the adjusted R-squared value from the model summary
adj_r_squared <- round(summary(model_social_health_tom_humanlikeness2)$adj.r.squared, 2)

# Create plot for model: social health on TOM
graph_regression_social_health_tom_humanlikeness2 <- ggplot(data = dat2, aes(x = mean_social_health_for_reg)) +
  geom_point(aes(y = mean_tom_exp_for_reg, color = "Experience")) +
  geom_point(aes(y = mean_tom_agency_for_reg, color = "Agency")) +
  geom_point(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness")) +
    geom_point(aes(y = mean_human_likeness_for_reg, color = "Human-likeness")) +
  geom_smooth(aes(y = mean_tom_exp_for_reg, color = "Experience"), method = "lm", fullrange = TRUE) +
  geom_smooth(aes(y = mean_tom_agency_for_reg, color = "Agency"), method = "lm", fullrange = TRUE) +
  geom_smooth(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness"), method = "lm", fullrange = TRUE) +
  geom_smooth(aes(y = mean_human_likeness_for_reg, color = "Human-likeness"), method = "lm", fullrange = TRUE) +
  labs(x = "Social health", y = "Mind perception",
       title = "Mind perception + Human-likeness moderate social health benefits",
       subtitle = paste0("Adjusted R-squared = ",
                         round(summary(model_social_health_tom_humanlikeness2)$adj.r.squared, 2))) +
  scale_color_manual(values = c("Experience" = "red", "Agency" = "blue", "Consciousness" = "green", "Human-likeness" = "orange")) + scale_x_continuous(limits = c(0, 8), expand = c(0, 0), breaks = c(1, 4, 7)) +
  scale_y_continuous(limits = c(0, 8), breaks = c(1, 4, 7), expand = c(0, 0))

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Mind perception + Humanlikeness moderate social health benefits.png"), width = 7, height = 5, dpi = 300)


###### other plots:

#### social health + consciousness/humanlikeness
# Create a scatter plot with a linear regression line for two y variables
graph_regression_social_health_humanlikeness_consciousness <- ggplot(data = dat2, aes(x = mean_social_health_for_reg)) +
  geom_point(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness")) +   # Add scatter plot for y1
  geom_point(aes(y = mean_human_likeness_for_reg, color = "Human-likeness")) +   # Add scatter plot for y2
  geom_smooth(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness"), method = "lm") +  # Add linear regression line for y1
  geom_smooth(aes(y = mean_human_likeness_for_reg, color = "Human-likeness"), method = "lm") + # Add linear regression line for y2
  labs(x = "Social health", y = "Consciousness & Human-likeness",
       title = "Consciousness + Humanlikeness moderate social health benefits") +
  scale_color_manual(values = c("Human-likeness" = "orange", "Consciousness" = "green")) # Add custom color scheme

# save plot to Desktop 
ggsave(file.path("~/Desktop/p2_Consciousness + Human-likeness moderate social health benefits.png"), width = 7, height = 5, dpi = 300)


##### Humanlikeness predicts Consciousness graph

# Create a scatter plot with a linear regression line
graph_regression_humanlikeness_consciousness <- ggplot(data = dat2, aes(x = mean_human_likeness_for_reg)) +
  geom_point(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness")) +  # Add scatter plot for y1
  geom_smooth(aes(y = mean_tom_consciousness_for_reg, color = "Consciousness"), method = "lm") +  # Add linear regression line for y1
  labs(x = "Human-likeness", y = "Consciousness",
       title = "Human-likeness moderates Consciousness-Perception") +
  scale_color_manual(values = c("Consciousness" = "green")) # Add custom color scheme

ggsave(file.path("~/Desktop/p2_Human-likeness moderates Consciousness-Perception.png"), width = 7, height = 5, dpi = 300)
```
### Put all 4 full regression plots together:
```{r}
#Replika and Prolific, respectively, with social health + TOM:
graph_regression_social_health_tom
graph_regression_social_health_tom2

#Replika and Prolific, respectively, with social health + TOM + Human-likeness:
graph_regression_social_health_tom_humanlikeness
graph_regression_social_health_tom_humanlikeness2


# Combine histograms into two rows
part1 <- grid.arrange(graph_regression_social_health_tom, 
                     graph_regression_social_health_tom_humanlikeness,
                     ncol = 2)

part2 <- grid.arrange(graph_regression_social_health_tom2, 
                     graph_regression_social_health_tom_humanlikeness2,
                     ncol = 2)

# Combine rows into a single image file
regressions_all_plot <- grid.arrange(part1, part2, nrow = 2)

# Save the image to desktop
ggsave(file.path("~/Desktop/regressions_all.png"), regressions_all_plot, width = 10, height = 8, dpi = 300)

```









# END OF CODE











