Animal - List unique animal IDs and count how many records there are for each.
Follower_ID - List unique follower IDs and count occurrences, which might be useful to see if certain animals are more frequently following others.
ENTRY - Entry time at the feeder
EXIT - Exit time at the feeder
STAY_IN - Numerical data showing how long an animal stays.
Social_Group - Categorize by social group, counting the number of records per group.
L_time -Log time transformation
Hour_ENTRY - Hour of entry; hour of the day
time_between - Time between visits at the feeder
FEED_INTK - Feed intake per visit at the feeder
PEN - Pen number
sdL_time - Standard deviation of Log of the time length
Follower_IDpe - Permanent Environment of the follower effect
Animalpe - Permanent Environment of the direct effect
Unique_Animal_Count - Number of unique animals per some category or record; summarize with average, total, min, and max.
feeding_rec - Number of feeding records; summarize with total, average, min, and max per animal or per social group.
Packages
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
library(tidyr)library(broom)library(lme4)
Loading required package: Matrix
Attaching package: 'Matrix'
The following objects are masked from 'package:tidyr':
expand, pack, unpack
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(lme4)library(lmerTest)
Attaching package: 'lmerTest'
The following object is masked from 'package:lme4':
lmer
The following object is masked from 'package:stats':
step
library(emmeans)library(car)
Loading required package: carData
Attaching package: 'car'
The following object is masked from 'package:dplyr':
recode
rm(list =ls())setwd("C:\\Users\\anunez\\OneDrive - Iowa State University\\Desktop\\PIC_DataAnalysis_files")data_PIC <-read.csv("FINAL_FIRE_2019_2023_AN.csv")summary(data_PIC)
ID LINE PED_IDENT_SIRE PED_IDENT_DAM
Min. : 80406526 Min. :65 Min. :72321895 Min. :70838758
1st Qu.: 84007778 1st Qu.:65 1st Qu.:79257130 1st Qu.:79153747
Median : 88690351 Median :65 Median :83589571 Median :84025461
Mean : 89253749 Mean :65 Mean :83724294 Mean :83988626
3rd Qu.: 93986447 3rd Qu.:65 3rd Qu.:87591160 3rd Qu.:88191389
Max. :100603759 Max. :65 Max. :95485445 Max. :96751344
LIT_LITTER_ID PEN TEST_FARM ENTRY_TIME
Min. :68967039 Length:1048575 Min. :774 Length:1048575
1st Qu.:71920248 Class :character 1st Qu.:774 Class :character
Median :74483118 Mode :character Median :774 Mode :character
Mean :74566106 Mean :774
3rd Qu.:77074566 3rd Qu.:774
Max. :80351636 Max. :774
EXIT_TIME STAY_IN FEED_INTK FEEDER_ENTRY_WT
Length:1048575 Min. : 2 Min. :-3892.0 Min. :-993
Class :character 1st Qu.: 513 1st Qu.: 231.0 1st Qu.: 786
Mode :character Median : 1103 Median : 521.0 Median :1051
Mean : 3582 Mean : 575.4 Mean :1106
3rd Qu.: 1757 3rd Qu.: 848.0 3rd Qu.:1399
Max. :665125948 Max. : 9280.0 Max. :9282
FEEDER_EXIT_WT FEEDER_NO START_DAY END_DAY
Min. :-993.0 Min. : 1.00 Length:1048575 Length:1048575
1st Qu.: 414.0 1st Qu.:14.00 Class :character Class :character
Median : 525.0 Median :31.00 Mode :character Mode :character
Mean : 530.8 Mean :30.19
3rd Qu.: 647.0 3rd Qu.:46.00
Max. :8182.0 Max. :66.00
# Arrange the data and add a row numberdata_PIC_arranged <- data_PIC_pvalues60 %>%arrange(Social_Group, ENTRY, EXIT, by_group =TRUE) %>%mutate(line =row_number())dim(data_PIC_arranged)
[1] 1038897 30
# Filter the data and select specific columnsdata_PIC_filtered <- data_PIC_pvalues60 %>%filter(ID != Follower_ID) %>% dplyr::select(ID, Follower_ID, ENTRY, EXIT, STAY_IN, Social_Group, L_time, Hour_ENTRY, time_between, FEED_INTK, PEN)data_PIC_pvalues60
unique_ids_per_group <- data_PIC_filtered %>%group_by(Social_Group) %>%summarise(Unique_IDs =n_distinct(ID),.groups ='drop') %>%# Calculate the mean of Unique_IDs across all groupssummarise(Mean_Unique_IDs =mean(Unique_IDs))print(unique_ids_per_group)
Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
: reciprocal condition number 1.0661e-15
Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
: There are other near singularities as well. 1
Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x
else if (is.data.frame(newdata))
as.matrix(model.frame(delete.response(terms(object)), : pseudoinverse used at
16.07
Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x
else if (is.data.frame(newdata))
as.matrix(model.frame(delete.response(terms(object)), : neighborhood radius
2.07
Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x
else if (is.data.frame(newdata))
as.matrix(model.frame(delete.response(terms(object)), : reciprocal condition
number 1.0661e-15
Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x
else if (is.data.frame(newdata))
as.matrix(model.frame(delete.response(terms(object)), : There are other near
singularities as well. 1
#| warning: true#| echo: truesocial_group_summary <- data_PIC_filtered %>%group_by(Social_Group) %>%summarise(Unique_Animal_Count =n_distinct(Animal), # Count distinct IDs in each social groupfeeding_rec =n() # Count all records in each social group )# joining this summary back to the original data to keep all columnsextended_data <- data_PIC_filtered %>%left_join(social_group_summary, by ="Social_Group")# Filter the data where the Unique_Animal_Count is greater than 13 to keep 14,15,16 SGfiltered_data <-filter(extended_data, Unique_Animal_Count >13)final_summary <- filtered_data %>%summarize(Total_rec =sum(feeding_rec))final_summary
ggplot(filtered_data, aes(x= Unique_Animal_Count , y = feeding_rec, )) +geom_point()+geom_smooth()
`geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
Warning: Failed to fit group -1.
Caused by error in `smooth.construct.cr.smooth.spec()`:
! x has insufficient unique values to support 10 knots: reduce k.