[R] offset in gam

2011-03-30 Thread Lucia Rueda
Hi, we are modelling dusky grouper distribution using underwater visual
census. Our response variable is the abundance of groupers but we want to
see differences in habitat related to maturity because dusky groupers use
different habitats when they're juveniles versus adults. So we're using the
% of maturity.

ie 1 individual that is 50cm TL gets aprox 0.5 (50% chances to be mature and
50% to be inmature) and so on. If we have let's say another grouper that is
40 cm TL it will have a probability for example 0.7 to be inmature so for
our transect we will have a total of 0.7 +0.5= 1.2 for 2 individuals. 

We're using the Poisson distribution because our data is not overdispersed
and it's not normal. But we don't know what offset we should include. Would
it be the area of the transect? all transects have the same area, 90 m2. Or
should it be the total abundance of groupers per transect? in the example
offset=2

Thanks a lot in adavance

Lucia

--
View this message in context: 
http://r.789695.n4.nabble.com/offset-in-gam-tp3417491p3417491.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


[R] color code in loop for piecharts plotting

2011-02-25 Thread Lucia Rueda

Hi,
I am using this loop

par(mfrow=c(3,3))  
annos<-c(2001:2007,2009)
for (i in annos) {  
t<-subset(masia,YEAR==i)
t$FAMILIA<-drop.levels(t$FAMILIA)
pie(table(t$FAMILIA),main=i)
  }  

To make piecharts of species composition among years (my data frame is
called "masia"). So I get 1 piechart of the families that we have found in
our survey each year. We don't have always the same families every year so I
added  t$FAMILIA<-drop.levels(t$FAMILIA) 
to the loop to avoid having those family levels that aren't there in some
specific years in the pie

The problem is that the color code changes and I get for example different
colors for the same families in different years.

If I group those families that I have less individuals together in a
category called "others" and I make a new column called "familia2" with
fewer levels so that every year I have all levels of familia2 in my species
composition I don't get the problem and all families have the same color
among years.

Does anybody know how to avoid the color code change for the families in the
loop. I know I can do it manually and give each family a color but I have
quite a lot of families so I'm wondering if there's any way to fix that some
other way.

I don't know if I made myself clear...

Thanks!

Lucia
-- 
View this message in context: 
http://r.789695.n4.nabble.com/color-code-in-loop-for-piecharts-plotting-tp3324196p3324196.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] reshape data, adding rows to dataframe

2011-02-02 Thread Lucia Rueda

Thanks Henrique!

It solves the problem of having the column "N" with unreal number of
individuals since N=1

with Petr's example:

expand <- transform(dat[rep(1:nrow(dat), times=dat$N), ] ,N=1)
rownames(expand) <- NULL 
expand
> expand
  animal N
1  a 1
2  a 1
3  b 1
4  c 1
5  c 1
6  c 1

Cheers! 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/reshape-data-adding-rows-to-dataframe-tp3253640p3254038.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] reshape data, adding rows to dataframe

2011-02-02 Thread Lucia Rueda

Exactly!! Thanks a lot Petr. It worked!

Thansk to you as well Ivan!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/reshape-data-adding-rows-to-dataframe-tp3253640p3253793.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] reshape data, adding rows to dataframe

2011-02-02 Thread Lucia Rueda

Hi Ivan,

Thanks for your reply. This is what I want to do:

Imagine my dataset looks like this:

Species N  Size
Coris julis 1   8
Coris julis 3   10
D.vulgaris  2   12

I have 1 C.julis of 8 cm, 3 C. julis of 10 cm and 2 D.vulgaris of 12 cm. I
want 1 row for each animal, something like this:

Species N   Size
Coris julis 1   8
Coris julis 1   10
Coris julis 1   10
Coris julis 1   10
D.vulgaris  1   12
D.vulgaris  1   12

I hope that helps. I tried reshape but couldn't do it and from what I've
seen I don't think that aggregate, unique or duplicated would do it... but
I'm not good with R so I can be wrong.

Cheers!

Lucia


