Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Load required libraries
- library(tidyverse)
- # Load the data
- inbound <- read.csv("/path/to/inbound.csv", stringsAsFactors = FALSE)
- outbound <- read.csv("/path/to/outbound.csv", stringsAsFactors = FALSE)
- # Compute speed differences
- compute_speed_difference <- function(data) {
- data <- data %>%
- arrange(X..Timestamp) %>%
- group_by(Name) %>%
- mutate(speed_difference = c(0, diff(SOG)))
- return(data)
- }
- inbound <- compute_speed_difference(inbound)
- outbound <- compute_speed_difference(outbound)
- # Combine the datasets and differentiate direction
- inbound$Direction <- "Inbound"
- outbound$Direction <- "Outbound"
- combined_data <- rbind(inbound, outbound)
- # Filter for the ship of interest
- combined_data <- combined_data %>% filter(Name == "NEWNEW POLAR BEAR")
- # Categorize the data into the two bins
- #combined_data$New_Speed_Bins <- ifelse(abs(combined_data$speed_difference) <= 0.1, "Speed delta: -0.1 to 0.1", "> -0.1 to 0.1")
- combined_data$New_Speed_Bins <- ifelse(abs(combined_data$speed_difference) <= 0.2, "-Speed delta: 0.2 to 0.2", "> -0.2 to 0.2")
- # Create a contingency table of counts using the new bins
- new_contingency_table <- table(combined_data$Direction, combined_data$New_Speed_Bins)
- # Conduct the Chi-Squared Test for Independence
- new_chi_squared_test <- chisq.test(new_contingency_table)
- # Print the new contingency table for inspection
- print(new_contingency_table)
- # Print the Chi-Squared test results
- new_chi_squared_test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement