A Guide to Qualitatively Analyzing Computing Code
  • Home
  • Step-by-Step Guide
  • About

Reproducing Student A’s Code

On this page

On this page

  • Reproducing Student A’s Code

Report an issue

  • Step 1: Selecting a Unit of Analysis
  • Step 2: Descriptive Codes
  • Step 3: Discovering Emergent Themes
  • Optional: Comparing Across Students
  • Step 4: Digging Deeper

On this page

  • Reproducing Student A’s Code

Report an issue

Reproducing Student A’s Code

The following analysis reproduces Student A’s code in the context of the penguins dataset from the palmerpenguins package (Horst, Hill, and Gorman 2020).

Horst, Allison Marie, Alison Presmanes Hill, and Kristen B Gorman. 2020. Palmerpenguins: Palmer Archipelago (Antarctica) Penguin Data. https://doi.org/10.5281/zenodo.3960218.
library(palmerpenguins)
library(tidyverse)

set.seed(123)

The only variable type missing from the penguins dataset is a variable similar to Student A’s “Age” variable. The pengins dataset contains information on adult penguins. Depending on the size of the penguin, they can take between three and eight years until they begin breeding. Most species of penguins take at least five years. Thus, when creating an age variable in the penguins dataset I simulated values from a Normal distribution with mean 5 and standard deviation 1.

penguins <- penguins |> 
  mutate(age = rnorm(n = nrow(penguins), mean = 5, sd = 1), 
         age = round(age, digits = 0)
         )

Reproducing Student A’s Code

#upper anterior measurement Linear model
linearAnterior <- lm(penguins$bill_length_mm~penguins$bill_depth_mm)
summary(linearAnterior)
linearAnterior
with(penguins, plot(bill_length_mm~bill_depth_mm,las = 1,col = ifelse(penguins$body_mass_g< 4050,"red","black")))
abline(linearAnterior)
plot(linearAnterior)


#Exponential function
expAnterior <- lm(penguins$bill_length_mm~log(penguins$bill_depth_mm))
summary (expAnterior)
expAnterior
with(penguins, plot(bill_length_mm~log(bill_depth_mm), las = 1, col = ifelse(penguins$body_mass_g< 4050,"red","black")))
abline(expAnterior)
plot(expAnterior)
summary(expAnterior)


early <- subset(penguins, year<2007)
mid <- subset(penguins, year<2009 & year>2007)
penguinsSub <- transform(penguins, Age = as.integer(age))
Early <- subset(penguinsSub, year<2008)
Mid <- subset(penguinsSub, year<2009 & year>2007)
EarlyWeightAge <- ddply(Early, ~Age, summarise, meanWE=mean(body_mass_g, na.rm = T))
EarlyLengthAge <- ddply(Early, ~Age, summarise, meanLE=mean(bill_length_mm, na.rm = T))
MidLengthAge <- ddply(Mid, ~Age, summarise, meanLM=mean(bill_length_mm, na.rm = T))
WeightChange <- rep(NA, 9)

library(plyr)
WeightAge <- ddply(penguinsSub, ~Age, summarise, meanW=mean(body_mass_g, na.rm = T))
LengthAge <- ddply(penguinsSub, ~Age, summarise, meanL=mean(bill_length_mm, na.rm = T))
plot(EarlyLengthAge$meanLE~EarlyLengthAge$Age,las = 1,ylab = "Fork Length (mm)",xlab = "Age")
lines(EarlyLengthAge$meanLE~EarlyLengthAge$Age)
points(MidLengthAge$meanLM~MidLengthAge$Age,col = "red")
lines(MidLengthAge$meanLM~MidLengthAge$Age,col = "red")
legend(6, 48, legend = c("1998-2003", "2006-2017"),col = c("black", "red"), lty = 1:1,cex = 0.8)

#Tanner's code/help
WeightChange <- rep(NA, 9)
library(plyr)
WeightAge <- ddply(penguinsSub, ~Age, summarise, meanW=mean(body_mass_g, na.rm = T))
LengthAge <- ddply(penguinsSub, ~Age, summarise, meanL=mean(bill_length_mm, na.rm = T))
plot(WeightAge$meanW~WeightAge$Age)
plot(LengthAge$mean~LengthAge$Age)
WeightChange

Weight1 <- mean(penguinsSub$body_mass_g[penguinsSub$Age==2], na.rm=TRUE)
Weight1
Length1 <- mean(penguinsSub$bill_length_mm[penguinsSub$Age==2], na.rm=TRUE)
Weight2 <- mean(penguinsSub$body_mass_g[penguinsSub$Age==3], na.rm=TRUE)
Length2 <- mean(penguinsSub$bill_length_mm[penguinsSub$Age==3], na.rm=TRUE)
Weight3 <- mean(penguinsSub$body_mass_g[penguinsSub$Age==4], na.rm=TRUE)
Length3 <- mean(penguinsSub$bill_length_mm[penguinsSub$Age==4], na.rm=TRUE)
Weight4 <- mean(penguinsSub$body_mass_g[penguinsSub$Age==5], na.rm=TRUE)
Length4 <- mean(penguinsSub$bill_length_mm[penguinsSub$Age==5], na.rm=TRUE)
Weight5 <- mean(penguinsSub$body_mass_g[penguinsSub$Age==6], na.rm=TRUE)
Length5 <- mean(penguinsSub$bill_length_mm[penguinsSub$Age==6], na.rm=TRUE)
Weight6 <- mean(penguinsSub$body_mass_g[penguinsSub$Age==7], na.rm=TRUE)
Length6 <- mean(penguinsSub$bill_length_mm[penguinsSub$Age==7], na.rm=TRUE)
# Weight7 - Length9 removed
x <- data.frame("Age" = 1:7, "Growth" = Weight1,Weight2,Weight3,Weight4,Weight5,Weight6)
© Copyright 2023, Allison Theobold
This page is built with ❤️ and Quarto.