-- 
View this message in context: 
http://r.789695.n4.nabble.com/reshape-data-adding-rows-to-dataframe-tp3253640p3253780.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


[R] reshape data, adding rows to dataframe

2011-02-02 Thread Lucia Rueda

Hello everyone,

I have a data set like this:

> head( fish_transect)
  ID_TRANSECT ID_PROJECT   DE_ZONE DE_LOCALITY DE_SECTOR MES
1  42 MB TarragonaCreixell Control I   9
2  42 MB TarragonaCreixell Control I   9
3  42 MB TarragonaCreixell Control I   9
4  42 MB TarragonaCreixell Control I   9
5  42 MB TarragonaCreixell Control I   9
6  42 MB TarragonaCreixell Control I   9
   ID_SPECIES WEIGHT  SIZE   NFAMILIA
1 Spondyliosoma cantharus15.64 10 1Sparidae
2  Symphodus melanocercus  11.21 10  1   Labridae
3   Diplodus vulgaris 30.20 10  2   Sparidae
4   Diplodus vulgaris 52.24 12  2   Sparidae
5 Diplodus sargus221.4114 5Sparidae
6  Diplodus annularis 3.47   6  1Sparidae

I have been trying to duplicate the rows where N> 1, that is I want a row
for each animal. Right now as you can see I have for example 5 D. sargus
which are 14 cm length and so on. How can I get 1 row for each animal? I've
been trying the reshape function without success. I also tried in access but
couldn't do it either.

Thanks a lot,

Lucia



-- 
View this message in context: 
http://r.789695.n4.nabble.com/reshape-data-adding-rows-to-dataframe-tp3253640p3253640.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Odp: count of factors

2011-01-19 Thread Lucia Rueda

Thanks a lot Petr!! It worked! 

-- 
View this message in context: 
http://r.789695.n4.nabble.com/count-of-factors-tp3224791p3224924.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


[R] count of factors

2011-01-19 Thread Lucia Rueda

Hello everyone,

I have a data set like this:

> head( fish_transect)
  ID_TRANSECT ID_PROJECT   DE_ZONE DE_LOCALITY DE_SECTOR MES
1  42 MB TarragonaCreixell Control I   9
2  42 MB TarragonaCreixell Control I   9
3  42 MB TarragonaCreixell Control I   9
4  42 MB TarragonaCreixell Control I   9
5  42 MB TarragonaCreixell Control I   9
6  42 MB TarragonaCreixell Control I   9
   ID_SPECIES WEIGHT  SIZE   NFAMILIA
1 Spondyliosoma cantharus15.64 10 1Sparidae
2  Symphodus melanocercus  11.21 10  1   Labridae
3   Diplodus vulgaris 30.20 10  2   Sparidae
4   Diplodus vulgaris 52.24 12  2   Sparidae
5 Diplodus sargus221.4114 5Sparidae
6  Diplodus annularis 3.47   6  1Sparidae

The table function of the column FAMILIA gives:
Apogonidae Atherinidae   Blennidae  BlenniidaeBothidae 
216   1 406   2 
11 
 Carangidae Centracanthidae   Congridae Gadidae
Gobidae 
 25   4  21   2
214 
 HaemulidaeLabridae   MugilidaeMullidae 
Muraenidae 
 256381  10 965 
45 
   Myliobatidae  Sciaenidae  ScombridaeScorpaenidae 
Serranidae 
  2 159   1 512   
2127 
   SparidaeSphyraenidaeSynodontidaeTorpedinidae
Trachinidae 
   6196   5   1   1  
1 
  Tripterygidae 
135

I want to add a new column "familia2" where those families with low number
of individuals are listed as "other", that is, for these families
Atherinidae  BlenniidaeBothidae  Carangidae Centracanthidae 
  1   2  11  25  
4 
  Congridae Gadidae  Haemulidae   Mugilidae 
Muraenidae 
 21   2  25  10 
45 
   Myliobatidae  ScombridaeSphyraenidaeSynodontidae   
Torpedinidae 
  2   1   5   1  
1 
Trachinidae 
  1

