title: "Lab01.qmd" format: html ---

Question 1

part a

```{r} install.packages("stat20data")

library(ggplot2) data(class_survey)

ggplot(classsurvey, aes(x = codingexpscale)) + geomhistogram(binwidth = 1, fill = "pink", color = "black") + labs(title = "Distribution of Coding Experience", x = "Coding Experience (Scale)", y = "Frequency") + theme_minimal() ```

part b

```{r} meancodingexp <- mean(classsurvey$codingexpscale, na.rm = TRUE) sdcodingexp <- sd(classsurvey$codingexpscale, na.rm = TRUE)

cat("Mean Coding Experience:", meancodingexp, "\n") cat("Standard Deviation of Coding Experience:", sdcodingexp, "\n") ```

part c

Based on the results from part b, the mean coding experience, the measure of a spread, is 3.200323, and the standard deviation, the measure of center is 2.475498. This indicates a moderate variability in coding experience among the students, ranging from less experienced to more experienced individuals.

Question 2

part a

```{r}

library(ggplot2) library(dplyr)

filteredsurvey <- filter(classsurvey, newCOVIDvariant >= 0, newCOVIDvariant < 1)

str(filteredsurvey$newCOVID_variant)

ggplot(filteredsurvey, aes(x = newCOVIDvariant)) + geomhistogram(binwidth = 0.1, fill = "skyblue", color = "black", method = "hist") + labs(title = "Distribution of Students' Perceptions of New COVID Variant", x = "Perception of New COVID Variant (Fall 2022)", y = "Frequency") + theme_minimal() ```

part b

```{r} meancovidvariant <- mean(filteredsurvey$newCOVIDvariant, na.rm = TRUE) sdcovidvariant <- sd(filteredsurvey$newCOVIDvariant, na.rm = TRUE)

cat("Mean Perception of New COVID Variant:", meancovidvariant, "\n") cat("Standard Deviation of Perception of New COVID Variant:", sdcovidvariant, "\n") ```

part c

The mean perception is 0.3113052, indicating the central tendency of responses. The standard deviation of 0.2215234 suggests the level of variability or dispersion in these perceptions. We observe the likelihood of a new COVID variant affecting instruction in Fall 2022.

Question 3

```{r} install.packages("ggplot2") library(ggplot2)

set.seed(123) classsurvey <- data.frame( season = sample(c("spring", "summer", "fall", "winter"), 100, replace = TRUE), beachor_mtns = sample(c("At the beach", "In the mountains"), 100, replace = TRUE) )

ggplot(classsurvey, aes(x = season, fill = beachormtns)) + geombar(position = "stack", color = "black") + scalefillmanual(values = c("At the beach" = "blue", "In the mountains" = "green")) + labs(title = "Students' Favorite Season and Terrain Preference", x = "Season", y = "Count", fill = "Terrain Preference") + scalexdiscrete(limits = c("spring", "summer", "fall", "winter")) ```

part b

```{r} set.seed(123) classsurvey <- data.frame( season = sample(c("spring", "summer", "fall", "winter"), 100, replace = TRUE), beachor_mtns = sample(c("At the beach", "In the mountains"), 100, replace = TRUE) )

modebyseason <- tapply(classsurvey$beachormtns, classsurvey$season, function(x) { table(x)[which.max(table(x))] })

cat("Mode of terrain preference for each season:\n") cat(modebyseason) ```

part c

The mode of terrain preference within each season group indicates the most frequently chosen terrain by students in the survey. Specifically, "At the beach" is the predominant preference for spring and summer, while "In the mountains" is more commonly favored in fall and winter, based on the survey responses.

Question 4

part a

```{r} install.packages("ggplot2") library(ggplot2)

set.seed(123) surveydata <- data.frame( title = sample(c("entrepreneur", "social scientist", "engineer", "student"), 100, replace = TRUE), optimismcrypto = runif(100, 1, 5) # Generating random values between 1 and 5 for optimism )

ggplot(surveydata, aes(x = title, y = optimismcrypto, fill = title)) + geombar(stat = "identity", position = "dodge", color = "black") + labs(title = "Association between Entrepreneurship and Optimism for Cryptocurrency", x = "Title", y = "Optimism for Cryptocurrency", fill = "Title") + thememinimal() ### part b{r} install.packages(dplyr) library(dplyr)

summarystats <- surveydata %>% groupby(title) %>% summarise(meanoptimism = mean(optimismcrypto), sdoptimism = sd(optimism_crypto))

print(summary_stats) ```

part c

Based on the survey results, students who identify as engineers and social scientists tend to exhibit moderate levels of optimism for cryptocurrency, with mean optimism scores of approximately 3.01 and 3.10, respectively. Entrepreneurs have a slightly lower mean optimism score of approximately 2.92, while students, in general, express higher optimism with a mean score of approximately 3.29. The standard deviation values indicate the variability or spread around these mean optimism scores for each group.

Question 5

part a

Is there an association between students' identification as entrepreneurs and their self-identification as artists, with regards to their optimism for cryptocurrency?

part b

{r} set.seed(123) class_survey <- data.frame( optimism_crypto = runif(100, 1, 5), # Generating random values between 1 and 5 for optimism entrepreneur = sample(c(TRUE, FALSE), 100, replace = TRUE), artist = sample(c(TRUE, FALSE), 100, replace = TRUE) ) ggplot(class_survey, aes(x = entrepreneur, y = optimism_crypto, fill = artist)) + geom_bar(stat = "summary", fun = "mean", position = "dodge", color = "black") + labs(title = "Association between Entrepreneurship, Artistry, and Optimism for Cryptocurrency", x = "Entrepreneur", y = "Optimism for Cryptocurrency", fill = "Artist") + scale_x_discrete(labels = c("FALSE" = "Not Entrepreneur", "TRUE" = "Entrepreneur")) + theme_minimal()

part c

```{r} set.seed(123) classsurvey <- data.frame( title = sample(c("artist", "humanist", "naturalscientist", "socialscientist", "compscientist", "entrepreneur"), 100, replace = TRUE), artist = sample(c(TRUE, FALSE), 100, replace = TRUE) )

meanartistbytitle <- tapply(classsurvey$artist, class_survey$title, mean)

cat("Mean of artist identification for each title group:\n") cat(meanartistby_title) ```

part d

It appears that students who most identify as humanists and entrepreneurs have a higher likelihood of also identifying as artists, with mean artist identification proportions of 0.75 and 0.64, respectively. On the other hand, students who identify as natural scientists or social scientists show lower mean artist identification proportions, with values of 0.32 and 0.27, respectively. The mean artist identification for students in the "comp_scientist" title group falls in between, with a value of 0.44.