The plm function of the plm library in R is giving me grief over having duplicate time-id couples, even when I'm running a model that I don't think should need a time variable at all (see reproducible example below).

I can think of three possibilities:


My understanding of fixed effects regression is wrong, and they really do require unique time indices (or time indices at all!).
plm() is just being overly-finicky here and should relax this requirement.
The particular estimation technique that plm() uses--the within transformation--requires time indices, even though the order doesn't seem to matter and the less computationally-efficient version (including dummies in a straight-up OLS model) doesn't need them.


Any thoughts?

set.seed(1)
n <- 1000
test <- data.frame( grp = as.factor(rep( letters, (n/length(letters))+1 ))[seq(n)], x = runif(n), z = runif(n) )
test$y <- with( test, 2*x + 3*z + rnorm(n) )
lm( y ~ x + z, data = test )
lm( y ~ x + z + grp, data = test )

require(plm)
# Model fails if I don't specify a time index, despite effect = "individual"
plm( y ~ x + z, data = test, model = "within", effect="individual", index = "grp" ) 
# Create time variable and add it to the index but still specify individual FE not time FE also
library(plyr)
test <- ddply( test, .(grp), function(dat) transform( dat, t = seq(nrow(dat)) ) )
# Now plm() works; note coefficients clearly include the fixed effects, as they match the lm() version above
plm( y ~ x + z, data = test, model = "within", effect="individual", index = c("grp","t") ) 
# Scramble time variables and show they don't matter as long as they're unique within a cluster
test <- ddply( test, .(grp), function(dat) transform( dat, t = sample(t) ) )
plm( y ~ x + z, data = test, model = "within", effect="individual", index = c("grp","t") ) 
# Add a duplicate time entry and show that it causes plm() to fail
test[ 2, "t" ] <- test[ 1, "t" ] 
plm( y ~ x + z, data = test, model = "within", effect="individual", index = c("grp","t") ) 


Why this matters

I'm trying to bootstrap my model, and when I do the requirement that the index-time pairs be unique is causing headaches which seem unnecessary if (2) is true.

Traditionally, the null hypothesis is a point value.  (It is typically $0$, but can in fact be any point value.)  The alternative hypothesis is that the true value is any value other than the null value.  Because a continuous variable (such as a mean difference) can take on a value which is indefinitely close to the null value but still not quite equal and thus make the null hypothesis false, a traditional point null hypothesis cannot be proven.  

Imagine your null hypothesis is $0$, and the mean difference you observe is $0.01$.  Is it reasonable to assume the null hypothesis is true?  You don't know yet; it would be helpful to know what our confidence interval looks like.  Let's say that your 95% confidence interval is $(-4.99,\ 5.01)$.  Now, should we conclude that the true value is $0$?  I would not feel comfortable saying that, because the CI is very wide, and there are many, large non-zero values that we might reasonably suspect are consistent with our data.  So let's say we gather much, much more data, and now our observed mean difference is $0.01$, but the 95% CI is $(0.005,\ 0.015)$.  The observed mean difference has stayed the same (which would be amazing if it really happened), but the confidence interval now excludes the null value.  Of course, this is just a thought experiment, but it should make the basic ideas clear.  We can never prove that the true value is any particular point value; we can only (possibly) disprove that it is some point value.  In statistical hypothesis testing, the fact that the p-value is > 0.05 (and that the 95% CI includes zero) means that we are not sure if the null hypothesis is true.

As for your concrete case, you cannot construct a test where the alternative hypothesis is that the mean difference is $0$ and the null hypothesis is anything other than zero.  This violates the logic of hypothesis testing.  It is perfectly reasonable that it is your substantive, scientific hypothesis, but it cannot be your alternative hypothesis in a hypothesis testing situation.  

So what can you do?  In this situation, you use equivalence testing.  (You might want to read through some of our threads on this topic by clicking on the equivalence tag.)  The typical strategy is to use the two one sided tests approach.  Very briefly, you select an interval within which you would consider that the true mean difference might as well be $0$ for all you could care, then you perform a one-sided test to determine if the observed value is less than the upper bound of that interval, and another one-sided test to see if it is greater than the lower bound.  If both of these tests are significant, then you have rejected the hypothesis that the true value is outside the interval you care about.  If one (or both) are non-significant, you fail to reject the hypothesis that the true value is outside the interval.  

For example, suppose anything within the interval $(-0.02,\ 0.02)$ is so close to zero that you think it is essentially the same as zero for your purposes, so you use that as your substantive hypothesis.  Now imagine that you get the first result described above.  Although $0.01$ falls within that interval, you would not be able to reject the null hypothesis on either one-sided t-test, so you would fail to reject the null hypothesis.  On the other hand, imagine that you got the second result described above.  Now you find that the observed value falls within the designated interval, and it can be shown to be both less than the upper bound and greater than the lower bound, so you can reject the null.  (It is worth noting that you can reject both the hypothesis that the true value is $0$, and the hypothesis that the true value lies outside of the interval $(-0.02,\ 0.02)$, which may seem perplexing at first, but is fully consistent with the logic of hypothesis testing.)  