I want them in column "familia2" to be named "others"

I've been trying to do a loop telling R to write "others" when the sum of
FAMILIA was less than 50, but it didn't work because FAMILIA is a factor,
and there isn't a "count" function (or I didn't find it). I also tried other
options like the "match" function, "level" function, etc. I know I can do it
manually typing by myself the names of the 16 families but I want to learn a
way to do where I don't need to type the names.

Thanks in advance!

Lucia


-- 
View this message in context: 
http://r.789695.n4.nabble.com/count-of-factors-tp3224791p3224791.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] offset in gam and spatial scale of variables

2010-05-20 Thread Lucia Rueda

Hi,

Thanks for the inputs. I talked to my coworker, who has been the one doing
the analysis. Perhaps I wasn't making myself clear about the “differences in
spatial scales”.  Here is what he says:

"The truth is that measuring scales (i.e all area related variable are
measured in m2) and spatial definition of initial cartography are
homogeneous among extracted variables. But all variables (ie. sum of the
total rocky bottom in the surrounding area) are computed for each different
integration areas (buffer) (i.e in an area of 40squaremeters around the
sample, in an area of 80m2, …).
The question is then if we can build a model that includes variables
measured at different buffers (for example a model that includes 3
variables:  1.-  the amount of rocky bottom in an area of 80m2 ; 2- the
amount of sandy bottom in an area of 200m2; and the mean depth calculated in
a surrounding area of 50m2) considering that each variable may be expressing
different ecological processes. I believe that if there is not an ecological
constrain in the interpretation of the variables (and their ecological
effect over the specie), including them in a model is correct, unless there
is not a mathematical constrain."

Also, about the spatial correlation I thought from what I've read so far
that I had to build the model and then check if there was spatial
correlation in the residuals since they are supposed to be i.i.d. And if it
turns out that they are then I have to do something about it like gamm, gee,
sar, car, etc.

Cheers,

Lucia


-- 
View this message in context: 
http://r.789695.n4.nabble.com/offset-in-gam-and-spatial-scale-of-variables-tp483p2224528.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] offset in gam and spatial scale of variables

2010-05-19 Thread Lucia Rueda

Hi Joris,

We're using mgcv. 

We have data on abundance of groupers on line transects that have the same
legth. My coworker has selected a bunch of variables and he has calculated
them in terms of total area in different sizes of buffers around the
centroid of the transect. He has run gam models (quasipoisson, mgcv) for
each explanatory variable at each size of buffer. Then he has selected the
signifficant variables. Some variables explain a higher percentage of
deviance at different sizes of buffers. And now he wants to build a gam
model trying the different explanatory variables but using the values that
correspond to the size of the buffer where they explain a higher deviance,
so one variable might have the values of a smaller scale whereas other might
correspond to a higher buffer size (I don't know if I made myself clear). I
am wondering if this is correct. 

Also I don't know if he should include an offset in spite all the transects
have the same length. 

I'm in charge of looking at the spatial correlation once he builds the
model. I don't know much about it but I was thinking of doing a Moran test,
correlogram and variogram and then if there's spatial autocorrelation doing
gamm, sar or gee. 

Thanks,

Lucia 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/offset-in-gam-and-spatial-scale-of-variables-tp483p976.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


[R] offset in gam and spatial scale of variables

2010-05-19 Thread Lucia Rueda

Hi,

We are analizing the relationship between the abundance of groupers in line
transects and some variables. We are using the quasipoisson distribution. Do
we need to include the length of the transects as an offset if they all have
the same length?? 

Also, can we include in the gam models variables that are measured at
different spatial scales? We have done an analysis to see what variables are
better for different sizes of buffers around the transect lines and some
variables are better at different scales. Can we run the gam model with
several explanatory variables if they are measured at different spatial
scales?

Thanks,

Lucia
-- 
View this message in context: 
http://r.789695.n4.nabble.com/offset-in-gam-and-spatial-scale-of-variables-tp483p483.html
Sent from the R help mailing list archive at Nabble.com.

__
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.