Dear all,
I'm trying to analyse the effect of "Factor1" and "Factor2" on the response variable "perf" by "location", and obtaining at the end my original dataset associated to the lsmeans and tukey groups letters. Here below the code I'm using that gives me exactly what I need but only by location, my need is : how can I extend it in a way my output combines results of all locations, i.e, output of lsmeans and CLD by location
library(multcomp)
library(lsmeans)
library(dplyr)
library(broom)
output <- as.data.frame(dataset)
output$perf <- as.numeric(output$perf)
output$factor1 <- as.factor(output$factor1)
output$factor2 <- as.factor(output$factor2)
output <- output %>%
group_by(location) %>%
mutate(row=row_number())
model <- lm(perf ~ factor1 + factor2, data = output)
lsmeans <- lsmeans(model, ~ factor1)
CLD = cld(lsmeans,
alpha = 0.05,
Letters = letters,
adjust = "tukey")
output <- left_join(output, CLD, by = "factor1")
Thank you in advance for your help !