Diana
Diana

Reputation: 1

Least Square Means problems in R

My data looks like this with plots as rows and with different Ellenberg values as columns together with Year, Forest (Skov) and Forest type (Skovtype).

My data are from 4 different years (1993, 1998, 2005 and 2016).

enter image description here

I have some problems with the lsmeans function my script looks like this:

ellenberg_LM <- read.csv2("Gns. Ellenberg1.csv")

Converting year from integer to factor

levels(ellenberg_LM$Year)
ellenberg_LM$Year <- factor(ellenberg_LM$Year)

Ellenberg L - LM

LLM<-lm(Gennemsnit.af.L_Ellenberg ~ Year + Skov + Skov*Year + Skovtype + Skovtype*Year,
        data=ellenberg_LM)

LS-means

install.packages("lsmeans")
library(lsmeans)
lsmeans(LLM,~ Year, data = ellenberg_LM)

My output looks like this, with NA’s for 1993 in the first example. But if I leave out the interaction with Skov*Year and Skovtype*Year R estimates lsmeans for all years like the last example.

enter image description here

My question is then; do you know what I have done wrong to get the NA’s or do I miss something? Because I want the calculate lsmeans for all years with the interactions.

Upvotes: 0

Views: 1350

Answers (1)

Russ Lenth
Russ Lenth

Reputation: 6770

The NA is there because the predicted value is not estimable at certain combinations of the three factors -- hence still not estimable after averaging over the levels of two of those factors. This is probably due to there being no data at certain factor combinations (empty cells in the data). When you fitted a simpler model, those predictions became estimable because some interaction effects no longer need to be estimated.

If any of the interaction effects are significant, you probably should not be estimating those marginal means anyway (that's why there is a warning message). Look at some interaction plots (e.g., using lsmip with the interaction model) to visualize what is going on and to see if it is sensible to average the predictions together. See a statistical consultant if this stuff is confusing to you.

By the way, the data argument is not necessary in the lsmeans call.

Upvotes: 2

Related Questions