[R-sig-eco] Organizing Data for Bootstrap ANOVA

2011-05-16 Thread Jane Shevtsov
How would you go about using boot() and boot.ci() to perform a one-way
ANOVA? I have a hand-coded, bootstrap-based function, but my main
question concerns organizing the raw data, so the problem may be
similar to using the aov() function. In doing a two-group comparison,
you concatenate the two data vectors and make a data frame with an
index. What do you do for ANOVA?

Thanks,
Jane Shevtsov

-- 
-
Jane Shevtsov
Ecology Ph.D. candidate, University of Georgia
co-founder, 
Check out my blog, <http://perceivingwholes.blogspot.com>Perceiving Wholes

"In the long run, education intended to produce a molecular
geneticist, a systems ecologist, or an immunologist is inferior, both
for the individual and for society, than that intended to produce a
broadly educated person who has also written a dissertation." --John
Janovy, Jr., "On Becoming a Biologist"

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


[R-sig-eco] Using rq() for least absolute deviation regression

2011-04-26 Thread Jane Shevtsov
I've seen several websites say that the function rq() from the package
quantreg can be used to do least absolute deviation regression. How do
you go about doing this and what's the connection between quantile
regression and LAD? (I'm very new to the former topic.)

Thanks,
Jane

-- 
-----
Jane Shevtsov
Ecology Ph.D. candidate, University of Georgia
co-founder, 
Check out my blog, <http://perceivingwholes.blogspot.com>Perceiving Wholes

"In the long run, education intended to produce a molecular
geneticist, a systems ecologist, or an immunologist is inferior, both
for the individual and for society, than that intended to produce a
broadly educated person who has also written a dissertation." --John
Janovy, Jr., "On Becoming a Biologist"

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


Re: [R-sig-eco] Linear Model of Data in Matrix Form

2011-04-03 Thread Jane Shevtsov
Thank you; that works!

Best,
Jane

On Sun, Apr 3, 2011 at 8:22 PM, Christian Roy  wrote:
> On Sun, Apr 3, 2011 at 11:05 PM, Jane Shevtsov  wrote:
>>
>> Thanks, but that doesn't quite work. Using your toy example gives an
>> error about variable lengths.
>>
>> > z <- matrix(1:9,nrow=3,dimnames=list(1:3,4:6))
>> > z.melt <- melt(z)
>> > z.melt
>>  X1 X2 value
>> 1  1  4     1
>> 2  2  4     2
>> 3  3  4     3
>> 4  1  5     4
>> 5  2  5     5
>> 6  3  5     6
>> 7  1  6     7
>> 8  2  6     8
>> 9  3  6     9
>> > lm(z ~ z.melt$X1 + z.melt$X2)
>
> In this example the syntax for your model is:
>> lm(z.melt$value ~ z.melt$X1 + z.melt$X2)
> Call:
> lm(formula = z.melt$value ~ z.melt$X1 + z.melt$X2)
> Coefficients:
> (Intercept)    z.melt$X1    z.melt$X2
>         -12            1            3
> Best,
> Chris
> ---
>>
>> Error in model.frame.default(formula = z ~ z.melt$X1 + z.melt$X2,
>> drop.unused.levels = TRUE) :
>>  variable lengths differ (found for 'z.melt$X1')
>> I'm using R 2.12.0 on Windows and just installed the reshape package.
>>
>> Jane
>>
>> On Sun, Apr 3, 2011 at 3:40 PM, Ben Bolker  wrote:
>> > -BEGIN PGP SIGNED MESSAGE-
>> > Hash: SHA1
>> >
>> > On 11-04-02 10:39 PM, Jane Shevtsov wrote:
>> >> I have data in matrix form from a parameter scan of a food web
>> >> simulation. (The matrix entry M[i,j] gives the variable of interest
>> >> for a web size i and connectance j.) How would I find an equation
>> >> expressing the variable of interest to web size and connectance? Can
>> >> lm() do it?
>> >>
>> >> Thanks,
>> >> Jane Shevtsov
>> >>
>> >
>> >  suppose your size and connectance vectors were sizevec and connvec.
>> > Then something like
>> >
>> > dimnames(M) <- list(sizevec,connvec)
>> > library(reshape)
>> > X <- melt(M)
>> > lm(value~X1+X2)
>> >
>> >  will do it.
>> >
>> >  Mini example:
>> >
>> >> z <- matrix(1:9,nrow=3,dimnames=list(1:3,4:6))
>> >> library(reshape)
>> > Loading required package: plyr
>> >
>> > Attaching package: 'reshape'
>> >
>> > The following object(s) are masked from 'package:plyr':
>> >
>> >    round_any
>> >
>> >> str(melt(z))
>> > 'data.frame':   9 obs. of  3 variables:
>> >  $ X1   : int  1 2 3 1 2 3 1 2 3
>> >  $ X2   : int  4 4 4 5 5 5 6 6 6
>> >  $ value: int  1 2 3 4 5 6 7 8 9
>> > -BEGIN PGP SIGNATURE-
>> > Version: GnuPG v1.4.10 (GNU/Linux)
>> > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>> >
>> > iEYEARECAAYFAk2Y90MACgkQc5UpGjwzenOmPQCdFAOGcxnzADXZNv9ikgDzJcPQ
>> > 3/IAn1ayn1HVOQOdlqFDPoq+Et6rR5nt
>> > =cfIQ
>> > -END PGP SIGNATURE-
>> >
>> > ___
>> > R-sig-ecology mailing list
>> > R-sig-ecology@r-project.org
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>> >
>>
>>
>>
>> --
>> -
>> Jane Shevtsov
>> Ecology Ph.D. candidate, University of Georgia
>> co-founder, 
>> Check out my blog, <http://perceivingwholes.blogspot.com>Perceiving Wholes
>>
>> "In the long run, education intended to produce a molecular
>> geneticist, a systems ecologist, or an immunologist is inferior, both
>> for the individual and for society, than that intended to produce a
>> broadly educated person who has also written a dissertation." --John
>> Janovy, Jr., "On Becoming a Biologist"
>>
>> ___
>> R-sig-ecology mailing list
>> R-sig-ecology@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
>
>
> --
> Christian Roy, Biol. Msc.
> Étudiant au Doctorat / Phd Student
> courriel: christian.roy...@ulaval.ca
> Université Laval, Faculté de foresterie, de géographie et de géomatique
>



-- 
-
Jane Shevtsov
Ecology Ph.D. candidate, University of Georgia
co-founder, 
Check out my blog, <http://perceivingwholes.blogspot.com>Perceiving Wholes

"In the long run, education intended to produce a molecular
geneticist, a systems ecologist, or an immunologist is inferior, both
for the individual and for society, than that intended to produce a
broadly educated person who has also written a dissertation." --John
Janovy, Jr., "On Becoming a Biologist"

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


Re: [R-sig-eco] Linear Model of Data in Matrix Form

2011-04-03 Thread Jane Shevtsov
Thanks, but that doesn't quite work. Using your toy example gives an
error about variable lengths.

> z <- matrix(1:9,nrow=3,dimnames=list(1:3,4:6))
> z.melt <- melt(z)
> z.melt
  X1 X2 value
1  1  4 1
2  2  4 2
3  3  4 3
4  1  5 4
5  2  5 5
6  3  5 6
7  1  6 7
8  2  6 8
9  3  6 9
> lm(z ~ z.melt$X1 + z.melt$X2)
Error in model.frame.default(formula = z ~ z.melt$X1 + z.melt$X2,
drop.unused.levels = TRUE) :
  variable lengths differ (found for 'z.melt$X1')

I'm using R 2.12.0 on Windows and just installed the reshape package.

Jane

On Sun, Apr 3, 2011 at 3:40 PM, Ben Bolker  wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> On 11-04-02 10:39 PM, Jane Shevtsov wrote:
>> I have data in matrix form from a parameter scan of a food web
>> simulation. (The matrix entry M[i,j] gives the variable of interest
>> for a web size i and connectance j.) How would I find an equation
>> expressing the variable of interest to web size and connectance? Can
>> lm() do it?
>>
>> Thanks,
>> Jane Shevtsov
>>
>
>  suppose your size and connectance vectors were sizevec and connvec.
> Then something like
>
> dimnames(M) <- list(sizevec,connvec)
> library(reshape)
> X <- melt(M)
> lm(value~X1+X2)
>
>  will do it.
>
>  Mini example:
>
>> z <- matrix(1:9,nrow=3,dimnames=list(1:3,4:6))
>> library(reshape)
> Loading required package: plyr
>
> Attaching package: 'reshape'
>
> The following object(s) are masked from 'package:plyr':
>
>    round_any
>
>> str(melt(z))
> 'data.frame':   9 obs. of  3 variables:
>  $ X1   : int  1 2 3 1 2 3 1 2 3
>  $ X2   : int  4 4 4 5 5 5 6 6 6
>  $ value: int  1 2 3 4 5 6 7 8 9
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk2Y90MACgkQc5UpGjwzenOmPQCdFAOGcxnzADXZNv9ikgDzJcPQ
> 3/IAn1ayn1HVOQOdlqFDPoq+Et6rR5nt
> =cfIQ
> -END PGP SIGNATURE-
>
> ___
> R-sig-ecology mailing list
> R-sig-ecology@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



-- 
-
Jane Shevtsov
Ecology Ph.D. candidate, University of Georgia
co-founder, 
Check out my blog, <http://perceivingwholes.blogspot.com>Perceiving Wholes

"In the long run, education intended to produce a molecular
geneticist, a systems ecologist, or an immunologist is inferior, both
for the individual and for society, than that intended to produce a
broadly educated person who has also written a dissertation." --John
Janovy, Jr., "On Becoming a Biologist"

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


[R-sig-eco] Linear Model of Data in Matrix Form

2011-04-02 Thread Jane Shevtsov
I have data in matrix form from a parameter scan of a food web
simulation. (The matrix entry M[i,j] gives the variable of interest
for a web size i and connectance j.) How would I find an equation
expressing the variable of interest to web size and connectance? Can
lm() do it?

Thanks,
Jane Shevtsov

-- 
-
Jane Shevtsov
Ecology Ph.D. candidate, University of Georgia
co-founder, 
Check out my blog, <http://perceivingwholes.blogspot.com>Perceiving Wholes

"In the long run, education intended to produce a molecular
geneticist, a systems ecologist, or an immunologist is inferior, both
for the individual and for society, than that intended to produce a
broadly educated person who has also written a dissertation." --John
Janovy, Jr., "On Becoming a Biologist"

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


[R-sig-eco] Positioning color key in heatmap

2011-02-27 Thread Jane Shevtsov
This is probably really basic, but I'm drawing a heatmap using the
heatmap.2() function from gplots and want to place the color key along
the left side of the plot. How do I do that?

Thanks,
Jane Shevtsov

-- 
-
Jane Shevtsov
Ecology Ph.D. candidate, University of Georgia
co-founder, 
Check out my blog, <http://perceivingwholes.blogspot.com>Perceiving Wholes

"In the long run, education intended to produce a molecular
geneticist, a systems ecologist, or an immunologist is inferior, both
for the individual and for society, than that intended to produce a
broadly educated person who has also written a dissertation." --John
Janovy, Jr., "On Becoming a Biologist"

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


Re: [R-sig-eco] lines() adds extra line

2011-01-24 Thread Jane Shevtsov
Thanks; that works!

Best,
Jane

On Mon, Jan 24, 2011 at 10:15 AM, Sarah Goslee  wrote:
> R is doing just as you asked. If you look at the middle of c(x, x) the
> x values jump from 10 to -10 and R draws the line segment connecting
> them, as it's been told.
>
>> c(x,x)[195:205]
>  [1]   9.4   9.5   9.6   9.7   9.8   9.9  10.0 -10.0  -9.9  -9.8  -9.7
>
> You might rather have:
>> x2.rev <- c(x, rev(x))
>> x.rev.pred <- predict(lm(dataBoth.poly ~ x2.rev + 
>> I(x2.rev^2)+I(x2.rev^3)+I(x2.rev^4)+I(x2.rev^5)+I(x2.rev^6)))
>> plot(x2.rev, x.rev.pred, type="l")
>
> Sarah
>
>
> On Mon, Jan 24, 2011 at 1:04 PM, Jane Shevtsov  wrote:
>> I'm trying a bit of an experiment with polynomial curve fitting (don't
>> worry, I wouldn't do this to actual data -- it's just a toy model for
>> a specific question). When I generate a linear model of the data and
>> plot it using plot(), everything works fine. But when I use plot(...,
>> type="l") or lines(), I get an extra line connecting two points. How
>> do I stop this from happening?
>>
>> Here's the code:
>> x = seq(-10, 10, by=0.1)
>> data1poly <- 0.1*x + 0.2*x^2 + 0.3*x^3 + 0.4*x^4 + 0.5*x^5 + 0.6*x^6 +
>> 0.7 + rnorm(length(x),1E-3, 1E-4)
>> data2poly <- 0.1*x + 0.2*x^2 + 0.3*x^3 + 0.4*x^4 + 0.5*x^5 + 0.6*x^6 -
>> 1 + rnorm(length(x), 1E-3, 1E-4)
>> dataBoth.poly <- c(data1poly, data2poly)
>> #Works well
>> plot(c(x,x), predict(lm(dataBoth.poly ~ c(x,x) +
>> I(c(x,x)^2)+I(c(x,x)^3)+I(c(x,x)^4)+I(c(x,x)^5)+I(c(x,x)^6
>> #Adds extra line
>> plot(c(x,x), predict(lm(dataBoth.poly ~ c(x,x) +
>> I(c(x,x)^2)+I(c(x,x)^3)+I(c(x,x)^4)+I(c(x,x)^5)+I(c(x,x)^6))),
>> type="l")  #or
>> lines(c(x,x), predict(lm(dataBoth.poly ~ c(x,x) +
>> I(c(x,x)^2)+I(c(x,x)^3)+I(c(x,x)^4)+I(c(x,x)^5)+I(c(x,x)^6
>>
>> Thanks,
>> Jane
>>
>> --
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>



-- 
-
Jane Shevtsov
Ecology Ph.D. candidate, University of Georgia
co-founder, 
Check out my blog, <http://perceivingwholes.blogspot.com>Perceiving Wholes

"The whole person must have both the humility to nurture the
Earth and the pride to go to Mars." --Wyn Wachhorst, The Dream
of Spaceflight

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


[R-sig-eco] lines() adds extra line

2011-01-24 Thread Jane Shevtsov
I'm trying a bit of an experiment with polynomial curve fitting (don't
worry, I wouldn't do this to actual data -- it's just a toy model for
a specific question). When I generate a linear model of the data and
plot it using plot(), everything works fine. But when I use plot(...,
type="l") or lines(), I get an extra line connecting two points. How
do I stop this from happening?

Here's the code:
x = seq(-10, 10, by=0.1)
data1poly <- 0.1*x + 0.2*x^2 + 0.3*x^3 + 0.4*x^4 + 0.5*x^5 + 0.6*x^6 +
0.7 + rnorm(length(x),1E-3, 1E-4)
data2poly <- 0.1*x + 0.2*x^2 + 0.3*x^3 + 0.4*x^4 + 0.5*x^5 + 0.6*x^6 -
1 + rnorm(length(x), 1E-3, 1E-4)
dataBoth.poly <- c(data1poly, data2poly)
#Works well
plot(c(x,x), predict(lm(dataBoth.poly ~ c(x,x) +
I(c(x,x)^2)+I(c(x,x)^3)+I(c(x,x)^4)+I(c(x,x)^5)+I(c(x,x)^6
#Adds extra line
plot(c(x,x), predict(lm(dataBoth.poly ~ c(x,x) +
I(c(x,x)^2)+I(c(x,x)^3)+I(c(x,x)^4)+I(c(x,x)^5)+I(c(x,x)^6))),
type="l")  #or
lines(c(x,x), predict(lm(dataBoth.poly ~ c(x,x) +
I(c(x,x)^2)+I(c(x,x)^3)+I(c(x,x)^4)+I(c(x,x)^5)+I(c(x,x)^6

Thanks,
Jane

-- 
-
Jane Shevtsov
Ecology Ph.D. candidate, University of Georgia
co-founder, 
Check out my blog, <http://perceivingwholes.blogspot.com>Perceiving Wholes

"The whole person must have both the humility to nurture the
Earth and the pride to go to Mars." --Wyn Wachhorst, The Dream
of Spaceflight

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


[R-sig-eco] Stochastic Model Gives Deterministic Output

2010-12-24 Thread Jane Shevtsov
I'm using R 2.10.1 (running on Ubuntu) to implement a simple null
model. The model (code below) assigns species to plots by shuffling
the numbers 1-# of plots and assigning the species to the first N
plots in the resulting vector, where N is the number of plots at which
the species was found in real life. The code works fine, except for
one problem -- different runs give exactly the same results! (Each
matrix is different, but matrix 1 of run 1 is identical to matrix 1 of
run 2.) How do I fix this? Is it possible to get R to use the time as
the seed for random number generation?

Thanks,
Jane Shevtsov

#input: vector of species occurences, # of iterations, #plots at site

nullModel.spsite <- function(occ, iter, plots) {
spp <- length(occ)
#Allocate array for co-occurrence frequencies of each species pair.
sitespArr <- array(0, c(spp, plots, iter))
#Pre-allocate other stuff
sitesp <- array(0, c(plots, spp)) #Preserve matrix orientation to
minimize recoding; transpose later
order <- array(0, plots)

for (i in 1:iter) {
#Zero out site-sp matrix
sitesp <- array(0, c(plots, spp))
for (j in 1:spp) {
#Randomly shuffle plots
order <- sample(1:plots, plots, replace=FALSE)
#Put sp i in first k (# plots where species i occurs) 
plots
according to order vector
sitesp[order[1:occ[j]], j] = 1
}
sitespArr[,,i] = t(sitesp)
}
return(sitespArr)   
}



-- 
-
Jane Shevtsov
Ecology Ph.D. candidate, University of Georgia
co-founder, 
Check out my blog, <http://perceivingwholes.blogspot.com>Perceiving Wholes

"The whole person must have both the humility to nurture the
Earth and the pride to go to Mars." --Wyn Wachhorst, The Dream
of Spaceflight

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


[R-sig-eco] p-Function for Empirical Distributions

2010-09-03 Thread Jane Shevtsov
Does R have a p-function for empirical distributions? In other words,
how can I find out what fraction of the values in my data set are
smaller than a given value?

-- 
-
Jane Shevtsov
Ecology Ph.D. candidate, University of Georgia
co-founder, 
Check out my blog, <http://perceivingwholes.blogspot.com>Perceiving Wholes

"The whole person must have both the humility to nurture the
Earth and the pride to go to Mars." --Wyn Wachhorst, The Dream
of Spaceflight

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology