You will have to talk to your local statistician/econometrician. Given that
you say you will have three observations per student, your description of
the data is incomplete. Therefore, it is impossible to tell what the right
approach would be. Assumed that all observations are independent, you would
fit fix3 as one dummy/factor variable (not fix1 or fix2), and then you would
test linear hypotheses for sums of certain coefficients against sums of
other coefficients in your case. Nested effects are what you can specify as
random effects, afaik; you don't fit them in fixed-effects analyses (rather
you would take the outlined linear-hypothesis approach).
 
As far as I can tell from your post, your understanding of the subject
matter is limited. As I said, you will have to get yourself an overview of
the topic and search for materials that explain a.) nested effects and b.)
the application of nested effects in R (e.g. with the nlme and lme4
libraries). So go ahead and put in the effort.
 
Daniel
 
ps: on a more general note, the R-help list is to help with the
implementation in R rather than statistical/econometric questions,
especially if these problems are extensive.
 
-------------------------
cuncta stricte discussurus
-------------------------
 

  _____  

Von: Jojo Ziggy [mailto:jojo.ziggy@yahoo.com] 
Gesendet: Saturday, September 05, 2009 2:14 PM
An: Daniel Malter
Betreff: Re: AW: [R] Nested Fixed Effects - basic questions


"Nesting would imply something like students nested
in class nested in school, where each student is only member of one class
and each class only member of one school."

Yes, I think this is actually what I have going on - I guess I did not
represent that correctly in the data table.

So... I gather my data shown properly as nested effects should actually look
more like:

fix1    fix2    fix3    response
0    0    0    16.596
0    0    0    16.564
0    0    1    22.665
0    0    1    22.801
0    1    2    16.000
0    1    2    15.930
0    1    3    21.739
0    1    3    21.628
1    2    4    16.260
1    2    4    16.128
1    2    5    22.969
1    2    5    23.245
1    3    6    14.687
1    3    6    14.635
1    3    7    22.954
1    3    7    23.345

In this case, how do I tell R that the effects are nested, as opposed to
unnested?  And how do I specify that they are fixed and not random effects?
Will it somehow know automatically?  

I will in the end have 3 observations for each "student" - so 24 datapoints
in this example.  Certainly nothing close to 160, however.

Thanks,
jojo


  _____  

From: Daniel Malter <daniel@umd.edu>
To: Jojo Ziggy <jojo.ziggy@yahoo.com>; r-help@r-project.org
Sent: Friday, September 4, 2009 4:37:14 PM
Subject: AW: [R] Nested Fixed Effects - basic questions

In R and experimental or mixed-model terminology, your lm model specifies
fixed effects. As long as each data row represents a unique subject, you are
fine with lm. If not, you have to account for the repeated measurement of
subjects and will need other methods (potentially involving random effects).
In your model, you perform a dummy variable OLS (ordinary least squares)
regression. Mixed-effects models that allow for a combination of fixed and
random effects or random-effects-only analyses are most prominently done
with Doug Bates's nlme or lme4 libraries (though, there are more libraries
that allow for mixed-effects modeling). Google for some manuals.

Further, your effects are not nested. If each row stands for a different
unit of observation (e.g., subject), and if subjects are randomized into
treatments fix1, fix2, and fix3, then you have a completely randomized
factorial design (CRF). Nesting would imply something like students nested
in class nested in school, where each student is only member of one class
and each class only member of one school. Then your fix columns should look
like (with 8 students nested in 4 classes nested in 2 schools):

fix1 fix2 fix3
1    1    1
2    1    1
3    2    1
4    2    1
5    3    2
6    3    2
7    4    2
8    4    2

Thus, your effects are really not nested (at least not for what you show us
as the data). What you can do to figure out whether not only fix1 and fix2
have an independent effect, but also whether fix1 and fix2 interact in their
effect on your response, you can include interaction effects. However, if
the data you provided is your entire dataset, you will likely overfit the
model and inflate the standard errors if you include all possible
interactions (eats up 4 degrees of freedom) along with the direct effects
and intercept (also 4 degrees of freedom), given that your provided data has
only 16 observations.

Example:
#Simulate data
fix1=rep(0:1,each=8)
fix2=rep(c(0,0,1,1),4)
fix3=rep(0:1,8)
e=rnorm(16)

#Dependent variable
y=-1*fix1+2*fix2+1*fix3-0.75*fix1*fix2+0.9*fix1*fix3-2*fix2*fix3+1.5*fix1*fi
x2*fix3+e

#Run regression and show output
reg0=lm(y~(fix1+fix2+fix3)^3) #all interactions up to three-way
summary(reg0) 
#note that this is not very insightful with so few observations

#Same as above, just with a 10-times larger simulated dataset
fix1=rep(0:1,each=80)
fix2=rep(c(0,0,1,1),40)
fix3=rep(0:1,80)
e=rnorm(160)
y=-1*fix1+2*fix2+1*fix3-0.75*fix1*fix2+0.9*fix1*fix3-2*fix2*fix3+1.5*fix1*fi
x2*fix3+e
reg1=lm(y~(fix1+fix2+fix3)^3)
summary(reg1) 
#160 observations works quite well already
#coef estimates are within the margin of error of the true coefficients 

The second example shows that the approach to use OLS to model your data is
fine if your error distribution (the distribution of e in the simulated
data) is normal..

Daniel

-------------------------
cuncta stricte discussurus
-------------------------

-----Ursprüngliche Nachricht-----
Von: r-help-bounces@r-project.org [mailto:r-help-bounces@r-project.org] Im
Auftrag von Jojo Ziggy
Gesendet: Friday, September 04, 2009 1:17 PM
An: r-help@r-project.org
Betreff: [R] Nested Fixed Effects - basic questions

Hi R people,

I have a very basic question to ask - I'm sorry if it's been asked before,
but I searched the archives and could not find an answer..  All the examples
I found were much more complicated/nuanced versions of the problem - my
question is much more simple.

I have data with multiple, nested fixed effects (as I understand it, fixed
effects are specified by the experimental design while random effects are
measured) and one continuous response variable.  All the fixed effects are
catagorical.  

e.g.
fix1    fix2    fix3    response
0    0    0    16.260
0    0    0    16.128
0    0    1    22.969
0    0    1    23.245
0    1    0    14.687
0    1    0    14.635
0    1    1    22.954
0    1    1    23.345
1    0    0    19..866
1    0    0    19.589
1    0    1    22.748
1    0    1    22.817
1    1    0    17.861
1    1    0    17.872
1    1    1    22.925
1    1    1    23.138

I was thinking I could use a linear model to determine whether any of the
nested fixed effects or their interactions effect the response, but I could
not determine how to specify whether effects were fixed or random, and how
to specify nesting.  

For example:
lm(response~ fix1+fix2+fix3)

The above, as I understand it, simply asks whether the effects fix1 through
fix4 have an effect on the response.  However, in reality my experimental
design has multiple levels of nesting:

fix1(fix2(fix3(fix4)))

So, how do I do this?  To specify nesting, do I need to use another type of
model such as lmer or glm? 

I also don't know whether the above example is specifying whether the
effects are fixed or random - how do I do this?

Thanks very much,
Jojo



      
    [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




	[[alternative HTML version deleted]]


