[R] Calculating & plotting a linear regression between two correlated variables

JulieV sharkette002 at hotmail.com
Sun Jan 22 21:31:19 CET 2012


Hi,
I have a Community (COM) composed of 6 species: A, B, C, D, E & F.
The density of my Community is thus (Eq.1): dCOM = dA + dB + dC + dE + dF

I would like to calculate and plot a linear regression between the density
of each of my species and the density of the whole community (illustrating
how the density of each species varies with variations of the whole
community).
For example, I would like to plot dA = a * dCOM + b, with a and b the slope
and intercept of the regression.

The problem is that dA and dCOM are correlated because dA contributes to
values of dCOM (see Eq.1 above), and thus I'm probably not allowed to use a
"simple" linear regression (because parametric statistics do not allow for
correlated observations).

>From what I red (eg, www.ats.ucla.edu/stat/r/faq/spatial_regression.htm),
Linear Mixed Models allow for correlated observations by adding a correction
to the values. The webpage also says that  we can use the correlation option
in the lme function (nlme package) to find the type of correction to be
used, but I can’t figure out how to do this for my dataset.  

Can someone help me please ?
You will find an example of my dataset below (density of species A [dA] and
density of the whole community [dCOM]) and my R script.


Example from my dataset:
dA	dCOM
0.611	0.73
0.474	0.669
0.203	0.388
0.011	0.213
0.407	0.722
0.148	0.437
0.084	0.281
0	0.054
0.402	0.93
0.044	0.285
0.011	0.147
0	0.091
0.547	0.767
0.559	0.699
0.321	0.441
0.084	0.262
0.428	0.761
0.234	0.398
0.019	0.191
0	0.053
0.302	0.509
0.06	0.213
0.045	0.184
0.033	0.118
0.374	0.585
0.256	0.5
0.22	0.401
0.136	0.275
0.503	0.684
0.48	0.617
0.257	0.387
0.038	0.159
0.382	0.611
0.192	0.393
0.047	0.243
0.036	0.188

R script for this example:

dummy <- rep(1,36)  #  grouping variable in our data
model1 <- lme(fixed = dA ~ dCOM, data = bb1, random = ~ 1 | dCOM/dummy,
correlation= ?,method = "ML")

Thank you very much.

Julie.


--
View this message in context: http://r.789695.n4.nabble.com/Calculating-plotting-a-linear-regression-between-two-correlated-variables-tp4319051p4319051.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list