install.packages("ggformula") library(ggformula) tetrismemories <- read.csv("https://raw.githubusercontent.com/smburns47/Psyc158/main/tetrismemories.csv") gf_histogram(gformula = ~ intrusive_memories, data = tetrismemories) #Change the plotted variable to STAI_T gf_histogram(gformula = ~ intrusive_memories, data = tetrismemories) outcome <- c(1,2,3,4,5) tiny_data <- data.frame(outcome) #gf_histogram only works on dataframe objects, not vectors #Write some code below here to plot a histogram of the variable "outcome" in the dataframe "tiny_data" gf_histogram(gformula = ~ outcome, data = tiny_data, bins = 5) gf_histogram(gformula = ~ outcome, data = tiny_data, bins = 5, color = "gray", fill = "blue") gf_dhistogram(gformula = ~ outcome, data = tiny_data, bins = 5, color = "gray", fill = "blue") #Finish the code below to make a density plot of Age in mindsetmatters gf_dhistogram(#set formula here, #set data frame here, #set bin and color options here) normal_data <- rnorm(n = 1000, mean = 0, sd = 1) #rnorm is a function that generates data in a normal distribution; # we'll talk about simulating data like this in a later chapter gf_dhistogram(gformula = ~ data_pts, data = data.frame(data_pts = normal_data)) test_scores <- c(76,91,86,80,93) #This computes a mean sum(test_scores) / length(test_scores) #Use mean() to calculate the mean of test_scores: #Evaluate the code below. Do you think it will be the same as your mean calculation? sum(test_scores) / length(test_scores) dist1 <- c(10, 10, 11, 9, 11, 12, 8, 9, 10) dist2 <- c(10, 10, 11, 9, 11, 12, 8, 9, 10, 100) #Write code to plot the density plot of each of these distributions, using df_dhistogram() #Calculate mean of dist1 #Calculate mean of dist2 median(test_scores) #Visualize a weird distribution. Where is the mean versus the median versus the mode? weird_dist <- data.frame(data_pts = c(10,20,20,30,30,30,40,40,40,40,50,50,50,50,50)) gf_dhistogram(gformula = ~ data_pts, data = weird_dist) table(weird_dist$data_pts) #Max of test_scores max(test_scores) #Min of test_scores min(test_scores) #Calculate the range of test_scores by subtracting the min from the max range(test_scores) quantile(tetrismemories$STAI_T, probs = 0.5, na.rm = TRUE) median(tetrismemories$STAI_T, na.rm = TRUE) quantile(tetrismemories$STAI_T, probs = c(0.25,0.5,0.75), na.rm = TRUE) IQR(tetrismemories$STAI_T, na.rm = TRUE) mean_score <- mean(test_scores) # mean of the data devs <- test_scores - mean_score # all deviations from the mean sum(devs) # sum of the deviations var(tetrismemories$intrusive_memories, na.rm = TRUE) # Find the standard deviation of tetrismemories$intrusive_memories using sd(), and verify # that it produces the same result as the square root of var() memories_var <- var(tetrismemories$intrusive_memories, na.rm = TRUE) memories_sd <- sd( #type your code here ) sqrt(memores_var) == memores_sd