I have currently a problem where I have a dataframe similar to the one I called "test" below.
What I would like to do is to fit a Linear Model for each Site against Time and Group, so one model for A, one for B, and one for C.
e.g: Site A is present in 2 Groups: G1 and G2. It was measured at 5 time points. So I do have 5 values which should be modelled as dependent from Time (value ~ Time) and because it was done in 2 conditions (Group) this should be integrated so: (value ~ Time*Group).
How can I most efficiently achieve this and then extract the information from the summary to store them in a vector or list?
Thank you for your time, I really appreciate it.
test <- data.frame(Site= rep(c( rep("A", 5),
rep("B", 5),
rep("C", 5)),2),
value= c(rnorm(1, n=15), rnorm(1, n=15)),
Time= rep(rep((1:5), 3), 2),
Group= c(rep("G1", 15), rep("G2", 15))
)
# Loop ?
linReg <- lm(value ~ Time * Group, data= test)