Al3xandria: Rstudio code

Simple code

acs=read.csv(file.choose())
View(acs)

enriched30<-acs$X30min.test[acs$environment==”enriched”] – new data set name <- Numerical Variable [treatment variable == “specific treatment you want to subset”]

>shapiro.test(enriched30) to test for normality, column or subset name in the brackets

>boxplot(enriched30, standard30) makes a box plot

>wilcox.test(enriched30, standard30) non parametric test for two treatments

>t.test(enriched30, standard30, mu=0, alternative=”two.sided”, paired = T, conf.level = 0.99) paired t-test, insert numerical data variables in enriched30 and standard30.

HOW TO MAKE A TABLE OF AVERAGES FROM A NUMERICAL COLUMN SPLIT

INTO LEVELS BY A CATEGORICAL VARIABLE

cleandata<- acs #(DATASET NAME)#%>%

  • group_by(environment #categorical variable# )%>%
  • summarise(mean_30min = mean(X30min.test #numerical variable#))
    summarise() ungrouping output (override with .groups argument)
    View(cleandata) #Dont need to put acs$ infront of variables because it has
    #been piped through already via %>% #

cleandata<- acs%>%

  • group_by(environment)%>%
  • summarise(mean_30min = mean(X30min.test))

summarise() ungrouping output (override with .groups argument)

View(cleandata)

HOW TO MAKE A TABLE OF AVERAGES, COUNT, SD, AND SE FROM A NUMERICAL

COLUMN SPLIT INTO LEVELS BY A CATEGORICAL VARIABLE

cleandata<- acs%>%

  • group_by(environment)%>%
  • summarise(mean_30min = mean(30min.test), sd_30min = sd(X30min.test), count = n(), se_30min = (sd_30min/sqrt(count)))
    summarise() ungrouping output (override with .groups argument)

summarise(mean_30min = mean(acs$X30min.test), sd_30min = sd(acs$X30min.test), count = n(), se_30min = (sd_30min/sqrt(count)))

HOW TO MAKE A BAR GRAPH FROM SAID TABLES ^^

Lab1plot<-ggplot(cleandata2, aes(x = environment, y = mean_30min)) +
geom_bar(stat = “identity”, color = “black”, position = position_dodge())

  • geom_errorbar(aes(ymin = mean_30min-se_30min, ymax = mean_30min + se_30min),
    width = .2) + labs(x = “environmental treatment”, y = “object exploration”) +
    theme_classic()
  1. snakeHOD= read.csv(file.choose())

attach(snakeHOD)
summary(snakeHOD)
-shows a table of shit if you did it correctly
head(snakeHOD)
tail(snakeHOD)
These show how the data looks at the top and bottom
attach (snakeHOD)
view(snakeHOD)
This is to see the data in a dataviewer

  1. >x= subset(snakeHOD, Handler>Stranger)

View(x)
This is to make your data into a subset, in this case its choosing every row in which the snake spent more time with the handler than the stranger.

  1. >snakedata=(head(snakehod, n=25))
    Melting is an important and useful function!!! It basically allows you to reshape your data and combine columns into an easier to use dataset. Thus making transformations or statistical tests way easier to conduct.

print(snakedata) this is to make sure it looks right, and find column labels
snakemelt=melt(snakedata, id=c(“ï..environment,”Differential”))
your independent variables get listed in the c bracket while the ones you did not list will be melted into one
print(snakemelt) and it should show your melted columns in addition to your independent, snakemelt is also how you will access said new data.

Bootstrapping and Combining

b<-10000 (set to bootstrapped sample size), n=length(H1) (length of the data)

H1bootstrap<-matrix(sample(H1, size = n*b, replace = TRUE),nrow = b, ncol =1)

combinedgroup1000<-data.frame(cbind(H1bootstrap1000,H5bootstrap1000,t1nbootstrap1000,
t1fbootstrap1000))

stacked10thous<-stack(combinedgroup10thous)

stackedsnakeanova<-aov(values~ind,data = stackedbootstrap)

t.test(t1f, t1n, mu=0, alternative =”two.sided”, paired = T, conf.level = 0.95)

na.omit()


Follow My Blog

Get new content delivered directly to your inbox.