1
$\begingroup$

My work looks at reproductive stages of an organism over two years, using bi-monthly sampling at 6 different locations. Using R, I did a multinomial logistic regression to analyze the data, and built a model using the following dataset (truncated for this example). Packages needed: nnet, ggplot2

SED<-structure(list(Date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("Month 1", 
"Month 2", "Month 3"), class = "factor"), Site = structure(c(1L, 
2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 
6L), .Label = c("Site 1", "Site 2", "Site 3", "Site 4", "Site 5", 
"Site 6"), class = "factor"), Veg = c(14L, 17L, 28L, 3L, 4L, 
8L, 5L, 12L, 6L, 2L, 11L, 6L, 1L, 3L, 0L, 1L, 2L, 1L), Dev = c(2L, 
5L, 0L, 10L, 0L, 11L, 0L, 0L, 3L, 0L, 0L, 1L, 2L, 1L, 1L, 2L, 
0L, 0L), Repro = c(10L, 8L, 1L, 8L, 11L, 10L, 25L, 15L, 21L, 
28L, 17L, 23L, 27L, 26L, 26L, 27L, 28L, 29L), Total = c(26L, 
30L, 29L, 21L, 15L, 29L, 30L, 27L, 30L, 30L, 28L, 30L, 30L, 30L, 
27L, 30L, 30L, 30L)), .Names = c("Date", "Site", "Veg", "Dev", 
"Repro", "Total"), class = "data.frame", row.names = c(NA, -18L
))
SED$Y<-as.matrix(SED[,c("Veg","Dev","Repro")])
library(nnet)
SED_1<-multinom(Y ~ Date + Site, data=SED); SED_1
summary(SED_1)

To visualize the model, I generated predicted probabilities using fitted() and graphed them with ggplot2.

SED_1_Fit<-fitted(SED_1)
#add back the date and site columns from the original file so fitted values can be graphed
SED_1_Fit<-as.data.frame(SED_1_Fit)
SED_1_Fit$Date<-SED$Date
SED_1_Fit$Site<-SED$Site
Library(ggplot2)
ggplot(data=SED_1_Fit, aes(x=Date, y=Veg, color=Site, group=Site)) + geom_line() + geom_point() + xlab("Date") + ylab("% Probability") + labs(title= "Fitted Values Vegetative Tissue")

I want to add 95% confidence intervals to the fitted values graphs, but most examples I have seen generate them using mlogit() or just lm(). What method or function can I use to get confidence intervals for the fitted values generated by fitted()?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.