knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(dplyr) vector_example <- c(4, 1, 9, 4, 2, 8, 7, 3) mean(vector_example)
data_frame_example <- data.frame(colors = c("blue", "blue", "red", "red", "yellow", "yellow", "purple", "purple", "green", "green"), congruency = c("congruent", "incongruent", "congruent", "incongruent", "congruent", "incongruent","congruent", "incongruent", "congruent", "incongruent"), data = c(35, 49, 21, 92, 54, 17, 38, 43, 20, 31)) data_frame_example
average_congruent <- mean(data_frame_example$data[data_frame_example$congruency == "congruent"]) average_congruent
bnj <- list("phishfood", 7, 4, "med") names(bnj) <- c("flavor", "tastyrating", "creamyrating", "pricing") hagendaaz <- list("vanilla", 6, 9, "high") names(hagendaaz) <- c("flavor", "tastyrating", "creamyrating", "pricing") breyers <- list("brownie", 9, 3, "low") names(breyers) <- c("flavor", "tastyrating", "creamyrating", "pricing") icecreamreviews <- list(bnj, hagendaaz, breyers) ### To conveniently vectorize tastyness ratings across two brands (the utility of lists is intended to be demonstrated here under a context of putting in all the review details of each ice cream brand separately) hd_breyers_tasty_compare <- c(icecreamreviews[[2]]$tastyrating, icecreamreviews[[3]]$tastyrating) hd_breyers_tasty_compare
matrix_data <- c(rnorm(100, 0, 1)) matrix_example <- matrix(data = matrix_data, nrow = 10, ncol = 10, byrow = FALSE)
second_col_mean <- mean(matrix_example[,2]) sixth_row_mean <- mean(matrix_example[6,]) means_of_second_col_and_sixth_row <- c(second_col_mean, sixth_row_mean) means_of_second_col_and_sixth_row
for(i in 0:20){ pretend_F_ratio <- (rnorm(1, 0, 0.5)+1) / ((rnorm(1, 0, 0.5)^2) + i) print(pretend_F_ratio) }
rand_data <- 5 i <- 1 while(i <= 100){ pretend_F_ratio <- (rand_data) / (rand_data+i) if((pretend_F_ratio) < 0.3){ break } print(pretend_F_ratio) i <- i+1 }
example_vector <- c(rnorm(20, 0, 1)) negative_values <- example_vector[example_vector < 0] positive_values <- example_vector[example_vector > 0] negative_values
positive_values
data_frame_example <- data.frame(colors = c("blue", "blue", "red", "red", "yellow", "yellow", "purple", "purple", "green", "green"), congruency = c("congruent", "incongruent", "congruent", "incongruent", "congruent", "incongruent","congruent", "incongruent", "congruent", "incongruent"), data = c(35, 49, 21, 92, 54, 17, 38, 43, 20, 31)) incongruent_values <- c(data_frame_example$data[data_frame_example$congruency == "incongruent"]) incongruent_values
fizzy_buzzy <- vector() for(i in 1:100){ if(i%%3 && i%%5 == 0){ fizzy_buzzy[i] <- "fizzbuzz" } else if (i%%3 == 0){ fizzy_buzzy[i] <- "fizz" } else if (i%%5 == 0){ fizzy_buzzy[i] <- "buzz" } else { fizzy_buzzy[i] <- i } } print(fizzy_buzzy)
freq <- runif(5000000, 0, 101) frequencies <- tabulate(freq) frequency_table <- tibble(Values = 1:100, Frequencies = frequencies) frequency_table
frequency_max <- frequency_table[frequency_table$Values == 100, ] max_frequency <- as.numeric(frequency_max %>% select(Frequencies)) frequency_min <- frequency_table[frequency_table$Values == 1, ] min_frequency <- as.numeric(frequency_min %>% select(Frequencies)) frequency_range <- (max_frequency - min_frequency) frequency_range
mean(frequency_table$Frequencies)
hist(freq)
library(immuno.analyze) immuno.analyze::percent.area.plane("PS6_%Area_BLA_Ant", "Med", "Pos", "PS6_Area_Percent", "Ctrl", "Switch", 6, "percent_ps6_BLA.csv")
percent.area.plane <- function(graph_name_1, graph_name_2, graph_name_3, DV, first_group, second_group, n_per_group, data = x){ library(stringr) library(dplyr) library(tidyr) library(ggplot2) library(patchwork) immunot_data <- as.data.frame(read.csv(data, header = TRUE, sep = ",", dec = ".")) %>% select(c("Label", "Mean", "X.Area")) immunot_data <- separate(immunot_data, "Label", c("Group", NA, "Subject", NA, "Plane", "Side", NA, NA, NA, NA, NA, NA), "_") means_by_plane <- tibble(aggregate(immunot_data$X.Area, FUN = mean, by = list(Plane = immunot_data$Plane, Group = immunot_data$Group))) sds_by_plane <- tibble(aggregate(immunot_data$X.Area, FUN = sd, by = list(Plane = immunot_data$Plane, Group = immunot_data$Group))) gp1_ant <- immunot_data[immunot_data$Group == first_group & immunot_data$Plane == "Ant", ] aa <- as.vector(t(gp1_ant %>% select(X.Area))) gp2_ant <- immunot_data[immunot_data$Group == second_group & immunot_data$Plane == "Ant", ] ab <- as.vector(t(gp2_ant %>% select(X.Area))) gp1_med <- immunot_data[immunot_data$Group == first_group & immunot_data$Plane == "Med", ] ba <- as.vector(t(gp1_med %>% select(X.Area))) gp2_med <- immunot_data[immunot_data$Group == second_group & immunot_data$Plane == "Med", ] bb <- as.vector(t(gp2_med %>% select(X.Area))) gp1_pos <- immunot_data[immunot_data$Group == first_group & immunot_data$Plane == "Pos", ] ca <- as.vector(t(gp1_pos %>% select(X.Area))) gp2_pos <- immunot_data[immunot_data$Group == second_group & immunot_data$Plane == "Pos", ] cb <- as.vector(t(gp2_pos %>% select(X.Area))) gp1_mean_ant <- means_by_plane[1,3] gp1_mean_med <- means_by_plane[2,3] gp1_mean_pos <- means_by_plane[3,3] gp2_mean_ant <- means_by_plane[4,3] gp2_mean_med <- means_by_plane[5,3] gp2_mean_pos <- means_by_plane[6,3] gp1_sterr_ant <- sds_by_plane[1,3] / sqrt(n_per_group) gp1_sterr_med <- sds_by_plane[2,3] / sqrt(n_per_group) gp1_sterr_pos <- sds_by_plane[3,3] / sqrt(n_per_group) gp2_sterr_ant <- sds_by_plane[4,3] / sqrt(n_per_group) gp2_sterr_med <- sds_by_plane[5,3] / sqrt(n_per_group) gp2_sterr_pos <- sds_by_plane[6,3] / sqrt(n_per_group) ant_compare <- as.numeric(c(gp1_mean_ant, gp2_mean_ant)) med_compare <- as.numeric(c(gp1_mean_med, gp2_mean_med)) pos_compare <- as.numeric(c(gp1_mean_pos, gp2_mean_pos)) ant_sterrs <- as.numeric(c(gp1_sterr_ant, gp2_sterr_ant)) med_sterrs <- as.numeric(c(gp1_sterr_med, gp2_sterr_med)) pos_sterrs <- as.numeric(c(gp1_sterr_pos, gp2_sterr_pos)) graph_df_ant <- tibble(Ant = rep(c(first_group, second_group)), DV = ant_compare) graph_df_med <- tibble(Med = rep(c(first_group, second_group)), DV = med_compare) graph_df_pos <- tibble(Pos = rep(c(first_group, second_group)), DV = pos_compare) a <- ggplot(graph_df_ant, aes(x = Ant, y = DV)) + geom_bar(stat = "identity") + geom_errorbar(aes(ymin = (DV - ant_sterrs), ymax = (DV + ant_sterrs))) + ggtitle(graph_name_1) + ylab(DV) m <- ggplot(graph_df_med, aes(x = Med, y = DV)) + geom_bar(stat = "identity") + geom_errorbar(aes(ymin = (DV - med_sterrs), ymax = (DV + med_sterrs))) + ggtitle(graph_name_2) + ylab(DV) p <- ggplot(graph_df_pos, aes(x = Pos, y = DV)) + geom_bar(stat = "identity") + geom_errorbar(aes(ymin = (DV - pos_sterrs), ymax = (DV + pos_sterrs))) + ggtitle(graph_name_3) + ylab(DV) ant_t <- t.test(aa, ab, var.equal = TRUE)$p.value med_t <- t.test(ba, bb, var.equal = TRUE)$p.value pos_t <- t.test(ca, cb, var.equal = TRUE)$p.value analysis_list <- c(ant_t, med_t, pos_t) plot <- a+m+p analysis <- return(list(analysis_list, plot)) }
library(DBSStats2SemesterProject)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.