Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Last active February 21, 2022 12:29
Show Gist options
  • Select an option

  • Save MJacobs1985/ec9067ebf622e97682c232ca8efbb2a7 to your computer and use it in GitHub Desktop.

Select an option

Save MJacobs1985/ec9067ebf622e97682c232ca8efbb2a7 to your computer and use it in GitHub Desktop.
dfnew<-as.data.frame(dfnew)
inTraining <- createDataPartition(dfnew$newField,
p = .75,
list = FALSE)
training <- dfnew[ inTraining,]
testing <- dfnew[-inTraining,]
training%>%
filter(lcn_id%in%(901:906))%>%
ggplot(., aes(x=curve_day,
y=comp1_provided,
colour=as.factor(newField)))+
geom_point()+
theme_bw()+
facet_wrap(~lcn_id, ncol=3)
testing%>%
group_by(ogn_id,newField, curve_day)%>%
summarize(sumprov = mean(feed_provided_cum),
sumpred = mean(pred))%>%
ggplot(., aes(x=curve_day,
fill=newField))+
geom_area(aes(y=sumprov), alpha=0.5)+
geom_point(aes(y=sumpred), alpha=0.5)+
geom_line(aes(y=sumpred))+
theme_bw()+
facet_wrap(~ogn_id+newField)
testing%>%
filter(lcn_id%in%(901:906))%>%
ggplot(., aes(x=curve_day,
y=comp1_provided,
colour=as.factor(newField)))+
geom_point()+
theme_bw()+
facet_wrap(~lcn_id, ncol=3)
m1_gam <- gamm4(feed_provided_cum~s(curve_day)+
s(animals_actual)+
s(feed_provided)+
ogn_id+
newField,
data=training,
random=~(1+curve_day|lcn_id))
m1_gam
plot(m1_gam$mer)
par(mfrow = c(2, 2))
plot(m1_gam$gam)
m1_gam_aug<-augment(m1_gam$gam, confint=TRUE)
m1_gam_mer_aug<-augment(m1_gam$mer, confint=TRUE)
m1_gam_aug%>%filter(lcn_id%in%(901:909))%>%
ggplot(., aes(x=feed_provided_cum, y=.fitted, colour=.resid))+
geom_point()+
theme_bw()+
facet_wrap(~lcn_id+newField)+
geom_abline(intercept=0, slope=1, lty=2, col="black")+
scale_color_viridis_c(option="turbo")
m1_gam_mer_aug%>%filter(lcn_id%in%(901:909))%>%
ggplot(., aes(x=.mu, y=.fitted, colour=.resid))+
geom_point()+
theme_bw()+
geom_abline(intercept=0, slope=1, lty=2, col="black")+
scale_color_viridis_c(option="turbo")
m1_gam_aug%>%filter(lcn_id%in%(901:920))%>%
ggplot(., aes(x=curve_day, group=newField))+
geom_point(aes(y=feed_provided_cum,colour=newField), alpha=0.5)+
geom_line(aes(y=.fitted, colour=newField), lty=2, lwd=1)+
theme_bw()+
facet_wrap(~lcn_id+newField)
m1_gam_aug%>%filter(lcn_id%in%(901:920))%>%
ggplot(., aes(x=.resid, fill=newField))+
geom_density(alpha=0.5)+
geom_vline(xintercept=0, lty=2, col="black")+
theme_bw()+
facet_wrap(~lcn_id)
testing$pred<-predict(m1_gam$gam, newdata=testing)
testing%>%filter(lcn_id%in%(901:920))%>%
ggplot(., aes(x=curve_day, group=newField))+
geom_point(aes(y=feed_provided_cum,colour=newField), alpha=0.5)+
geom_line(aes(y=pred, colour=newField), lty=2, lwd=1)+
theme_bw()+
facet_wrap(~lcn_id+newField)
testing%>%filter(lcn_id%in%(901:909))%>%
ggplot(., aes(x=feed_provided_cum,
y=pred,
colour=feed_provided_cum-pred))+
geom_point()+
theme_bw()+
facet_wrap(~newField)+
geom_abline(intercept=0, slope=1, lty=2, col="black")+
scale_color_viridis_c(option="turbo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment