[R] row sum with all absence in a presence-absence matrix

2013-10-08 Thread Elaine Kuo
Dear list



I have a matrix composed of islandID as rows and speciesID as columns.

IslandID: Island A, B, C….O (15 islands in total)

SpeciesID: D0001, D0002, D0003….D0100 (100 species in total)



The cell of the matrix describes presence (1) or absence (0) of the species
in an island.



Now I would like to search how many species are found in (1, presence) for
Island A, Island D, and Island L respectively.



Please kindly advise the R code for the search purpose.

Thank you.

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


[R] Compare species presence and absence between sites

2013-09-27 Thread Elaine Kuo
Dear List,



I want to compare the presence and absence of bird species based on the
sites in a matrix.

The matrix has 5 rows for Island A, B, C, D, and E.

It has 100 columns for bird species D001-D100.

In each cell of the matrix,

the presence-absence of bird species will be recorded as 1 or 0.

(For example, if species D001 is found on Island D,

the matrix cell of species D001 and Island D will be 1.)



Now I want to know the different bird species between Island B and E.

In other words, I would like to find out bird species present (1) on Island
B but absent (0)on island E, and vice versa (absent (0) on Island B but
present (1)on island E).



Please kindly advise how to code the purpose above.

Thank you in advance.



Elaine

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


Re: [R] Compare species presence and absence between sites

2013-09-27 Thread Elaine Kuo
Thanks Rui and Arun.
Both worked well.

One more question, what shall I add for Rui's code if only the comparison
of TRUE (no FALSE) to be shown in the result?

Elaine

code
different - function(x, y) x == 1  y == 0

set.seed(7054)
mat - matrix(sample(0:1, 500, TRUE), nrow = 5)
rownames(mat) - LETTERS[1:5]
colnames(mat) - sprintf(D%03d, 1:100)

different(mat[B,], mat[E,])


On Fri, Sep 27, 2013 at 9:31 PM, arun smartpink...@yahoo.com wrote:

 Just to add:

 If you wanted the difference of every combination of rows:
 set.seed(248)
  mat1-
 matrix(sample(0:1,5*100,replace=TRUE),ncol=100,dimnames=list(LETTERS[1:5],paste0(D,sprintf(%03d,1:100)))
 )
  dat-expand.grid(LETTERS[1:5],LETTERS[1:5],stringsAsFactors=FALSE)
 dat1-dat[!paste0(dat[,1],dat[,2]) %in% paste0(LETTERS[1:5],LETTERS[1:5]),]
  lst1- lapply(seq_len(nrow(dat1)),function(i)
 {x-mat1[unlist(dat1[i,]),]; which(different(x[1,],x[2,]))}) #using Rui's
 function
 names(lst1)- paste(dat1[,1],dat1[,2],sep=_)


 A.K.



 - Original Message -
 From: Rui Barradas ruipbarra...@sapo.pt
 To: Elaine Kuo elaine.kuo...@gmail.com
 Cc: r-help@r-project.org r-help@r-project.org
 Sent: Friday, September 27, 2013 7:39 AM
 Subject: Re: [R] Compare species presence and absence between sites

 Hello,

 Something like this?


 different - function(x, y) x == 1  y == 0

 set.seed(7054)
 mat - matrix(sample(0:1, 500, TRUE), nrow = 5)
 rownames(mat) - LETTERS[1:5]
 colnames(mat) - sprintf(D%03d, 1:100)

 different(mat[B,], mat[E,])



 Hope this helps,

 Rui Barradas

 Em 27-09-2013 11:48, Elaine Kuo escreveu:
  Dear List,
 
 
 
  I want to compare the presence and absence of bird species based on the
  sites in a matrix.
 
  The matrix has 5 rows for Island A, B, C, D, and E.
 
  It has 100 columns for bird species D001-D100.
 
  In each cell of the matrix,
 
  the presence-absence of bird species will be recorded as 1 or 0.
 
  (For example, if species D001 is found on Island D,
 
  the matrix cell of species D001 and Island D will be 1.)
 
 
 
  Now I want to know the different bird species between Island B and E.
 
  In other words, I would like to find out bird species present (1) on
 Island
  B but absent (0)on island E, and vice versa (absent (0) on Island B but
  present (1)on island E).
 
 
 
  Please kindly advise how to code the purpose above.
 
  Thank you in advance.
 
 
 
  Elaine
 
  [[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.
 

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

__
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] search species with all absence in a presence-absence matrix

2013-09-20 Thread Elaine Kuo
Dear list



I have a matrix composed of islandID as rows and speciesID as columns.

IslandID: Island A, B, C….O (15 islands in total)

SpeciesID: D0001, D0002, D0003….D0100 (100 species in total)



The cell of the matrix describes presence (1) or absence (0) of the species
in an island.



Now I would like to search the species with absence (0)

in all the islands (Island A to Island O.)



Please kindly advise the R code for the search purpose.

Thank you.



Elaine

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


[R] to retrieve specific data from a matrix

2013-09-11 Thread Elaine Kuo
Dear list,

I want to retrieve a specific data from a matrix with 3000 columns.
The matrix has island ID as its rows and species ID as its columns.
There are 20 rows and 3000 columns in the matrix.
(Island ID: Species 1- Species 20/ species ID: Species 1- Species 3000)
The contents of the matrix grids is 1 or 0, for presence and absence.

Now I would like to check in Island 1 which species is 1. (Island 1 as row
2)
Please kindly advise how to code the command and thank you in advance.

Elaine

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


Re: [R] merge matrix row data

2013-08-01 Thread Elaine Kuo
Hello arun

Thanks for the answers.
I understand the answer to question 2.
However, about question 1, sorry I did not clarify the question.

1. If the row names are 1, 2, and 4 etc (numbers) instead of GID 1, GID 2,
and GID 3,
   is there any modification in need for the code ?
   The original data looks like below.

Original matrix

GID   D0989   D9820  D5629  D4327  D2134

1   100   1  0

2   011   0  0

4   001   0  0

5   110   0  0

7   010   0  1



Resulting matrix

D0989   D9820  D5629  D4327  D2134

Island A   11   0   1   0

Island B   01   1   0   1


Elaine


On Thu, Aug 1, 2013 at 7:15 AM, arun smartpink...@yahoo.com wrote:

 Hi Elaine,

 In that case:
 Do you have GID in the IslandA and IslandBs?

 IslandA-c(GID 1, GID 5)
 IslandB- c(GID 2, GID 4, GID 7)

 If there is no change in the two Islands, then using the same dataset:

 mat1- as.matrix(read.table(text=
 D0989  D9820  D5629  D4327  D2134
 GID_1100  1  0
 GID_2011  0  0
 GID_4001  0  0
 GID_5110  0  0
 GID_7010  0  1
 ,sep=,header=TRUE))

 row.names(mat1)- gsub(.*\\_,,row.names(mat1)) #to replace the GID_
 from the row.names()
  mat1
 #  D0989 D9820 D5629 D4327 D2134
 #1 1 0 0 1 0
 #2 0 1 1 0 0
 #4 0 0 1 0 0
 #5 1 1 0 0 0
 #7 0 1 0 0 1
  IslandA-c(GID 1, GID 5)
  IslandB- c(GID 2, GID 4, GID 7)
 res-t(sapply(c(IslandA,IslandB),function(x) {x1-
 mat1[match(gsub(.*\\s+,,get(x)),row.names(mat1)),];(!!colSums(x1))*1}))
 res
  #   D0989 D9820 D5629 D4327 D2134
 #IslandA 1 1 0 1 0
 #IslandB 0 1 1 0 1


 Regarding the use of !!colSums()
 You can check these:

  t(sapply(c(IslandA,IslandB),function(x) {x1-
 mat1[match(gsub(.*\\s+,,get(x)),row.names(mat1)),];!colSums(x1)}))
 #D0989 D9820 D5629 D4327 D2134
 #IslandA FALSE FALSE  TRUE FALSE  TRUE
 #IslandB  TRUE FALSE FALSE  TRUE FALSE

 t(sapply(c(IslandA,IslandB),function(x) {x1-
 mat1[match(gsub(.*\\s+,,get(x)),row.names(mat1)),];!!colSums(x1)}))
 #D0989 D9820 D5629 D4327 D2134
 #IslandA  TRUE  TRUE FALSE  TRUE FALSE
 #IslandB FALSE  TRUE  TRUE FALSE  TRUE

 # *1 will replace TRUE with 1 and FALSE with 0.

 A.K.






 
 From: Elaine Kuo elaine.kuo...@gmail.com
 To: arun smartpink...@yahoo.com
 Sent: Wednesday, July 31, 2013 6:58 PM
 Subject: Re: [R] merge matrix row data



 Dear Arun,

 Thank you for the clear explanation.
 The row.names question is a mistyping, for I do not have enough sleep last
 night.

 Two more questions

 1. If the row names are 1, 2, and 4 etc (numbers) instead of GID 1, GID 2,
 and GID 3,
is there any modification in need for the code ?

 2. Please kindly explain the code
 (!!colSums(x1))*1}

It is the critical part to merge the row data.

 Thanks again.

 Elaine



 On Thu, Aug 1, 2013 at 6:45 AM, arun smartpink...@yahoo.com wrote:

 Dear Elaine,
 
 I used that line only because you didn't provide the data using dput().
 So, I need to either use delimiter  , or just leave a space by first
 joining the GID and the numbers using _.  I chose the latter as I
 didn't had that much time to spent by putting , between each entries.
 After that, I removed _ using the ?gsub().  As Bert pointed out, there
 are many online resources for understanding regular expression.
 
 In this particular case, what I did was to single out the _ in the
 first pair of quotes, and replace with  space in the second pair of quotes
  .  Therefore, GID_1, would become GID 1, which is what your original
 dataset looks like.
 
 If you type row.names(mat1) on the R console and enter, you will be able
 to get the output.
 
 Hope it helps.
 Arun
 
 
 
 
 
 
 
 
 
 From: Elaine Kuo elaine.kuo...@gmail.com
 To: arun smartpink...@yahoo.com
 Cc: R help r-help@r-project.org
 Sent: Wednesday, July 31, 2013 5:07 PM
 Subject: Re: [R] merge matrix row data
 
 
 
 
 Dear Arun
 
 Thank you for the very useful help.
 However, please kindly explain the code below.
 row.names(mat1)- gsub([_], ,row.names(mat1))
 
 
 1. what does [_] mean?
 2. what doesmean?
 3. what does row.names(mat1) mean?
 
 I checked ?gsub but still did not get the idea.
 
 Thank you again
 
 Elaine
 
 
 
 On Wed, Jul 31, 2013 at 9:35 PM, arun smartpink...@yahoo.com wrote:
 
 HI,
 
 Please use ?dput()
 mat1- as.matrix(read.table(text=
 
 D0989  D9820  D5629  D4327  D2134
 GID_1100  1  0
 GID_2011  0  0
 GID_4001  0  0
 GID_5110  0

Re: [R] merge matrix row data

2013-08-01 Thread Elaine Kuo
Hello Arun

Thank for comments.

You are right. GID is the first column in the matrix this time.

In the second row of the first column, it used to be GID 1 in the first
e-mail.
But you are also right. You answered it already, and  this time In the
second row of the first column is 1.
Below is part of dput()(too many columns)

.. .Names = c(GID,
D5291, D5293, D7414, D7415, D7416, D7417, D7418,
D7419, D7420, D7421, D7422, D7423, D7424, D7425,
D7426, D7427, D7428, D7429, D7430, D7431, D7432,
D7433, D7434, D7435, D7436, D7437, D7438, D7439,
D7440, D7441, D7442, D7443, D7444, D7445, D7446,

Elaine


On Thu, Aug 1, 2013 at 12:35 PM, arun smartpink...@yahoo.com wrote:



 Hi Elaine,
 I am not sure how your original matrix keeps on changing from the
 original post.  Here, your statement about rownames are 1, 2, 4 (the answer
 I already provided in the last post) and the matrix you showed looks
 different.  It seems like GID is the first column in the matrix.  I
 requested you to dput() the data to reduce these confusions.

 mat1-as.matrix(read.table(text=
 GID   D0989   D9820  D5629  D4327  D2134
 1   100   1  0
 2   011   0  0
 4   001   0  0
 5   110   0  0
 7   010   0  1
 ,sep=,header=TRUE))
 IslandA-c(GID 1, GID 5)
 IslandB- c(GID 2, GID 4, GID
 7)t(sapply(c(IslandA,IslandB),function(x) {x1-
 mat1[match(gsub(.*\\s+,,get(x)),mat1[,1]),-1];(!!colSums(x1))*1}))
 #D0989 D9820 D5629 D4327 D2134
 #IslandA 1 1 0 1 0
 #IslandB 0 1 1 0 1
 A.K.





 
 From: Elaine Kuo elaine.kuo...@gmail.com
 To: arun smartpink...@yahoo.com
 Cc: R help r-help@r-project.org
 Sent: Thursday, August 1, 2013 12:00 AM
 Subject: Re: [R] merge matrix row data



 Hello arun

 Thanks for the answers.
 I understand the answer to question 2.
 However, about question 1, sorry I did not clarify the question.

 1. If the row names are 1, 2, and 4 etc (numbers) instead of GID 1, GID 2,
 and GID 3,
is there any modification in need for the code ?
The original data looks like below.

 Original matrix
 GID   D0989   D9820  D5629  D4327  D2134
 1   100   1  0
 2   011   0  0
 4   001   0  0
 5   110   0  0
 7   010   0  1

 Resulting matrix
 D0989   D9820  D5629  D4327  D2134
 Island A   11   0   1   0
 Island B   01   1   0   1

 Elaine



 On Thu, Aug 1, 2013 at 7:15 AM, arun smartpink...@yahoo.com wrote:

 Hi Elaine,
 
 In that case:
 Do you have GID in the IslandA and IslandBs?
 
 
 IslandA-c(GID 1, GID 5)
 IslandB- c(GID 2, GID 4, GID 7)
 
 If there is no change in the two Islands, then using the same dataset:
 
 
 mat1- as.matrix(read.table(text=
 D0989  D9820  D5629  D4327  D2134
 GID_1100  1  0
 GID_2011  0  0
 GID_4001  0  0
 GID_5110  0  0
 GID_7010  0  1
 ,sep=,header=TRUE))
 
 row.names(mat1)- gsub(.*\\_,,row.names(mat1)) #to replace the GID_
 from the row.names()
  mat1
 
 #  D0989 D9820 D5629 D4327 D2134
 
 #1 1 0 0 1 0
 #2 0 1 1 0 0
 
 #4 0 0 1 0 0
 
 #5 1 1 0 0 0
 
 #7 0 1 0 0 1
 
  IslandA-c(GID 1, GID 5)
  IslandB- c(GID 2, GID 4, GID 7)
 res-t(sapply(c(IslandA,IslandB),function(x) {x1-
 mat1[match(gsub(.*\\s+,,get(x)),row.names(mat1)),];(!!colSums(x1))*1}))
 
 res
  #   D0989 D9820 D5629 D4327 D2134
 #IslandA 1 1 0 1 0
 #IslandB 0 1 1 0 1
 
 
 Regarding the use of !!colSums()
 You can check these:
 
  t(sapply(c(IslandA,IslandB),function(x) {x1-
 mat1[match(gsub(.*\\s+,,get(x)),row.names(mat1)),];!colSums(x1)}))
 
 #D0989 D9820 D5629 D4327 D2134
 #IslandA FALSE FALSE  TRUE FALSE  TRUE
 #IslandB  TRUE FALSE FALSE  TRUE FALSE
 
 t(sapply(c(IslandA,IslandB),function(x) {x1-
 mat1[match(gsub(.*\\s+,,get(x)),row.names(mat1)),];!!colSums(x1)}))
 
 #D0989 D9820 D5629 D4327 D2134
 #IslandA  TRUE  TRUE FALSE  TRUE FALSE
 #IslandB FALSE  TRUE  TRUE FALSE  TRUE
 
 # *1 will replace TRUE with 1 and FALSE with 0.
 
 A.K.
 
 
 
 
 
 
 
 
 From: Elaine Kuo elaine.kuo...@gmail.com
 To: arun smartpink...@yahoo.com
 Sent: Wednesday, July 31, 2013 6:58 PM
 
 Subject: Re: [R] merge matrix row data
 
 
 
 Dear Arun,
 
 Thank you for the clear explanation.
 The row.names question is a mistyping, for I do not have enough sleep
 last night.
 
 Two more questions
 
 1. If the row names are 1, 2, and 4 etc (numbers) instead

Re: [R] merge matrix row data

2013-08-01 Thread Elaine Kuo
Hello arun

I modified your code a little bit but failed to retrieve the row.names.

The response is NULL.

Please kindly help and thanks.

Elaine


Code

load(h:/b_W_line/R_workspace/dataset_Residence_2748.RData)

  dim(dataR)

  str(dataR)

  dataR.m- as.matrix(dataR, header=TRUE)

  dataR.m[,1]

  row.names(dataR.m)


dput(dataR.m)

.skipped...0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,

0L, 0L, 0L, 0L, 0L), .Dim = c(4873L, 14L), .Dimnames = list(NULL,

c(GID, D0407, D0409, D0410, D0462, D0463, D0473,

D0475, D0488, D0489, D0492, D0493, D0504, D0536

)))


On Thu, Aug 1, 2013 at 1:24 PM, Elaine Kuo elaine.kuo...@gmail.com wrote:

 Hello Arun

 Thank for comments.

 You are right. GID is the first column in the matrix this time.

 In the second row of the first column, it used to be GID 1 in the first
 e-mail.
 But you are also right. You answered it already, and  this time In the
 second row of the first column is 1.
 Below is part of dput()(too many columns)

 .. .Names = c(GID,
 D5291, D5293, D7414, D7415, D7416, D7417, D7418,
 D7419, D7420, D7421, D7422, D7423, D7424, D7425,
 D7426, D7427, D7428, D7429, D7430, D7431, D7432,
 D7433, D7434, D7435, D7436, D7437, D7438, D7439,
 D7440, D7441, D7442, D7443, D7444, D7445, D7446,
 
 Elaine


 On Thu, Aug 1, 2013 at 12:35 PM, arun smartpink...@yahoo.com wrote:



 Hi Elaine,
 I am not sure how your original matrix keeps on changing from the
 original post.  Here, your statement about rownames are 1, 2, 4 (the answer
 I already provided in the last post) and the matrix you showed looks
 different.  It seems like GID is the first column in the matrix.  I
 requested you to dput() the data to reduce these confusions.

 mat1-as.matrix(read.table(text=
 GID   D0989   D9820  D5629  D4327  D2134
 1   100   1  0
 2   011   0  0
 4   001   0  0
 5   110   0  0
 7   010   0  1
 ,sep=,header=TRUE))
 IslandA-c(GID 1, GID 5)
 IslandB- c(GID 2, GID 4, GID
 7)t(sapply(c(IslandA,IslandB),function(x) {x1-
 mat1[match(gsub(.*\\s+,,get(x)),mat1[,1]),-1];(!!colSums(x1))*1}))
 #D0989 D9820 D5629 D4327 D2134
 #IslandA 1 1 0 1 0
 #IslandB 0 1 1 0 1
 A.K.





 
 From: Elaine Kuo elaine.kuo...@gmail.com
 To: arun smartpink...@yahoo.com
 Cc: R help r-help@r-project.org
 Sent: Thursday, August 1, 2013 12:00 AM
 Subject: Re: [R] merge matrix row data



 Hello arun

 Thanks for the answers.
 I understand the answer to question 2.
 However, about question 1, sorry I did not clarify the question.

 1. If the row names are 1, 2, and 4 etc (numbers) instead of GID 1, GID
 2, and GID 3,
is there any modification in need for the code ?
The original data looks like below.

 Original matrix
 GID   D0989   D9820  D5629  D4327  D2134
 1   100   1  0
 2   011   0  0
 4   001   0  0
 5   110   0  0
 7   010   0  1

 Resulting matrix
 D0989   D9820  D5629  D4327  D2134
 Island A   11   0   1   0
 Island B   01   1   0   1

 Elaine



 On Thu, Aug 1, 2013 at 7:15 AM, arun smartpink...@yahoo.com wrote:

 Hi Elaine,
 
 In that case:
 Do you have GID in the IslandA and IslandBs?
 
 
 IslandA-c(GID 1, GID 5)
 IslandB- c(GID 2, GID 4, GID 7)
 
 If there is no change in the two Islands, then using the same dataset:
 
 
 mat1- as.matrix(read.table(text=
 D0989  D9820  D5629  D4327  D2134
 GID_1100  1  0
 GID_2011  0  0
 GID_4001  0  0
 GID_5110  0  0
 GID_7010  0  1
 ,sep=,header=TRUE))
 
 row.names(mat1)- gsub(.*\\_,,row.names(mat1)) #to replace the
 GID_ from the row.names()
  mat1
 
 #  D0989 D9820 D5629 D4327 D2134
 
 #1 1 0 0 1 0
 #2 0 1 1 0 0
 
 #4 0 0 1 0 0
 
 #5 1 1 0 0 0
 
 #7 0 1 0 0 1
 
  IslandA-c(GID 1, GID 5)
  IslandB- c(GID 2, GID 4, GID 7)
 res-t(sapply(c(IslandA,IslandB),function(x) {x1-
 mat1[match(gsub(.*\\s+,,get(x)),row.names(mat1)),];(!!colSums(x1))*1}))
 
 res
  #   D0989 D9820 D5629 D4327 D2134
 #IslandA 1 1 0 1 0
 #IslandB 0 1 1 0 1
 
 
 Regarding the use of !!colSums()
 You can check these:
 
  t(sapply(c(IslandA,IslandB),function(x) {x1-
 mat1[match(gsub(.*\\s+,,get(x)),row.names(mat1)),];!colSums(x1)}))
 
 #D0989 D9820 D5629 D4327 D2134
 #IslandA FALSE FALSE  TRUE FALSE  TRUE
 #IslandB  TRUE FALSE FALSE  TRUE FALSE
 
 t(sapply(c(IslandA,IslandB),function(x) {x1-
 mat1[match

[R] merge matrix row data

2013-07-31 Thread Elaine Kuo
Dear list,



I have a matrix showing the species presence-absence on a map.

Its rows are map locations, represented by GridCellID, such as GID1 and GID
5.

Its columns are species ID, such as D0989, D9820, and D5629.

The matrix is as followed.



Now I want to merge the GridCellID according to the map location of each
island.

For instance, Island A consist of GID 1 and 5. Island B consist of GID 2,
4, and 7.

In GID 1 and 5, species D0989 are both 1.

Then I want to merge GID 1 and 5 into Island A, with species D0989 as 1.

The original matrix and the resulting matrix are listed below.

Please kindly advise how to code the calculation in R.

Please do not hesitate to ask if anything is unclear.

Thank you in advance.



Elaine



Original matrix

D0989   D9820  D5629  D4327  D2134

GID 1100   1  0

GID 2011   0  0

GID 4001   0  0

GID 5110   0  0

GID 7010   0  1



Resulting matrix

D0989   D9820  D5629  D4327  D2134

Island A   11   0   1   0

Island B   01   1   0   1

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


Re: [R] merge matrix row data

2013-07-31 Thread Elaine Kuo
Dear Arun

Thank you for the very useful help.
However, please kindly explain the code below.
row.names(mat1)- gsub([_], ,row.names(mat1))

1. what does [_] mean?
2. what doesmean?
3. what does row.names(mat1) mean?

I checked ?gsub but still did not get the idea.

Thank you again

Elaine


On Wed, Jul 31, 2013 at 9:35 PM, arun smartpink...@yahoo.com wrote:

 HI,

 Please use ?dput()
 mat1- as.matrix(read.table(text=
 D0989  D9820  D5629  D4327  D2134
 GID_1100  1  0
 GID_2011  0  0
 GID_4001  0  0
 GID_5110  0  0
 GID_7010  0  1
 ,sep=,header=TRUE))
 row.names(mat1)- gsub([_], ,row.names(mat1))
 IslandA-c(GID 1, GID 5)
 IslandB- c(GID 2, GID 4, GID 7)
  res-  t(sapply(c(IslandA,IslandB),function(x)
 {x1-mat1[match(get(x),row.names(mat1)),];(!!colSums(x1))*1} ))

  res
 #D0989 D9820 D5629 D4327 D2134
 #IslandA 1 1 0 1 0
 #IslandB 0 1 1 0 1
 A.K.




 - Original Message -
 From: Elaine Kuo elaine.kuo...@gmail.com
 To: r-h...@stat.math.ethz.ch r-h...@stat.math.ethz.ch
 Cc:
 Sent: Wednesday, July 31, 2013 9:03 AM
 Subject: [R] merge matrix row data

 Dear list,



 I have a matrix showing the species presence-absence on a map.

 Its rows are map locations, represented by GridCellID, such as GID1 and GID
 5.

 Its columns are species ID, such as D0989, D9820, and D5629.

 The matrix is as followed.



 Now I want to merge the GridCellID according to the map location of each
 island.

 For instance, Island A consist of GID 1 and 5. Island B consist of GID 2,
 4, and 7.

 In GID 1 and 5, species D0989 are both 1.

 Then I want to merge GID 1 and 5 into Island A, with species D0989 as 1.

 The original matrix and the resulting matrix are listed below.

 Please kindly advise how to code the calculation in R.

 Please do not hesitate to ask if anything is unclear.

 Thank you in advance.



 Elaine



 Original matrix

 D0989   D9820  D5629  D4327  D2134

 GID 1100   1  0

 GID 2011   0  0

 GID 4001   0  0

 GID 5110   0  0

 GID 7010   0  1



 Resulting matrix

 D0989   D9820  D5629  D4327  D2134

 Island A   11   0   1   0

 Island B   01   1   0   1

 [[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]]

__
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] [R-sig-eco] extract beta.sim from dist type data (package betapart)

2013-07-19 Thread Elaine Kuo
Hello Sarah,

Thank you for the help very much.

Please kindly advise manuals dealing with the object list (or dist).
In addition, I would like to show the beta diversity index in a map.
Please kindly advise any other R package in need.

Elaine


On Wed, Jul 17, 2013 at 10:20 PM, Sarah Goslee sarah.gos...@gmail.comwrote:

 Replied to on the R-sig-ecology list, with a request not to cross-post.

 Briefly, the output is a list with named components, so can be
 extracted as usual.

 Sarah

 On Wed, Jul 17, 2013 at 5:50 AM, Elaine Kuo elaine.kuo...@gmail.com
 wrote:
  Dear List,
 
  This is Elaine.
  I am using beta.part to calculate the beta diversity index.
  The function of beta.part can generate three kinds of beta diversity
 indice
  at one time.
  However, it is Simpson index that I want.
 
  The calculation result is composed of three rows and N/A columns (dist
  class).
  I do not know how to extract one of the indice in the form of dist class.
  No relevant example is found the manual.
  (I tried as.vector as below but failed.)
 
  Please kindly help and thank you in advance.
 
  Elaine
 
  Code
   library(betapart)
dist.sim-beta.pair(dataR, index.family=sor)
 
  # Unfold distance matrices into vectors
data.sim-data.frame(as.vector(dist.sim))
 
 --
 Sarah Goslee
 http://www.functionaldiversity.org

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

__
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] how to calculate the average values of each row in a matrix

2013-07-19 Thread Elaine Kuo
Hello,

I have a matrix (class matrix) composed of GridCell (row and column).
The matrix value is the beta diversity index value between two grids.

Now I would like to get the average value of each GridCell.
Please kindly advise how to make the calculation.
Thank you.

Elaine

The matrix looks like (cited from Michael Friendly)
I would like to get the average value of each color.


  Obs  stim   RPur   Red   Yel   Gy1   Gy2  Green  Blue  BlP  Pur1
 Pur2

  1  RPur . . . . .  . .
 . . .
  2  Red11.5. . . .  . .
 . . .
  3  Yel13.1   6.0. . .  . .
 . . .
  4  Gy112.6   7.9   6.2. .  . .
 . . .
  5  Gy210.6   8.4   8.4   5.2.  . .
 . . .
  6  Green  10.6   9.4   9.9   6.5   4.1 . .
 . . .
  7  Blue   10.8  10.2  10.3   8.8   7.06.4.
 . . .
   8  BlP 7.3  11.3  12.7  11.2  10.49.9   4.2
  . . .
   9  Pur15.4  11.5  12.9  11.7  10.89.4   8.4
 4.5. .
  10  Pur25.0  11.5  10.7  10.2  10.6   10.1   8.1
 6.43 .

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


[R] extract beta.sim from dist type data (package betapart)

2013-07-17 Thread Elaine Kuo
Dear List,

This is Elaine.
I am using beta.part to calculate the beta diversity index.
The function of beta.part can generate three kinds of beta diversity indice
at one time.
However, it is Simpson index that I want.

The calculation result is composed of three rows and N/A columns (dist
class).
I do not know how to extract one of the indice in the form of dist class.
No relevant example is found the manual.
(I tried as.vector as below but failed.)

Please kindly help and thank you in advance.

Elaine

Code
 library(betapart)
  dist.sim-beta.pair(dataR, index.family=sor)

# Unfold distance matrices into vectors
  data.sim-data.frame(as.vector(dist.sim))

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


Re: [R] error of betadiver in vegan

2013-07-12 Thread Elaine Kuo
Hello,

Thanks for Jari's comment.
It worked well after correction.
However, an error jumped out for the code below.
Error: cannot allocate vector of size 90.6 Mb

Please kindly advise how to modify it.
Thank you.

Elaine

Code
# Non-Passerine table
dataNP_1 -read.dbf(H:/temp_D/stage_4_R_2748/NP_1-10.dbf, as.is = FALSE)
dataNP_2 -read.dbf(H:/temp_D/stage_4_R_2748/NP_11-19.dbf, as.is = FALSE)
dataNP-merge(dataNP_1,dataNP_2,by=c(GID),all=T)

.. skip...

# Non-Passerine and Passerine table (2748 species)
dataR-merge(dataP,dataNP,by=c(GID),all=T)
dim(dataR)
str(dataR)

library(vegan)

  ##  The  beta sim  index (Lennon 2001)
  d  -  betadiver(dataR,  sim)


On Fri, Jul 12, 2013 at 2:13 PM, Jari Oksanen jari.oksa...@oulu.fi wrote:

 Elaine Kuo elaine.kuo.tw at gmail.com writes:

 
  Hello,
 
  I am using betadiver (vegan) to calculate beta diversity.
  However, an error message shows
 
  Error in ifelse(x  0, 1, 0) :
(list) object cannot be coerced to type 'double'
 ...snip...

##  Raw  data
R  -  betadiver(dataR)
 
##  The  indices
betadiver(help=TRUE)
 
##  The  beta sim  index (Lennon 2001)
d  -  betadiver(R,  sim)
 
 Elaine,

 Look carefully what you do here: betadiver needs data as input -- not beta
 diversities. Your last command is equal to this oneliner:

 d - betadiver(betadiver(dataR), sim)

 This is guaranteed to fail. Use instead

 d - betadiver(dataR, sim)

 Cheers, Jari Oksanen

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

__
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] memory problem of betadiver of vegan

2013-07-12 Thread Elaine Kuo
Hello List,

This is Elaine.
I am running betadiver for a dataset of 4873 rows and 2749 columns.
(4873 rows = 4873 gridcell of the study region and 2749 columns for the
bird species)
The dataset was produced by combing 5 dbf.

When running the code o, an error message jumped out, saying
Error: cannot allocate vector of size 90.6 Mb

I posted the issue in r-help and checked the previous mails about R memory
problems.
gc() and save .Rdata were tried but did not work.
Also, I tried to transformed the dataset into a matrix, using the code m
below.
However, an error also appeared, saying
Error in ifelse(x  0, 1, 0) :
  (list) object cannot be coerced to type 'double'.

Please kindly advise how to alleviate the memory problem, particularly in
modifying the code of betadiver of vegan.
Thank you.

Elaine

code m
matrixR-matrix(data = dataR, nrow = 4873, ncol = 2749)
d  -  betadiver(matrixR,  sim)



code o
# Non-Passerine table
dataNP_1 -read.dbf(H:/temp_D/stage_4_R_2748/NP_1-10.dbf, as.is = FALSE)
dataNP_2 -read.dbf(H:/temp_D/stage_4_R_2748/NP_11-19.dbf, as.is = FALSE)
dataNP-merge(dataNP_1,dataNP_2,by=c(GID),all=T)

.. skip...

# Non-Passerine and Passerine table (2748 species)
dataR-merge(dataP,dataNP,by=c(GID),all=T)
dim(dataR)
str(dataR)

library(vegan)

  ##  The  beta sim  index (Lennon 2001)
  d  -  betadiver(dataR,  sim)

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


Re: [R] memory problem of betadiver of vegan

2013-07-12 Thread Elaine Kuo
Hello List,

I solved the problem by using the code with 31 votes
http://stackoverflow.com/questions/1358003/tricks-to-manage-the-available-memory-in-an-r-session


On Sat, Jul 13, 2013 at 6:15 AM, Elaine Kuo elaine.kuo...@gmail.com wrote:

 Hello List,

 This is Elaine.
 I am running betadiver for a dataset of 4873 rows and 2749 columns.
 (4873 rows = 4873 gridcell of the study region and 2749 columns for the
 bird species)
 The dataset was produced by combing 5 dbf.

 When running the code o, an error message jumped out, saying
 Error: cannot allocate vector of size 90.6 Mb

 I posted the issue in r-help and checked the previous mails about R memory
 problems.
 gc() and save .Rdata were tried but did not work.
 Also, I tried to transformed the dataset into a matrix, using the code m
 below.
 However, an error also appeared, saying
 Error in ifelse(x  0, 1, 0) :
   (list) object cannot be coerced to type 'double'.

 Please kindly advise how to alleviate the memory problem, particularly in
 modifying the code of betadiver of vegan.
 Thank you.

 Elaine

 code m
 matrixR-matrix(data = dataR, nrow = 4873, ncol = 2749)
 d  -  betadiver(matrixR,  sim)



 code o
 # Non-Passerine table
 dataNP_1 -read.dbf(H:/temp_D/stage_4_R_2748/NP_1-10.dbf, as.is = FALSE)
 dataNP_2 -read.dbf(H:/temp_D/stage_4_R_2748/NP_11-19.dbf, as.is =
 FALSE)
 dataNP-merge(dataNP_1,dataNP_2,by=c(GID),all=T)

 .. skip...

 # Non-Passerine and Passerine table (2748 species)
 dataR-merge(dataP,dataNP,by=c(GID),all=T)
 dim(dataR)
 str(dataR)

 library(vegan)

   ##  The  beta sim  index (Lennon 2001)
   d  -  betadiver(dataR,  sim)


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


[R] error of betadiver in vegan

2013-07-11 Thread Elaine Kuo
Hello,

I am using betadiver (vegan) to calculate beta diversity.
However, an error message shows

Error in ifelse(x  0, 1, 0) :
  (list) object cannot be coerced to type 'double'


R version: 3.0.0

Please kindly advise how to solve the issue.
Also, please kindly tell if any more information is in need.
Thank you.

Elaine


code
# Non-Passerine table
dataNP_1 -read.dbf(H:/temp_D/stage_4_R_2748/NP_1-10.dbf, as.is = FALSE)
dataNP_2 -read.dbf(H:/temp_D/stage_4_R_2748/NP_11-19.dbf, as.is = FALSE)
dataNP-merge(dataNP_1,dataNP_2,by=c(GID),all=T)

.. skip...

# Non-Passerine and Passerine table (2748 species)
dataR-merge(dataP,dataNP,by=c(GID),all=T)
dim(dataR)
str(dataR)

library(vegan)

  ##  Raw  data
  R  -  betadiver(dataR)

  ##  The  indices
  betadiver(help=TRUE)

  ##  The  beta sim  index (Lennon 2001)
  d  -  betadiver(R,  sim)

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


[R] pearson correlation significant level

2013-05-17 Thread Elaine Kuo
Hello

I am using package Hmisc to calculate the pearson correlation and the
significant level for the matrix of t_i and t_r. (temperature minimum and
temperature range)

However, I have difficulty interpreting the result, even after checking the
manual.
Please kindly help to indicate if the p-value is zero.
Thank you in advance.
Elaine

The code
 library(Hmisc)
 rcorr(as.matrix(datat), type=pearson) # type can be pearson or spearman


The result is
 t_i   t_r
t_i  1.00 -0.89
t_r -0.89  1.00

n= 4873


P
t_i t_r
t_i  0
t_r  0



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


Re: [R] R package for bootstrapping (comparing two quadratic regression models)

2013-05-06 Thread Elaine Kuo
Thanks Jean.
Y1 = observed value
Y2= estimated value

Elaine


On Mon, May 6, 2013 at 9:22 PM, Adams, Jean jvad...@usgs.gov wrote:

 Elaine,

 I suggest that you consult with a statistician to see if it even makes
 sense to compare the two models you describe.  The first model makes sense
 to me, the second one does not.  Isn't y2 in the second equation equal to
 the estimated y1 from the first equation?  You need to talk with someone
 about what you have, where it came from, and what questions you are trying
 to answer.

 Jean


 On Fri, May 3, 2013 at 6:08 PM, Elaine Kuo elaine.kuo...@gmail.comwrote:

 Hello ,

 I want to compare two quadratic regression models with non-parametric
 bootstrap.
 However, I do not know which R package can serve the purpose,
 such as boot, rms, or bootstrap, DeltaR.
 Please kindly advise and thank you.

 Elaine

 The two quadratic regression models are

 y1=a1x^2+b1x+c1

 y1= observed migration distance of butterflies()

 y2=a2x^2+b2x+c2

 y2= predicted migration distance of butterflies (based on body mass)

 x= body mass of butterflies


 null hypothesis: a1=a2 and b1=b2 and c1=c2

 bootstrap to test if the coeffients (a, b, c) of the y1 and the y2 model
 differ

 [[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]]

__
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] slope coefficient of a quadratic regression bootstrap

2013-05-05 Thread Elaine Kuo
Hello,

I want to know if two quadratic regressions are significantly different.
I was advised to make the test using
step 1 bootstrapping both quadratic regressions and get their slope
coefficients.
  (Let's call the slope coefficient *â*^1 and *â*^2)
step 2 use the slope difference *â*^1-*â*^2 and bootstrap the slope
coefficent
step 3   find out the sampling distribution above and calculate the % =0
step 4  multiple the % by 2

However, I am new to the package boot.
I wrote a code for step 1 and got a error message.

Please kindly advise how to modify it and thank you.

Elaine

code
require(boot)
function.fit2  -  function(data){
  #data  -  data[indices,]   #  select  obs.  in  bootstrap  sample
  fit2 -lm(logDIS~logBMN+I(logBMN^2))
  coefficients(fit2)   #  return  coefficient  vector
  }

boot.fit2  -  boot(dataN,  function.fit2,  1000)

error
 fit2.boot  -  boot(dataN,  fun.fit2,  1000)
Error in statistic(data, original, ...) : unused argument (original)

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


Re: [R] slope coefficient of a quadratic regression bootstrap

2013-05-05 Thread Elaine Kuo
Hello all,

I found the following code worked.

code
require(boot)
function.fit2  -  function(data,i){
  d  -  data[i,]   #  select  obs.  in  bootstrap  sample
  fit2 -lm(logDIS~logBMN+I(logBMN^2), data=dataN)
  coefficients(fit2)   #  return  coefficient  vector
  }

boot.fit2  -  boot(dataN,  function.fit2,  1000)



On Mon, May 6, 2013 at 7:36 AM, Elaine Kuo elaine.kuo...@gmail.com wrote:

 Hello,

 I want to know if two quadratic regressions are significantly different.
 I was advised to make the test using
 step 1 bootstrapping both quadratic regressions and get their slope
 coefficients.
   (Let's call the slope coefficient *â*^1 and *â*^2)
 step 2 use the slope difference *â*^1-*â*^2 and bootstrap the slope
 coefficent
 step 3   find out the sampling distribution above and calculate the % =0
 step 4  multiple the % by 2

 However, I am new to the package boot.
 I wrote a code for step 1 and got a error message.

 Please kindly advise how to modify it and thank you.

 Elaine

 code
 require(boot)
 function.fit2  -  function(data){
   #data  -  data[indices,]   #  select  obs.  in  bootstrap
  sample
   fit2 -lm(logDIS~logBMN+I(logBMN^2))
   coefficients(fit2)   #  return  coefficient  vector
   }

 boot.fit2  -  boot(dataN,  function.fit2,  1000)

 error
  fit2.boot  -  boot(dataN,  fun.fit2,  1000)
 Error in statistic(data, original, ...) : unused argument (original)



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


[R] compare two quadratic regression using bootstrap

2013-05-05 Thread Elaine Kuo
Hello,

I want to know if two quadratic regressions are significantly different.
I was advised to make the test using
step 1 bootstrapping both quadratic regressions and get their slope
coefficients.
  (Let's call the slope coefficient *â*^1 and *â*^2)
step 2 use the slope difference *â*^1-*â*^2 and bootstrap the slope
coefficent
step 3   find out the sampling distribution above and calculate the % =0
step 4  multiple the % by 2

However, I am new to the package boot.
I finished writing  code for step 1 as below.
Please kindly advise how to code step 2 and 3.
Thank you.

Elaine

code
require(boot)
function.fit2  -  function(data,i){
  d  -  data[i,]   #  select  obs.  in  bootstrap  sample
  fit2 -lm(logDIS~logBMN+I(logBMN^2), data=dataN)
  coefficients(fit2)   #  return  coefficient  vector
  }

boot.fit2  -  boot(dataN,  function.fit2,  1000)

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


Re: [R] significantly different from one (not zero) using lm

2013-05-04 Thread Elaine Kuo
Hello,

Thanks.
But the parameter offset is new to me.
Please kindly explain why setting offset to x will give a significant test
of whether the slope coefficient is different from one.
(I checked the ?lm but still do not understand it well)

Thanks again

Elaine


On Wed, May 1, 2013 at 11:12 AM, Thomas Lumley tlum...@uw.edu wrote:

 Or use an offset

 lm( y ~ x+offset(x), data = dat)

 The offset gives x a coefficient of 1, so the coefficient of x in this
 model is the difference between the coefficient of x in the model without
 an offset and 1 -- the thing you want.

 -thomas


 On Wed, May 1, 2013 at 2:54 PM, Paul Johnson pauljoh...@gmail.com wrote:

 It is easy to construct your own test. I test against null of 0 first so I
 can be sure I match the right result from summary.lm.

 ## get the standard error
 seofb - sqrt(diag(vcov(lm1)))
 ## calculate t. Replace 0 by your null
 myt - (coef(lm1) - 0)/seofb
 mypval - 2*pt(abs(myt), lower.tail = FALSE, df = lm1$df.residual)

 ## Note you can pass a vector of different nulls for the coefficients
 myt - (coef(lm1)  - c(0,1))/seofb

 We could write this into a function if we wanted to get busy.  Not a bad
 little homework exercise, I think.




  dat - data.frame(x = rnorm(100), y = rnorm(100))
  lm1 - lm(y ~ x, data = dat)
  summary(lm1)

 Call:
 lm(formula = y ~ x, data = dat)

 Residuals:
 Min  1Q  Median  3Q Max
 -3.0696 -0.5833  0.1351  0.7162  2.3229

 Coefficients:
  Estimate Std. Error t value Pr(|t|)
 (Intercept) -0.001499   0.104865  -0.0140.989
 x   -0.039324   0.113486  -0.3470.730

 Residual standard error: 1.024 on 98 degrees of freedom
 Multiple R-squared: 0.001224,Adjusted R-squared: -0.008968
 F-statistic: 0.1201 on 1 and 98 DF,  p-value: 0.7297

  seofb - sqrt(diag(vcov(lm1)))
  myt - (coef(lm1) - 0)/seofb
  mypval - 2*pt(abs(myt), lower.tail = FALSE, df = lm1$df.residual)
  myt
 (Intercept)   x
 -0.01429604 -0.34650900
  mypval
 (Intercept)   x
   0.9886229   0.7297031
  myt - (coef(lm1) - 1)/seofb
  mypval - 2*pt(abs(myt), lower.tail = FALSE, df = lm1$df.residual)
  myt
 (Intercept)   x
   -9.550359   -9.158166
  mypval
  (Intercept)x
 1.145542e-15 8.126553e-15


 On Tue, Apr 30, 2013 at 9:07 PM, Elaine Kuo elaine.kuo...@gmail.com
 wrote:

  Hello,
 
 
 
  I am work with a linear regression model:
 
  y=ax+b with the function of lm.
 
  y= observed migration distance of butterflies
 
  x= predicted migration distance of butterflies
 
 
 
  Usually the result will show
 
  if the linear term a is significantly different from zero based on the
  p-value.
 
  Now I would like to test if the linear term is significantly different
 from
  one.
 
  (because I want to know if the regression line (y=ax+b) is significantly
  from the line with the linear term =1 and the intercept =0)
 
 
 
  Please kindly advise if it is possible
 
  to adjust some default parameters in the function to achieve the goal.
 
  Thank you.
 
 
  Elaine
 
  [[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.
 



 --
 Paul E. Johnson
 Professor, Political Science  Assoc. Director
 1541 Lilac Lane, Room 504  Center for Research Methods
 University of Kansas University of Kansas
 http://pj.freefaculty.org   http://quant.ku.edu

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




 --
 Thomas Lumley
 Professor of Biostatistics
 University of Auckland


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


[R] significant test of two quadratic regression models (lm)

2013-05-03 Thread Elaine Kuo
Hello,

I am work with two quadratic regression models

y=ax^2+bx+c with the function of lm.

y1= observed migration distance of butterflies(y1=a1x^2+b1x+c1)

y2= predicted migration distance of butterflies (based on body mass)

(y2=a2x^2+b2x+c2)

x= body mass of butterflies


Now I would like to check the two regression model differ

by testing if the coeffients (a, b, c) of the y1 and the y2 model differ

(null hypothesis: a1=a2 and b1=b2 and c1=c2)


Please kindly advise any significant test in R for the purpose.

Also, please kindly advise how to apply Bonferroni procedure in the test if
necessary.

Thank you in advance.


Elaine

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


[R] R package for bootstrapping (comparing two quadratic regression models)

2013-05-03 Thread Elaine Kuo
Hello ,

I want to compare two quadratic regression models with non-parametric
bootstrap.
However, I do not know which R package can serve the purpose,
such as boot, rms, or bootstrap, DeltaR.
Please kindly advise and thank you.

Elaine

The two quadratic regression models are

y1=a1x^2+b1x+c1

y1= observed migration distance of butterflies()

y2=a2x^2+b2x+c2

y2= predicted migration distance of butterflies (based on body mass)

x= body mass of butterflies


null hypothesis: a1=a2 and b1=b2 and c1=c2

bootstrap to test if the coeffients (a, b, c) of the y1 and the y2 model
differ

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


[R] significantly different from one (not zero) using lm

2013-04-30 Thread Elaine Kuo
Hello,



I am work with a linear regression model:

y=ax+b with the function of lm.

y= observed migration distance of butterflies

x= predicted migration distance of butterflies



Usually the result will show

if the linear term a is significantly different from zero based on the
p-value.

Now I would like to test if the linear term is significantly different from
one.

(because I want to know if the regression line (y=ax+b) is significantly
from the line with the linear term =1 and the intercept =0)



Please kindly advise if it is possible

to adjust some default parameters in the function to achieve the goal.

Thank you.


Elaine

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


[R] MOS-test using package vegan

2013-04-20 Thread Elaine Kuo
Dear all,

I am using MOStest in vegan to examine the hump-shaped of
a quadratic regression model.
In the manual of vegan, it mentions that the value of MOStest include
isHump.
My result showed the quadratic regression is hump-shaped according to the
p-value (nearly 0).
However, the value isHump did not show up.
Please kindly help where to find isHump.

Further, I do not understand the result of the function plot
for the MOStested regression model, after reading the manual of vegan.
(There are three graphs in the result, y-x plot, residuals and fitted
regression model, and cook's distance)
Please kindly share any references to interpret the graphs.
Thank you.

Elaine

code
library(vegan)
mos_test  -  MOStest(BMN,   DIS,  family=gaussian)
plot(mos_test)

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


[R] failed to download vegan

2013-04-16 Thread Elaine Kuo
Hello,

This is Elaine.

I am using R 3.0 to download package vegan but failed.
The warning message is

package ‘vegan’ successfully unpacked and MD5 sums checked
Warning: unable to move temporary installation
‘C:\Users\elaine\Documents\R\win-library\3.0\file16c82da53b1b\vegan’ to
‘C:\Users\elaine\Documents\R\win-library\3.0\vegan’

I cannot find the folder \file16c82da53b1b\ below
C:\Users\elaine\Documents\R\win-library\3.0
Please kindly help how to download or move the vegan to the folder it
should be in.

Thank you very much
Elaine

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


Re: [R] failed to download vegan

2013-04-16 Thread Elaine Kuo
Hello All,

I manually moved the vegan.zip to ‘C:\Users\elaine\Documents\R\
win-library\3.0\vegan’.
Then unzipping the file.
It worked to require vegan

Elaine


On Wed, Apr 17, 2013 at 8:56 AM, Elaine Kuo elaine.kuo...@gmail.com wrote:

 Hello,

 This is Elaine.

 I am using R 3.0 to download package vegan but failed.
 The warning message is

 package ‘vegan’ successfully unpacked and MD5 sums checked
 Warning: unable to move temporary installation
 ‘C:\Users\elaine\Documents\R\win-library\3.0\file16c82da53b1b\vegan’ to
 ‘C:\Users\elaine\Documents\R\win-library\3.0\vegan’

 I cannot find the folder \file16c82da53b1b\ below
 C:\Users\elaine\Documents\R\win-library\3.0
 Please kindly help how to download or move the vegan to the folder it
 should be in.

 Thank you very much
 Elaine




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


[R] put strip below the panel (dotplot)

2013-02-28 Thread Elaine Kuo
Hello



I am using lattice dotplot and I would like to put the strip under the
panel.

I found the code “strip” is for the strip above the panel, and “strip.left”
for the strip left to the panel.

Please kindly advise how to write the code for the strip under the panel

Thank you


Elaine

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


[R] resizing panels but some strip letters disappeared (dotplot)

2013-02-28 Thread Elaine Kuo
Hello,

I am using library(latticeExtra) resizePanels to have better visual display
in dotplot (lattice).
However, some panels became smaller and the strip letters of those panels
were partially missing.
Please kindly advise how to keep all strip letters remaining when resizing
panels.
Thank you.

Elaine

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


Re: [R] locating boxplot in bwplot (lattice)

2013-02-27 Thread Elaine Kuo
Hello,

I used group in dotplot to classify diet by colors.

Elaine

On Mon, Feb 25, 2013 at 6:27 AM, Elaine Kuo elaine.kuo...@gmail.com wrote:

 Hello

 sorry that I did not make the letter clearly stated.

 Now I have 21 boxplots (No. 1, No. 2No. 21 from the left to the
 right)(lattice).
 I want the first two (No. 1 and 2) to become red and the rest (No. 3 to
 No. 21) to become blue.
 (rep will make No. 1 and 2, No. 9 and 10, No. 17 and 18, No. become red.)

 Please kindly advise R-code that can specify the red color for No. 1 and
 2, the blue color for the rest.
 Thanks again.

 Elaine

 On Mon, Feb 25, 2013 at 4:17 AM, Peter Ehlers ehl...@ucalgary.ca wrote:

 On 2013-02-24 03:50, Elaine Kuo wrote:

 Hello

 Thank you for the advice on vector.
 I found a previous mail on this issue and pasted it below.

 Now here comes a different scenario.
 I have more than 20 boxplots and just wanted the first two from the left
 to
 be red and the rest to be blue.
 Please kindly advise how to code the color without writing the color
 names
 18 times.
 Thanks again.

 Elaine


 [...snip...]

 I haven't followed this thread, but is there some reason why you can't
 just use rep()?

 Example (from the help page for bwplot):

  mycol - rep( c(red, blue), c(2, 6) )
  bwplot(voice.part ~ height, data = singer, fill = mycol)

 Peter Ehlers




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


Re: [R] locating boxplot in bwplot (lattice)

2013-02-24 Thread Elaine Kuo
Hello

Thank you for the advice on vector.
I found a previous mail on this issue and pasted it below.

Now here comes a different scenario.
I have more than 20 boxplots and just wanted the first two from the left to
be red and the rest to be blue.
Please kindly advise how to code the color without writing the color names
18 times.
Thanks again.

Elaine


code for color using vector

dataset - data.frame ( time = rep(1:5,times=9),
genotype = factor(rep(rep
(c(A,B,C),each=5),times=3 )),
location= factor(rep (paste(LOC,1:3),each=15)),
color = rep (rep
(c(red,green,blue),each=5),times=3
),
result = rnorm (45))


library(lattice)

# The black, red, green behaviour you were seeing is because
# dataset$color is a factor
dataset$color
# which is coded 1, 2, 3 levels = (red, green, blue).
# This is being interpreted as the first three colours of the palette
pallete()

# coerce the vector to a character vector
as.character(dataset$color)

# gives you
xyplot( result ~ time | location, data=dataset,groups=genotype,
fill.color = as.character(dataset$color),
panel = function(x, y,fill.color,...,subscripts) {
fill = fill.color [subscripts]
panel.xyplot(x, y,pch=19, col=fill, type =b)}
)

# Lines only take a single value so only the first value of the vector,
# red, is passed to line colour.

# these are simple alternatives

xyplot( result ~ time | location, data=dataset, groups=genotype,
pch=c(1,2,3),   type=b,
col=c(red,blue,green))

xyplot( result ~ time | location, data=dataset, groups=genotype,
pch=c(1,2,3),   type=b,
col=dataset$color)

# or use

par.settings - list(superpose.symbol = list(col = c(red, green,
blue), fill = c(red, green, blue)), superpose.line = list(col =
c(red, green, blue)) )

xyplot( result ~ time | location, data=dataset,groups=genotype,pch=19,
type = b, par.settings = par.settings)



On Sun, Feb 24, 2013 at 6:29 PM, Andrés Aragón Martínez armand...@gmail.com
 wrote:

 Hi Elaine,

 In your dataset create a vector with the order in which you want appear
 the levels, then use that vector in the argument reorder.

 Andrés AM





 El 24/02/2013, a las 00:59, Elaine Kuo elaine.kuo...@gmail.com escribió:

  Hello,
 
  I tried to manipulate the order of boxplots using the reorder below and
  worked.
 
  However, please kindly advise how to specify the colors of each boxplot
  (bird group),
  like red, green, and blue, from the left to the right.
  Thanks again.
 
  code
  bwplot(GE_distance~OF, data=dataN,
 index.cond  =  function(x,  y)  mean(y),
 xlab=list(Taxonomy  group, cex = 1.6),
 prepanel = function(x,  y)  {
 list(xlim = levels(reorder(x,  y)))
 },
 panel = function(x, y,  ...)  {
 panel.bwplot(reorder(x, y),y,   ...)
 })
 
  data
 
  migration distance (km)bird group
 
  10987  Charadriiformes
 
  9867Charadriiformes
 
  8702Charadriiformes
 
  9432Charadriiformes
 
  9054Charadriiformes
 
  5087   Falconiiformes
 
  5783   Falconiiformes
 
  5298Falconiiformes
 
  5687   Falconiiformes
 
  3987Gruiformes
 
  3298Gruiformes
 
  3567Gruiformes
 
  3409Gruiformes
 
  3321Gruiformes
 
  3598Gruiformes
 
 
 
  On Sat, Feb 23, 2013 at 6:29 AM, Ben Bolker bbol...@gmail.com wrote:
 
  Elaine Kuo elaine.kuo.tw at gmail.com writes:
 
 
  Hello
 
  I am using lattice bwplot to draw migration distance of three groups of
  birds.
 
  The boxplots from the left to right is displayed
  in alphabetic order of the boxplot names, as the default setting.
 
  However, I would like the boxplots from the left to right to be
 displayed
  according to the migration distance from the short values to the long
  ones.
 
  In the data below, from the left to the right should be Gruiformes,
  Falconiiformes, and Charadriiformes.
 
  Please kindly advise how to modify the code below.
 
 
  Define the order of the levels of your factor
  accordingly. Take a look at
 
  http://stackoverflow.com/questions/15033107/
   specifing-order-of-lattice-plot-panels
 
  (broken URL to meet gmane line length limits)
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R

Re: [R] locating boxplot in bwplot (lattice)

2013-02-24 Thread Elaine Kuo
Hello

sorry that I did not make the letter clearly stated.

Now I have 21 boxplots (No. 1, No. 2No. 21 from the left to the
right)(lattice).
I want the first two (No. 1 and 2) to become red and the rest (No. 3 to No.
21) to become blue.
(rep will make No. 1 and 2, No. 9 and 10, No. 17 and 18, No. become red.)

Please kindly advise R-code that can specify the red color for No. 1 and 2,
the blue color for the rest.
Thanks again.

Elaine

On Mon, Feb 25, 2013 at 4:17 AM, Peter Ehlers ehl...@ucalgary.ca wrote:

 On 2013-02-24 03:50, Elaine Kuo wrote:

 Hello

 Thank you for the advice on vector.
 I found a previous mail on this issue and pasted it below.

 Now here comes a different scenario.
 I have more than 20 boxplots and just wanted the first two from the left
 to
 be red and the rest to be blue.
 Please kindly advise how to code the color without writing the color names
 18 times.
 Thanks again.

 Elaine


 [...snip...]

 I haven't followed this thread, but is there some reason why you can't
 just use rep()?

 Example (from the help page for bwplot):

  mycol - rep( c(red, blue), c(2, 6) )
  bwplot(voice.part ~ height, data = singer, fill = mycol)

 Peter Ehlers



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


Re: [R] locating boxplot in bwplot (lattice)

2013-02-23 Thread Elaine Kuo
Hello,

I tried to manipulate the order of boxplots using the reorder below and
worked.

However, please kindly advise how to specify the colors of each boxplot
(bird group),
like red, green, and blue, from the left to the right.
Thanks again.

code
 bwplot(GE_distance~OF, data=dataN,
index.cond  =  function(x,  y)  mean(y),
xlab=list(Taxonomy  group, cex = 1.6),
prepanel = function(x,  y)  {
list(xlim = levels(reorder(x,  y)))
},
panel = function(x, y,  ...)  {
panel.bwplot(reorder(x, y),y,   ...)
})

data

migration distance (km)bird group

10987  Charadriiformes

9867Charadriiformes

8702Charadriiformes

9432Charadriiformes

9054Charadriiformes

5087   Falconiiformes

5783   Falconiiformes

5298Falconiiformes

5687   Falconiiformes

3987Gruiformes

3298Gruiformes

3567Gruiformes

3409Gruiformes

3321Gruiformes

3598Gruiformes



On Sat, Feb 23, 2013 at 6:29 AM, Ben Bolker bbol...@gmail.com wrote:

 Elaine Kuo elaine.kuo.tw at gmail.com writes:

 
  Hello
 
  I am using lattice bwplot to draw migration distance of three groups of
  birds.
 
  The boxplots from the left to right is displayed
  in alphabetic order of the boxplot names, as the default setting.
 
  However, I would like the boxplots from the left to right to be displayed
  according to the migration distance from the short values to the long
 ones.
 
  In the data below, from the left to the right should be Gruiformes,
  Falconiiformes, and Charadriiformes.
 
  Please kindly advise how to modify the code below.
 

  Define the order of the levels of your factor
 accordingly. Take a look at

 http://stackoverflow.com/questions/15033107/
   specifing-order-of-lattice-plot-panels

 (broken URL to meet gmane line length limits)

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

__
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] locating boxplot in bwplot (lattice)

2013-02-22 Thread Elaine Kuo
Hello



I am using lattice bwplot to draw migration distance of three groups of
birds.

The boxplots from the left to right is displayed

in alphabetic order of the boxplot names, as the default setting.



However, I would like the boxplots from the left to right to be displayed
according to the migration distance from the short values to the long ones.

In the data below, from the left to the right should be Gruiformes,
Falconiiformes, and Charadriiformes.



Please kindly advise how to modify the code below.

The data is as below.

Thank you.


Elaine





Code

Library(lattice)

bwplot(migration_distance~bird)





data

migration distance (km)bird group

10987  Charadriiformes

9867Charadriiformes

8702Charadriiformes

9432Charadriiformes

9054Charadriiformes

5087   Falconiiformes

5783   Falconiiformes

5298Falconiiformes

5687   Falconiiformes

3987Gruiformes

3298Gruiformes

3567Gruiformes

3409Gruiformes

3321Gruiformes

3598Gruiformes

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


[R] how to make a median line thicker in bwplot (lattice)

2013-02-11 Thread Elaine Kuo
Hello,

I am drawing a boxplot using bwplot in lattice.
I would like to learn how to draw a thicker median line instead of the
default setting.
Thank you.

Code

bwplot(,
pch=rep(|,2))

Elaine

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


[R] how to change whisker width in bwplot (lattice)

2013-02-11 Thread Elaine Kuo
Hello,

I am using lattice to draw boxplots.
I would like to make the whisker look shorter than the box width.
Please kindly advise how to modify the code.
Thank you.

Elaine

code

bwplot(x,y,
pch=rep(|,2),
box.umbrella = list(col = black, lty = 1))

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


[R] how to draw confidence interval lines of a fitted curve of polynominal regression

2013-02-06 Thread Elaine Kuo
Hello,

I drew a plot of weight and height of people and fitted it with a
polynominal regression x^2.
(using curve())

Now I would like to draw the confidence interval line for the fitted curve.
Please kindly advise the code for the purpose.
Thank you.

Elaine

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


[R] customize color in xyplot

2013-01-12 Thread Elaine Kuo
Hello

I want to draw a plot and classify the dot by different color, according to
the habitats.
I am using xyplot in lattice but do not know how to assign specific colors
to the habitats.
Please kindly advise how to modify the code.

Thank you.

Elaine


code
dataN -read.csv(H:/Mig_bird_586_20130109.csv,header=T, row.names=1)
dataN$Habitat -factor(dataN$Habitat)
dim(dataN)
dataN[1,]

habitat.code - c(Water, Land)
habitat.colors - c(darkblue,forestgreen)
levels(dataN$Habitat) - habitat.code

  # graph
par(mai=c(1.03,1.03,0.4,0.4))
par(new=T)

xyplot(GE_distance~Habitat, data=dataN,
xlab=list(Habitat, cex = 1.4),
ylab=list(Migration  Distance  (km),cex = 1.4),
cex=1.5)

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


[R] add categorical labels in plot

2013-01-11 Thread Elaine Kuo
Hello

I want to draw a plot using the code below.

Further, I want to add labels (White, Yellow, Red) to x-axis.
Please kindly advise how to add the categorical labels, by modifying the
code.
Thank you.

Elaine

Code

dataN -read.csv(H:/skin_color.csv,header=T, row.names=1)

dim(dataN)

dataN[1,]

str(dataN)



obs.group-dataN$skin_color

levels(dataN$skin_color) - skin.code



skin.code - c(White, Yellow, Red)



  # graph

par(mai=c(1.03,1.03,0.4,0.4))

par(new=T)



plot(dataN$skin_color, dataN$body_length,

xlab=Skin Color,

ylab=Body Lenght,

xaxt=n,

type=p,

pch=1,lwd=2.0,

cex.lab=1.4, cex.axis=1.2,

font.axis=2,

cex=1.5,

las=1,

bty=l,

col=c(gray38,orange,red2)[obs.group])

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


[R] two-group comparison in boxplot

2013-01-11 Thread Elaine Kuo
Hello



I have a data composing three columns: body weight, body length, and sex.

I want to draw a box plot, X-axis for body weight, Y-axis for body length.



In the boxplot,

I want to compare the body length between two sexes of three groups of body
weight: 50, 51-100, 101 kg.

(For instance, from left to right,

the first boxplot: sex =1, body weight 50

the second boxplot: sex =2, body weight 50

the third boxplot: sex =1, body weight 51-100

the fourth boxplot: sex =2, body weight51-100

the fifth boxplot: sex =1, body weight 101

the sixth boxplot: sex =2, body weight 101)



Please kindly advise how to modify the code below for the above purpose.

Thank you.



Elaine



Code

library(HH)



# data input 1 (all data)

dataN-read.csv(H:/body_status.csv,header=T, row.names=1)

dataN$sex -factor(dataN$sex)

dim(dataN)

dataN[1,]

str(dataN)



sex.colors - c(darkblue,red2)

sex.code - c(Boy, Girl)

levels(dataN$sex) - sex.code



 # graph

par(mai=c(1,1.03,0.4,0.4))

par(new=T)



bwplot(body_length~body_weight, data=dataN,

xlab=list(Body weight, cex = 1.4),

ylab=list(Body length,cex = 1.4),

xaxt=n,

yaxt=n,type=p,

lwd=1.5,

cex.lab=1.4, cex.axis=1.2,

font.axis=2,

cex=1.5,

las=1,

bty=l,

panel=panel.bwplot.intermediate.hh,

col=Diet.colors,

pch=rep(|,3),

scales=list(x=list(rot=90)),

par.settings=list(box.umbrella=list(lty=1)))



data



No

body_weight

body_length

Sex

1

87

154

1

2

76

189

2

3

54

176

2

4

87

162

2

5

67

190

2

6

89

143

1

7

73

167

2

8

86

189

2

9

90

196

1

10

94

154

1

11

61

167

2

12

102

180

2

13

106

193

1

14

110

206

2

15

114

219

2

16

118

156

2

17

122

198

2

18

87

187

1

19

67

174

1

20

46

179

2

21

54

164

1

22

98

167

1

23

93

198

1

24

62

201

1

25

60

173

1

26

78

165

1

27

75

169

2

28

66

178

1

29

42

174

1

30

90

178

2

31

105

172

2

32

118

180

1

33

94

187

2

34

85

176

1

35

72

145

2

36

66

165

2

37

56

162

2

38

89

159

2

39

73

167

1

40

52

190

1

41

51

154

1

42

98

176

2

43

74

172

2

44

78

171

2

45

97

173

1

46

45

167

2

47

46

163

2

48

107

164

1

49

93

160

2

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


[R] how to change font size of axis label (not axis title)

2013-01-11 Thread Elaine Kuo
Hello,

I am using lattice to produce xyplot.
I want to change the font size of axis-X label.
Please kindly advise how to write the code.
Thank you.

For changing the font size of axis-X title
it would be

xlab=list(Diet  of  Breeding  Ground, cex = 1.4)

Elaine

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


[R] panel failure in xyplot

2013-01-11 Thread Elaine Kuo
Hello

I ran the code below but it said:

no object 'panel.xyplot.intermediate.hh'

Please kindly advise how to modify the code.
thank you.

(It works with panel.bwplot.intermediate.hh)

Elaine


code

library(HH)

# data input
dataN -read.csv(H:/R_data/Mig_bird_586.csv,header=T, row.names=1)
dim(dataN)
dataN[1,]
str(dataN)

diet.code - c(Herbivore, Omnivore, Carnivore)
Diet.colors - c(forestgreen, darkblue,red2)
levels(dataN$Diet) - diet.code

  # graph
par(mai=c(1.03,1.03,0.4,0.4))
par(new=T)

xyplot(GE_distance~Diet, data=dataN,
xlab=list(Diet  of  Breeding  Ground, cex = 1.4),
ylab=list(Migration  Distance,cex = 1.4),
xaxt=n,
yaxt=n,type=p,
lwd=1.5,
cex.lab=1.4, cex.axis=1.2,
font.axis=2,
cex=1.5,
las=1,
bty=l,
panel=panel.xyplot.intermediate.hh,
col=Diet.colors,
pch=rep(|,3),
scales=list(x=list(rot=0)),
par.settings=list(box.umbrella=list(lty=1)))

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


[R] color in xyplot

2013-01-11 Thread Elaine Kuo
Hello

I want to draw a xyplot.
Its dots will have three colors: red for meat, green for vegetable, and
blue for both.

I used the code below but could not make the dot in the same group show the
same color.
Please kindly advise how to modify it.
Thank you.

code

library (lattice)
 diet.code - c(Herbivore, Omnivore, Carnivore)
Diet.colors - c(forestgreen, darkblue,red2)
levels(dataN$Diet) - diet.code

  # graph
par(mai=c(1.03,1.03,0.4,0.4))
par(new=T)

xyplot(GE_distance~Diet, data=dataN,
xlab=list(Diet  of  Breeding  Ground, cex = 1.4),
ylab=list(Migration  Distance,cex = 1.4),
xaxt=n,
yaxt=n,type=p,
lwd=1.5,
cex.lab=1.4, cex.axis=1.2,
font.axis=2,
cex=1.5,
las=1,
bty=l,
col=rep(Diet.colors))

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


[R] plot xaxp issue

2013-01-07 Thread Elaine Kuo
Hello,

I have data of Body length and Body weight of 8 boys and 7 girls.

I want to draw the plot of Body length (for X) and Body weight (for Y)
based on sex.
Then the two plots want to be overlapped for comparison.

I used the code below but found the unit length of X axis of boy and
girl plot are not the same.
For instance, the length between 0 and 1 of boy plot is larger than
that in girl plot.
The same thing happened to Y axis as well.
(In other words, though axap and yaxp were set to be the same, the
display were not the same.)

Please kindly advise correction of the code.
Thank you.

Elaine

# plot code
boy-read.csv(H:/boy_data.csv,header=T)
girl-read.csv(H:/girl_data.csv,header=T)
par(mai=c(1.03,1.03,0.4,0.4))

plot(boy$body_length, boy$body_weight,
xlab= body_length (cm),
ylab= body_weight  ( kg ),
xaxp=c(0,200,4),
yaxp=c(0,100,4),
type=p,
pch=1,lwd=1.0,
cex.lab=1.4, cex.axis=1.2,
font.axis=2,
cex=1.5,
las=1,
bty=l,col=firebrick3)

boyline-lm(body_weight ~ body_length, boy)
summary(boyline)
abline(boyline,col=firebrick3,lwd=2)

#~~~
  # graph
par(mai=c(1.03,1.03,0.4,0.4))

par(new=T)

plot(girl$body_length, girl$body_weight,
xlab= body_length (cm),
ylab= body_weight  ( kg ),
xaxp=c(0,200,4),
yaxp=c(0,100,4),
type=p,
pch=1,lwd=1.0,
cex.lab=1.4, cex.axis=1.2,
font.axis=2,
cex=1.5,
las=1,
bty=l,col=saddlebrown)


girlline-lm(body_weight~ body_length, girl)
summary(girlline)
abline(girlline,col=saddlebrown,lwd=2)

__
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] plot xaxp issue

2013-01-07 Thread Elaine Kuo
Thanks a lot.
Please kindly indicate the meaning of the c(8,7).

 together - rbind(boy, girl)
 together$sex - factor(rep(c(boy, girl), c(8,7)))

Elaine

On Mon, Jan 7, 2013 at 4:55 PM, PIKAL Petr petr.pi...@precheza.cz wrote:
 Hi

 Instead of two plots with par(new = TRUE) try to put boys and girls together 
 (quite natural thing, they will be pleased 8-)

 together - rbind(boy, girl)
 together$sex - factor(rep(c(boy, girl), c(8,7)))

 plot(together$body_length, together$body_weight, , 
 col=c(firebrick3,saddlebrown)[as.numeric(together$sex)], )

 Regards
 Petr


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Elaine Kuo
 Sent: Monday, January 07, 2013 9:27 AM
 To: r-help@r-project.org
 Subject: [R] plot xaxp issue

 Hello,

 I have data of Body length and Body weight of 8 boys and 7 girls.

 I want to draw the plot of Body length (for X) and Body weight (for Y)
 based on sex.
 Then the two plots want to be overlapped for comparison.

 I used the code below but found the unit length of X axis of boy and
 girl plot are not the same.
 For instance, the length between 0 and 1 of boy plot is larger than
 that in girl plot.
 The same thing happened to Y axis as well.
 (In other words, though axap and yaxp were set to be the same, the
 display were not the same.)

 Please kindly advise correction of the code.
 Thank you.

 Elaine

 # plot code
 boy-read.csv(H:/boy_data.csv,header=T)
 girl-read.csv(H:/girl_data.csv,header=T)
 par(mai=c(1.03,1.03,0.4,0.4))

 plot(boy$body_length, boy$body_weight,
 xlab= body_length (cm),
 ylab= body_weight  ( kg ),
 xaxp=c(0,200,4),
 yaxp=c(0,100,4),
 type=p,
 pch=1,lwd=1.0,
 cex.lab=1.4, cex.axis=1.2,
 font.axis=2,
 cex=1.5,
 las=1,
 bty=l,col=firebrick3)

 boyline-lm(body_weight ~ body_length, boy)
 summary(boyline)
 abline(boyline,col=firebrick3,lwd=2)

 #~~~
   # graph
 par(mai=c(1.03,1.03,0.4,0.4))

 par(new=T)

 plot(girl$body_length, girl$body_weight,
 xlab= body_length (cm),
 ylab= body_weight  ( kg ),
 xaxp=c(0,200,4),
 yaxp=c(0,100,4),
 type=p,
 pch=1,lwd=1.0,
 cex.lab=1.4, cex.axis=1.2,
 font.axis=2,
 cex=1.5,
 las=1,
 bty=l,col=saddlebrown)


 girlline-lm(body_weight~ body_length, girl)
 summary(girlline)
 abline(girlline,col=saddlebrown,lwd=2)

 __
 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-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] plot xaxp issue

2013-01-07 Thread Elaine Kuo
Thank you Petr, the code is wonderful.

One more question,
you used [as.numeric(together$sex)] to drawing plots many times (Par(new)).
Please kindly advise if there is a similar method to replace drawing
ablines many times.
If not, I am afraid that the ablines will not follow the same Y and
X-axis places.

Elaine


On Mon, Jan 7, 2013 at 8:11 PM, Elaine Kuo elaine.kuo...@gmail.com wrote:
 Thanks a lot.
 Please kindly indicate the meaning of the c(8,7).

 together - rbind(boy, girl)
 together$sex - factor(rep(c(boy, girl), c(8,7)))

 Elaine

 On Mon, Jan 7, 2013 at 4:55 PM, PIKAL Petr petr.pi...@precheza.cz wrote:
 Hi

 Instead of two plots with par(new = TRUE) try to put boys and girls together 
 (quite natural thing, they will be pleased 8-)

 together - rbind(boy, girl)
 together$sex - factor(rep(c(boy, girl), c(8,7)))

 plot(together$body_length, together$body_weight, , 
 col=c(firebrick3,saddlebrown)[as.numeric(together$sex)], )

 Regards
 Petr


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Elaine Kuo
 Sent: Monday, January 07, 2013 9:27 AM
 To: r-help@r-project.org
 Subject: [R] plot xaxp issue

 Hello,

 I have data of Body length and Body weight of 8 boys and 7 girls.

 I want to draw the plot of Body length (for X) and Body weight (for Y)
 based on sex.
 Then the two plots want to be overlapped for comparison.

 I used the code below but found the unit length of X axis of boy and
 girl plot are not the same.
 For instance, the length between 0 and 1 of boy plot is larger than
 that in girl plot.
 The same thing happened to Y axis as well.
 (In other words, though axap and yaxp were set to be the same, the
 display were not the same.)

 Please kindly advise correction of the code.
 Thank you.

 Elaine

 # plot code
 boy-read.csv(H:/boy_data.csv,header=T)
 girl-read.csv(H:/girl_data.csv,header=T)
 par(mai=c(1.03,1.03,0.4,0.4))

 plot(boy$body_length, boy$body_weight,
 xlab= body_length (cm),
 ylab= body_weight  ( kg ),
 xaxp=c(0,200,4),
 yaxp=c(0,100,4),
 type=p,
 pch=1,lwd=1.0,
 cex.lab=1.4, cex.axis=1.2,
 font.axis=2,
 cex=1.5,
 las=1,
 bty=l,col=firebrick3)

 boyline-lm(body_weight ~ body_length, boy)
 summary(boyline)
 abline(boyline,col=firebrick3,lwd=2)

 #~~~
   # graph
 par(mai=c(1.03,1.03,0.4,0.4))

 par(new=T)

 plot(girl$body_length, girl$body_weight,
 xlab= body_length (cm),
 ylab= body_weight  ( kg ),
 xaxp=c(0,200,4),
 yaxp=c(0,100,4),
 type=p,
 pch=1,lwd=1.0,
 cex.lab=1.4, cex.axis=1.2,
 font.axis=2,
 cex=1.5,
 las=1,
 bty=l,col=saddlebrown)


 girlline-lm(body_weight~ body_length, girl)
 summary(girlline)
 abline(girlline,col=saddlebrown,lwd=2)

 __
 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-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] plot xaxp issue

2013-01-07 Thread Elaine Kuo
Hello,

Thanks again.
But something wrong with the subset after lm


 It is not about drawing plot many times but coding points or graphic objects 
 by some factor. In your case sex.

 Instead of
 boyline-lm(body_weight ~ body_length, boy)

 use collective data frame together and subset only one sex.

boy-read.csv(H:/boy_data.csv,header=T)
girl-read.csv(H:/girl_data.csv,header=T)
together - rbind(boy, girl)
together$sex - factor(rep(c(boy, girl), c(8,7)))
plot(together$body_length, together$body_weight, ,
col=c(firebrick3,saddlebrown)[as.numeric(together$sex)], )

boyline-lm(body_weight ~ body_length, data=together, subset(sex==boy))
 abline(boyline,col=firebrick3,lwd=2)


I updated it aas
boyline-lm(body_weight ~ body_length, data=together, 
subset(together,sex==boy))

But an error showed, saying:
error in xj[i] : useless type of  'list'

Please kindly help and thanks again.
BTW, the code below might need update as well.
Elaine


 In case of more than two sexes (some SF authors mentioned it is possible) you 
 can use simple loop.

 for (i in 1:2)) {
 subs - together$sex==levels(together$sex)[i]
 line-lm(body_weight ~ body_length, data=together, subset=subs)
 abline(line, col=c(firebrick3,saddlebrown)[i],lwd=2)
 }


The original code with advice by Petr
#~~
boy-read.csv(H:/boy_data.csv,header=T)
girl-read.csv(H:/girl_data.csv,header=T)
together - rbind(boy, girl)
together$sex - factor(rep(c(boy, girl), c(8,7)))
plot(together$body_length, together$body_weight, ,
col=c(firebrick3,saddlebrown)[as.numeric(together$sex)], )

boyline-lm(body_weight ~ body_length, data=together, subset(sex==boy))
abline(boyline,col=firebrick3,lwd=2)

__
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] plot xaxp issue

2013-01-07 Thread Elaine Kuo
Hello,

I figured out that the code should be

boyline-lm(body_weight ~ body_length, data=subset (together,,sex==boy))

However, the  could be omitted if the field name happened to be
numeric, such as 1, 2, or 3.
Please kindly explain why the  could be omitted for numbers.
Thanks again.

Elaine
On Tue, Jan 8, 2013 at 8:40 AM, Elaine Kuo elaine.kuo...@gmail.com wrote:
 boyline-lm(body_weight ~ body_length, data=together, 
 subset(together,sex==boy))

__
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] error in a abline loop

2013-01-07 Thread Elaine Kuo
Hello

I have data of body length and body weight of people of different skin colors.

I tried to write a code to plot body length and body weight according
to the skin colors.
(Thanks for Petr's advice so far.)

A loop is used but an error shows up in the following code.
It says:
 unexpected '}' in

red3,red3,saddlebrown,coral4,chocolate4,darkblue,navy,grey38)[i],lwd=2)
}

Please kindly advise how to modify the code.
Thank you.

The code
  data -read.csv(H:/skincolor.csv,header=T)

  # graph
par(mai=c(1.03,1.03,0.4,0.4))

plot(data$body_weight, data$body_length,
xaxp=c(0,200,4),
yaxp=c(0,200,4),
type=p,
pch=1,lwd=1.0,
cex.lab=1.4, cex.axis=1.2,
font.axis=2,
cex=1.5,
las=1,
bty=l,col=c(yellow,chocolate1,darkorange2,
red3,saddlebrown,coral4,grey38)[as.numeric(data$skin_color)])



#~~~
##
for (i in 1:7) {
subs - data$skin_color==levels(data$skin_color)[i]
line-lm(body_weight~body_length, data=subset(data, subset=subs),
abline(line,col=c(yellow,chocolate1,darkorange2,
red3,saddlebrown,coral4,grey38)[i],lwd=2)
}

__
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] error in a abline loop

2013-01-07 Thread Elaine Kuo
Hello

Thanks.
It is right a ) is missing for lm.
With the modification, I ran the code but the command seems not
closed, with + instead of .
Please kindly help.

The code modified
for (i in 1:7) {
subs - data$skin_color==levels(data$skin_color)[i]
line-lm(body_weight~body_length, data=subset(data, subset=subs))
abline(line,col=c(yellow,chocolate1,darkorange2,
red3,saddlebrown,coral4,grey38)[i],lwd=2) )
}

Elaine



On Tue, Jan 8, 2013 at 10:03 AM, arun smartpink...@yahoo.com wrote:

 HI,

 A possible guess ( with no data):
 for (i in 1:7) {
 subs - data$skin_color==levels(data$skin_color)[i]
 line-lm(body_weight~body_length, data=subset(data, subset=subs)) 
 #closing parentheses
 abline(line,col=c(yellow,chocolate1,darkorange2,
 red3,saddlebrown,coral4,grey38)[i],lwd=2)
 }


 A.K.



 - Original Message -
 From: Elaine Kuo elaine.kuo...@gmail.com
 To: r-help@r-project.org
 Cc:
 Sent: Monday, January 7, 2013 8:23 PM
 Subject: [R] error in a abline loop

 Hello

 I have data of body length and body weight of people of different skin colors.

 I tried to write a code to plot body length and body weight according
 to the skin colors.
 (Thanks for Petr's advice so far.)

 A loop is used but an error shows up in the following code.
 It says:
 unexpected '}' in
 
 red3,red3,saddlebrown,coral4,chocolate4,darkblue,navy,grey38)[i],lwd=2)
 }

 Please kindly advise how to modify the code.
 Thank you.

 The code
   data -read.csv(H:/skincolor.csv,header=T)

   # graph
 par(mai=c(1.03,1.03,0.4,0.4))

 plot(data$body_weight, data$body_length,
 xaxp=c(0,200,4),
 yaxp=c(0,200,4),
 type=p,
 pch=1,lwd=1.0,
 cex.lab=1.4, cex.axis=1.2,
 font.axis=2,
 cex=1.5,
 las=1,
 bty=l,col=c(yellow,chocolate1,darkorange2,
 red3,saddlebrown,coral4,grey38)[as.numeric(data$skin_color)])


 
 #~~~
 ##
 for (i in 1:7) {
 subs - data$skin_color==levels(data$skin_color)[i]
 line-lm(body_weight~body_length, data=subset(data, subset=subs),
 abline(line,col=c(yellow,chocolate1,darkorange2,
 red3,saddlebrown,coral4,grey38)[i],lwd=2)
 }

 __
 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-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] averaging X of specific Y (latitude)

2012-12-17 Thread Elaine Kuo
Hello,

Thank you again, David.

I tried with the first step of the command deput as followed

datam -read.csv ('H:/Butterfly_RS_20121217.csv',header=T, row.names=1)
dput(datam, Migrant_RS_L_txt)

However, there is a error message that
the object Migrant_RS_L_txt is not found.

I read the example but still unsure which file (or object) should be input
behind datam.
Please kindly help and thank you again

Elaine



On Mon, Dec 17, 2012 at 9:28 AM, David L Carlson dcarl...@tamu.edu wrote:

 It is not necessary to rearrange the order. The aggregate function will do
 that. To get the mean Range for a latitude combining species within a
 latitude just remove Species:

  aggregate(Range~floor(Latitude), dta, mean)
   floor(Latitude)   Range
 1   9 616.440
 2  10 714.360
 3  12 851.550
 4  16 690.770
 5  18 766.155

 ---
 David


 From: Elaine Kuo [mailto:elaine.kuo...@gmail.com]
 Sent: Sunday, December 16, 2012 5:17 PM
 To: dcarl...@tamu.edu; r-help@r-project.org; r-sig-...@stat.math.ethz.ch
 Subject: Re: [R] averaging X of specific Y (latitude)

 Thank you, David.

 Your answer reminded me of rearranging the order according to the latitude
 before running the calculation.

 One more question,
 please kindly help with the code to calculate the mean of the ranges of the
 same latitude?
 Or should any re-arrangement be noticed before the mean calculation?

 Thank you.

 Elaine



 - Original Message -
 From: David L Carlson dcarl...@tamu.edu
 To: 'Elaine Kuo' elaine.kuo...@gmail.com; r-help@r-project.org;
 'r-sig-geo' r-sig-...@stat.math.ethz.ch
 Cc:
 Sent: Sunday, December 16, 2012 11:32 AM
 Subject: Re: [R] averaging X of specific Y (latitude)

 It is better to use dput() in R to create a text version of your data for
 us
 to work with. The aggregate command below gives you the mean ranges by
 butterfly species and latititude and saves the result as Bfly. The
 colnames() command simply renames the columns:

  dta - structure(list(Species = structure(1:11, .Label = c(Butterfly
 A1,

 + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
 + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
 + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
 + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
 + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
 + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
 + Latitude), class = data.frame, row.names = c(NA, -11L))
  Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
  colnames(Bfly) - c(Species, Latitude, Mean)
  Bfly
 Species LatitudeMean
 1  Butterfly A19  130.50
 2  Butterfly A39 1102.38
 3  Butterfly A2   10  450.68
 4  Butterfly B1   10  820.20
 5  Butterfly B2   10  872.20
 6  Butterfly B5   12  982.78
 7  Butterfly C1   12  720.32
 8  Butterfly A4   16  893.34
 9  Butterfly B3   16  488.20
 10 Butterfly B4   18  620.11
 11 Butterfly C2   18  912.20

 --
 David L Carlson
 Associate Professor of Anthropology
 Texas AM University
 College Station, TX 77843-4352

  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
  project.org] On Behalf Of Elaine Kuo
  Sent: Saturday, December 15, 2012 10:15 PM
  To: r-help@r-project.org; r-sig-geo
  Subject: [R] averaging X of specific Y (latitude)
 
  Hello
 
 
 
  I have a table describing butterfly range traits.
 
  It is composed of three columns as below
 
 
 
  Species name  range size (X)latitude of range midpoint (Y)
 
 
 
  There are 11 kinds of butterflies.
 
  Each has its range size, and the latitude of each range midpoint ranges
  from 9 to 19.
 
  I would like to have the average range size of every degree of
  latitude.
 
  For example, the average range size of latitude degree 10 (10.0-10.99:
  Butterfly A2, B1, B2)
 
  Please kindly help with R code to calculate the average values.
 
  Thank you.
 
 
  Elaine
 
 
  The details are as followed.
 
 
 
  Butterfly A1  130.5 9.45
 
  Butterfly A2  450.68   10.2
 
  Butterfly A3  1102.389.3
 
  Butterfly A4893.34 16.4
 
  Butterfly B1   820.2   10.54
 
  Butterfly B2872.2   10.87
 
  Butterfly B3488.2   16.79
 
  Butterfly B4620.11 18.3
 
  Butterfly B5982.78 12.98
 
  Butterfly C1   720.32 12.67
 
  Butterfly C2912.2   18.07
 
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r

Re: [R] averaging X of specific Y (latitude)

2012-12-17 Thread Elaine Kuo
Thank you, Berend.

I tried
1. dput (datam, datam)
2. dput (datam)

both worked

Elaine


On Mon, Dec 17, 2012 at 7:30 PM, Berend Hasselman b...@xs4all.nl wrote:


 On 17-12-2012, at 12:06, Elaine Kuo wrote:

  Hello,
 
  Thank you again, David.
 
  I tried with the first step of the command deput as followed
 

 It's dput not deput.

  datam -read.csv ('H:/Butterfly_RS_20121217.csv',header=T, row.names=1)
  dput(datam, Migrant_RS_L_txt)
 
  However, there is a error message that
  the object Migrant_RS_L_txt is not found.
 
  I read the example but still unsure which file (or object) should be
 input
  behind datam.
  Please kindly help and thank you again
 

 Variable (object) if used like that should contain the name of a file to
 which you want the output of dput to be written to.
 You can also use

 dput(datam)

 which implies file= (default) and output going to the console.

 Berend

  Elaine
 
 
 
  On Mon, Dec 17, 2012 at 9:28 AM, David L Carlson dcarl...@tamu.edu
 wrote:
 
  It is not necessary to rearrange the order. The aggregate function will
 do
  that. To get the mean Range for a latitude combining species within a
  latitude just remove Species:
 
  aggregate(Range~floor(Latitude), dta, mean)
   floor(Latitude)   Range
  1   9 616.440
  2  10 714.360
  3  12 851.550
  4  16 690.770
  5  18 766.155
 
  ---
  David
 
 
  From: Elaine Kuo [mailto:elaine.kuo...@gmail.com]
  Sent: Sunday, December 16, 2012 5:17 PM
  To: dcarl...@tamu.edu; r-help@r-project.org;
 r-sig-...@stat.math.ethz.ch
  Subject: Re: [R] averaging X of specific Y (latitude)
 
  Thank you, David.
 
  Your answer reminded me of rearranging the order according to the
 latitude
  before running the calculation.
 
  One more question,
  please kindly help with the code to calculate the mean of the ranges of
 the
  same latitude?
  Or should any re-arrangement be noticed before the mean calculation?
 
  Thank you.
 
  Elaine
 
 
 
  - Original Message -
  From: David L Carlson dcarl...@tamu.edu
  To: 'Elaine Kuo' elaine.kuo...@gmail.com; r-help@r-project.org;
  'r-sig-geo' r-sig-...@stat.math.ethz.ch
  Cc:
  Sent: Sunday, December 16, 2012 11:32 AM
  Subject: Re: [R] averaging X of specific Y (latitude)
 
  It is better to use dput() in R to create a text version of your data
 for
  us
  to work with. The aggregate command below gives you the mean ranges by
  butterfly species and latititude and saves the result as Bfly. The
  colnames() command simply renames the columns:
 
  dta - structure(list(Species = structure(1:11, .Label = c(Butterfly
  A1,
 
  + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
  + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
  + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
  + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
  + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
  + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
  + Latitude), class = data.frame, row.names = c(NA, -11L))
  Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
  colnames(Bfly) - c(Species, Latitude, Mean)
  Bfly
 Species LatitudeMean
  1  Butterfly A19  130.50
  2  Butterfly A39 1102.38
  3  Butterfly A2   10  450.68
  4  Butterfly B1   10  820.20
  5  Butterfly B2   10  872.20
  6  Butterfly B5   12  982.78
  7  Butterfly C1   12  720.32
  8  Butterfly A4   16  893.34
  9  Butterfly B3   16  488.20
  10 Butterfly B4   18  620.11
  11 Butterfly C2   18  912.20
 
  --
  David L Carlson
  Associate Professor of Anthropology
  Texas AM University
  College Station, TX 77843-4352
 
  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
  project.org] On Behalf Of Elaine Kuo
  Sent: Saturday, December 15, 2012 10:15 PM
  To: r-help@r-project.org; r-sig-geo
  Subject: [R] averaging X of specific Y (latitude)
 
  Hello
 
 
 
  I have a table describing butterfly range traits.
 
  It is composed of three columns as below
 
 
 
  Species name  range size (X)latitude of range midpoint (Y)
 
 
 
  There are 11 kinds of butterflies.
 
  Each has its range size, and the latitude of each range midpoint ranges
  from 9 to 19.
 
  I would like to have the average range size of every degree of
  latitude.
 
  For example, the average range size of latitude degree 10 (10.0-10.99:
  Butterfly A2, B1, B2)
 
  Please kindly help with R code to calculate the average values.
 
  Thank you.
 
 
  Elaine
 
 
  The details are as followed.
 
 
 
  Butterfly A1  130.5 9.45
 
  Butterfly A2  450.68   10.2
 
  Butterfly A3  1102.389.3
 
  Butterfly A4893.34 16.4
 
  Butterfly B1   820.2   10.54

Re: [R] averaging X of specific Y (latitude)

2012-12-17 Thread Elaine Kuo
One more question:

Please kindly explain
why it is written as row.names = c(NA, -11L)).
(in the code below)

I am unsure why it is negative 11.
Thank you .

Elaine

code

dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1,

+ Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
+ Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
+ Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
+ 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
+ 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
+ 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
+ Latitude), class = data.frame, row.names = c(NA, -11L)))


 
 
  - Original Message -
  From: David L Carlson dcarl...@tamu.edu
  To: 'Elaine Kuo' elaine.kuo...@gmail.com; r-help@r-project.org;
  'r-sig-geo' r-sig-...@stat.math.ethz.ch
  Cc:
  Sent: Sunday, December 16, 2012 11:32 AM
  Subject: Re: [R] averaging X of specific Y (latitude)
 
  It is better to use dput() in R to create a text version of your data
 for
  us
  to work with. The aggregate command below gives you the mean ranges by
  butterfly species and latititude and saves the result as Bfly. The
  colnames() command simply renames the columns:
 
  dta - structure(list(Species = structure(1:11, .Label = c(Butterfly
  A1,
 
  + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
  + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
  + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
  + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
  + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
  + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
  + Latitude), class = data.frame, row.names = c(NA, -11L))
  Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
  colnames(Bfly) - c(Species, Latitude, Mean)
  Bfly
 Species LatitudeMean
  1  Butterfly A19  130.50
  2  Butterfly A39 1102.38
  3  Butterfly A2   10  450.68
  4  Butterfly B1   10  820.20
  5  Butterfly B2   10  872.20
  6  Butterfly B5   12  982.78
  7  Butterfly C1   12  720.32
  8  Butterfly A4   16  893.34
  9  Butterfly B3   16  488.20
  10 Butterfly B4   18  620.11
  11 Butterfly C2   18  912.20
 
  --
  David L Carlson
  Associate Professor of Anthropology
  Texas AM University
  College Station, TX 77843-4352
 
  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
  project.org] On Behalf Of Elaine Kuo
  Sent: Saturday, December 15, 2012 10:15 PM
  To: r-help@r-project.org; r-sig-geo
  Subject: [R] averaging X of specific Y (latitude)
 
  Hello
 
 
 
  I have a table describing butterfly range traits.
 
  It is composed of three columns as below
 
 
 
  Species name  range size (X)latitude of range midpoint (Y)
 
 
 
  There are 11 kinds of butterflies.
 
  Each has its range size, and the latitude of each range midpoint
 ranges
  from 9 to 19.
 
  I would like to have the average range size of every degree of
  latitude.
 
  For example, the average range size of latitude degree 10 (10.0-10.99:
  Butterfly A2, B1, B2)
 
  Please kindly help with R code to calculate the average values.
 
  Thank you.
 
 
  Elaine
 
 
  The details are as followed.
 
 
 
  Butterfly A1  130.5 9.45
 
  Butterfly A2  450.68   10.2
 
  Butterfly A3  1102.389.3
 
  Butterfly A4893.34 16.4
 
  Butterfly B1   820.2   10.54
 
  Butterfly B2872.2   10.87
 
  Butterfly B3488.2   16.79
 
  Butterfly B4620.11 18.3
 
  Butterfly B5982.78 12.98
 
  Butterfly C1   720.32 12.67
 
  Butterfly C2912.2   18.07
 
 [[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.
 
  __
  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]]
 
  __
  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

Re: [R] averaging X of specific Y (latitude)

2012-12-17 Thread Elaine Kuo
Another question (I am sure it is the last one tentatively):

After creating a text.file using dput (let's name the created file
datam),
please kindly advise how to use the text file in writing the code using
structure like below.

Thank you.

code
dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1,

+ Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
+ Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
+ Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
+ 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
+ 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
+ 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
+ Latitude), class = data.frame, row.names = c(NA, -11L)))

Elaine


On Mon, Dec 17, 2012 at 7:40 PM, Elaine Kuo elaine.kuo...@gmail.com wrote:

 One more question:

 Please kindly explain
 why it is written as row.names = c(NA, -11L)).
 (in the code below)

 I am unsure why it is negative 11.
 Thank you .

 Elaine

 code

 dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1,

 + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
 + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
 + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
 + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
 + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
 + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
 + Latitude), class = data.frame, row.names = c(NA, -11L)))



 
 
  - Original Message -
  From: David L Carlson dcarl...@tamu.edu
  To: 'Elaine Kuo' elaine.kuo...@gmail.com; r-help@r-project.org;
  'r-sig-geo' r-sig-...@stat.math.ethz.ch
  Cc:
  Sent: Sunday, December 16, 2012 11:32 AM
  Subject: Re: [R] averaging X of specific Y (latitude)
 
  It is better to use dput() in R to create a text version of your data
 for
  us
  to work with. The aggregate command below gives you the mean ranges by
  butterfly species and latititude and saves the result as Bfly. The
  colnames() command simply renames the columns:
 
  dta - structure(list(Species = structure(1:11, .Label = c(Butterfly
  A1,
 
  + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
  + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
  + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
  + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
  + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
  + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
  + Latitude), class = data.frame, row.names = c(NA, -11L))
  Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
  colnames(Bfly) - c(Species, Latitude, Mean)
  Bfly
 Species LatitudeMean
  1  Butterfly A19  130.50
  2  Butterfly A39 1102.38
  3  Butterfly A2   10  450.68
  4  Butterfly B1   10  820.20
  5  Butterfly B2   10  872.20
  6  Butterfly B5   12  982.78
  7  Butterfly C1   12  720.32
  8  Butterfly A4   16  893.34
  9  Butterfly B3   16  488.20
  10 Butterfly B4   18  620.11
  11 Butterfly C2   18  912.20
 
  --
  David L Carlson
  Associate Professor of Anthropology
  Texas AM University
  College Station, TX 77843-4352
 
  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
  project.org] On Behalf Of Elaine Kuo
  Sent: Saturday, December 15, 2012 10:15 PM
  To: r-help@r-project.org; r-sig-geo
  Subject: [R] averaging X of specific Y (latitude)
 
  Hello
 
 
 
  I have a table describing butterfly range traits.
 
  It is composed of three columns as below
 
 
 
  Species name  range size (X)latitude of range midpoint (Y)
 
 
 
  There are 11 kinds of butterflies.
 
  Each has its range size, and the latitude of each range midpoint
 ranges
  from 9 to 19.
 
  I would like to have the average range size of every degree of
  latitude.
 
  For example, the average range size of latitude degree 10
 (10.0-10.99:
  Butterfly A2, B1, B2)
 
  Please kindly help with R code to calculate the average values.
 
  Thank you.
 
 
  Elaine
 
 
  The details are as followed.
 
 
 
  Butterfly A1  130.5 9.45
 
  Butterfly A2  450.68   10.2
 
  Butterfly A3  1102.389.3
 
  Butterfly A4893.34 16.4
 
  Butterfly B1   820.2   10.54
 
  Butterfly B2872.2   10.87
 
  Butterfly B3488.2   16.79
 
  Butterfly B4620.11 18.3
 
  Butterfly B5982.78 12.98
 
  Butterfly C1   720.32 12.67
 
  Butterfly C2912.2   18.07
 
 [[alternative HTML version deleted

Re: [R] averaging X of specific Y (latitude)

2012-12-17 Thread Elaine Kuo
Thank you, David.

Now I know how to use dput.

Two more questions conjured up when running the code:
1. If there are about 500 species of butterflies,
please kindly advise if it is possible to input the butterfly names
(for .Label) using code,
instead of keying in them one by one.

2. Aggregrate command
Last time we produced the mean of range sizes.
Please kindly advise if it is possible to produce barplot showing the
value range, instead of mean.

Thank you
Elaine

code
dta - structure(list(Species = structure(1:11, .Label = c(Butterfly
 A1,

 + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
 + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
 + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
 + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
 + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
 + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
 + Latitude), class = data.frame, row.names = c(NA, -11L))
 Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
 colnames(Bfly) - c(Species, Latitude, Mean)
 Bfly
Species LatitudeMean
 1  Butterfly A19  130.50
 2  Butterfly A39 1102.38
 3  Butterfly A2   10  450.68
 4  Butterfly B1   10  820.20
 5  Butterfly B2   10  872.20
 6  Butterfly B5   12  982.78
 7  Butterfly C1   12  720.32
 8  Butterfly A4   16  893.34
 9  Butterfly B3   16  488.20
 10 Butterfly B4   18  620.11
 11 Butterfly C2   18  912.20


On Tue, Dec 18, 2012 at 12:27 AM, David L Carlson dcarl...@tamu.edu wrote:

 You are only using dput to create a version of your data that you can post
 in your email along with your question. You do not use it in your analysis.
 You originally posted a table of your data that requires extra steps for us
 to convert into a useable form so I suggested you use dput in the future to
 create a version of the data that is easy for r-help subscribers to use in
 order to recreate your data. That makes it easier to answer your question.
 

 ** **

 --

 David L Carlson

 Associate Professor of Anthropology

 Texas AM University

 College Station, TX 77843-4352

 ** **

 *From:* Elaine Kuo [mailto:elaine.kuo...@gmail.com]
 *Sent:* Monday, December 17, 2012 5:56 AM
 *To:* dcarl...@tamu.edu; r-help@r-project.org

 *Subject:* Re: [R] averaging X of specific Y (latitude)

 ** **

 Another question (I am sure it is the last one tentatively):

 ** **

 After creating a text.file using dput (let's name the created file
 datam), 

 please kindly advise how to use the text file in writing the code using
 structure like below.

 ** **

 Thank you.

 ** **

 code

 dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1,

 + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
 + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
 + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
 + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
 + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
 + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,

 + Latitude), class = data.frame, row.names = c(NA, -11L)))

 ** **

 Elaine

 ** **

 ** **

 On Mon, Dec 17, 2012 at 7:40 PM, Elaine Kuo elaine.kuo...@gmail.com
 wrote:

 One more question:

 ** **

 Please kindly explain 

 why it is written as row.names = c(NA, -11L)).

 (in the code below)

 ** **

 I am unsure why it is negative 11.

 Thank you .

 ** **

 Elaine

 ** **

 code

 ** **

 dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1,

 + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
 + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
 + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
 + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
 + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
 + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,

 + Latitude), class = data.frame, row.names = c(NA, -11L)))

 ** **


 
 
  - Original Message -
  From: David L Carlson dcarl...@tamu.edu
  To: 'Elaine Kuo' elaine.kuo...@gmail.com; r-help@r-project.org;
  'r-sig-geo' r-sig-...@stat.math.ethz.ch
  Cc:
  Sent: Sunday, December 16, 2012 11:32 AM
  Subject: Re: [R] averaging X of specific Y (latitude)
 
  It is better to use dput() in R to create a text version of your data
 for
  us
  to work with. The aggregate command below gives you the mean ranges by
  butterfly species and latititude and saves the result as Bfly. The
  colnames() command simply renames the columns:
 
  dta - structure(list(Species = structure(1:11, .Label = c(Butterfly
  A1,
 
  + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
  + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5

Re: [R] averaging X of specific Y (latitude)

2012-12-17 Thread Elaine Kuo
Hello David,

Thank you for the response.

I changed the e-mail format to text via gmail setting.

1.   the butterfly names
You are right that the butterfly names are stored in the original data.
However, in your code, it is necessary to input the names for the
command structure.
The method I used to input is
1.  display them in the original excel file, as one column with 11 rows.
2.  add commas in a column, right to the name column.
3.  copy the columns of butterfly names and commas, then pasting them
in the wordpad.
4.  copy the wordpad text with butterfly names and commas into your code

Since the method sounds tedious, particularly when the number of
butterfly names increases over 11,
I would like to ask for less time-consuming method to elicit butterfly
names as factor.
(Maybe using some R command I do not know)

2. Latitude degree
Thank you for helping generate the mean of range size per latitudinal
degree, using the code:\
Bfly - aggregate(Range~floor(Latitude), dta, mean)

Please kindly advise if it is possible to calculate the mean of range
size per 5 latitudinal degrees,
such as 6-10, 11-15, or 16-20 latitudinal degrees.

Thank you again.

Elaine

 dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1,

+ Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
+ Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
+ Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
+ 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
+ 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
+ 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
+ Latitude), class = data.frame, row.names = c(NA, -11L))
 Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
 colnames(Bfly) - c(Species, Latitude, Mean)
 Bfly
Species LatitudeMean
1  Butterfly A19  130.50
2  Butterfly A39 1102.38
3  Butterfly A2   10  450.68
4  Butterfly B1   10  820.20
5  Butterfly B2   10  872.20
6  Butterfly B5   12  982.78
7  Butterfly C1   12  720.32
8  Butterfly A4   16  893.34
9  Butterfly B3   16  488.20
10 Butterfly B4   18  620.11
11 Butterfly C2   18  912.20

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352

On Tue, Dec 18, 2012 at 11:07 AM, David L Carlson dcarl...@tamu.edu wrote:

 You should change your email format to text (you keep sending messages in
 html format).

 Where are the butterfly names? Are they not in your original data? Create
 your data.frame from the original data (which presumably has the butterfly
 names in it already). Then use dput() if you need to email the data to
 r-help. You cannot compute statistics or graphics from the result of the
 dput() function.

 Yes you can produce a barplot. Type ?barplot to get the instructions.

 --
 David L Carlson
 Associate Professor of Anthropology
 Texas AM University
 College Station, TX 77843-4352


 From: Elaine Kuo [mailto:elaine.kuo...@gmail.com]
 Sent: Monday, December 17, 2012 6:37 PM
 To: dcarl...@tamu.edu
 Cc: r-help@r-project.org
 Subject: Re: [R] averaging X of specific Y (latitude)

 Thank you, David.

 Now I know how to use dput.

 Two more questions conjured up when running the code:
 1. If there are about 500 species of butterflies,
 please kindly advise if it is possible to input the butterfly names (for
 .Label) using code,
 instead of keying in them one by one.

 2. Aggregrate command
 Last time we produced the mean of range sizes.
 Please kindly advise if it is possible to produce barplot showing the
 value range, instead of mean.

 Thank you
 Elaine

 code
 dta - structure(list(Species = structure(1:11, .Label = c(Butterfly
  A1,
 
  + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
  + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
  + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
  + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
  + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
  + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
  + Latitude), class = data.frame, row.names = c(NA, -11L))
  Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
  colnames(Bfly) - c(Species, Latitude, Mean)
  Bfly
 Species LatitudeMean
  1  Butterfly A19  130.50
  2  Butterfly A39 1102.38
  3  Butterfly A2   10  450.68
  4  Butterfly B1   10  820.20
  5  Butterfly B2   10  872.20
  6  Butterfly B5   12  982.78
  7  Butterfly C1   12  720.32
  8  Butterfly A4   16  893.34
  9  Butterfly B3   16  488.20
  10 Butterfly B4   18  620.11
  11 Butterfly C2   18  912.20
 
 On Tue, Dec 18, 2012 at 12:27 AM, David L Carlson dcarl...@tamu.edu wrote:
 You are only using dput to create a version of your data that you can post
 in your email along

Re: [R] averaging X of specific Y (latitude)

2012-12-16 Thread Elaine Kuo
Thank you, David.

Your answer reminded me of rearranging the order according to the latitude
before running the calculation.

One more question,
please kindly help with the code to calculate the mean of the ranges of the
same latitude?
Or should any re-arrangement be noticed before the mean calculation?

Thank you.

Elaine




 - Original Message -
 From: David L Carlson dcarl...@tamu.edu
 To: 'Elaine Kuo' elaine.kuo...@gmail.com; r-help@r-project.org;
 'r-sig-geo' r-sig-...@stat.math.ethz.ch
 Cc:
 Sent: Sunday, December 16, 2012 11:32 AM
 Subject: Re: [R] averaging X of specific Y (latitude)

 It is better to use dput() in R to create a text version of your data for
 us
 to work with. The aggregate command below gives you the mean ranges by
 butterfly species and latititude and saves the result as Bfly. The
 colnames() command simply renames the columns:

  dta - structure(list(Species = structure(1:11, .Label = c(Butterfly
 A1,

 + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1,
 + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5,
 + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5,
 + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
 + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
 + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range,
 + Latitude), class = data.frame, row.names = c(NA, -11L))
  Bfly - aggregate(Range~Species+floor(Latitude), dta, mean)
  colnames(Bfly) - c(Species, Latitude, Mean)
  Bfly
 Species LatitudeMean
 1  Butterfly A19  130.50
 2  Butterfly A39 1102.38
 3  Butterfly A2   10  450.68
 4  Butterfly B1   10  820.20
 5  Butterfly B2   10  872.20
 6  Butterfly B5   12  982.78
 7  Butterfly C1   12  720.32
 8  Butterfly A4   16  893.34
 9  Butterfly B3   16  488.20
 10 Butterfly B4   18  620.11
 11 Butterfly C2   18  912.20

 --
 David L Carlson
 Associate Professor of Anthropology
 Texas AM University
 College Station, TX 77843-4352

  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
  project.org] On Behalf Of Elaine Kuo
  Sent: Saturday, December 15, 2012 10:15 PM
  To: r-help@r-project.org; r-sig-geo
  Subject: [R] averaging X of specific Y (latitude)
 
  Hello
 
 
 
  I have a table describing butterfly range traits.
 
  It is composed of three columns as below
 
 
 
  Species name  range size (X)latitude of range midpoint (Y)
 
 
 
  There are 11 kinds of butterflies.
 
  Each has its range size, and the latitude of each range midpoint ranges
  from 9 to 19.
 
  I would like to have the average range size of every degree of
  latitude.
 
  For example, the average range size of latitude degree 10 (10.0-10.99:
  Butterfly A2, B1, B2)
 
  Please kindly help with R code to calculate the average values.
 
  Thank you.
 
 
  Elaine
 
 
  The details are as followed.
 
 
 
  Butterfly A1  130.5 9.45
 
  Butterfly A2  450.68   10.2
 
  Butterfly A3  1102.389.3
 
  Butterfly A4893.34 16.4
 
  Butterfly B1   820.2   10.54
 
  Butterfly B2872.2   10.87
 
  Butterfly B3488.2   16.79
 
  Butterfly B4620.11 18.3
 
  Butterfly B5982.78 12.98
 
  Butterfly C1   720.32 12.67
 
  Butterfly C2912.2   18.07
 
  [[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.

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

__
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] average X value of specific Y

2012-12-15 Thread Elaine Kuo
Hello



I have a table describing butterfly range traits.

It is composed of three columns as below



Species name  range size (X)latitude of range midpoint (Y)



There are 11 kinds of butterflies.

Each has its range size, and the latitude of each range midpoint ranges
from 9 to 19.

I would like to have the average range size of every degree of latitude.

For example, the average range size of latitude degree 10 (10.0-10.99:
Butterfly A2, B1, B2)

Please kindly help with python code to calculate the average values.

Thank you.


Elaine


The details are as followed.



Butterfly A1  130.5 9.45

Butterfly A2  450.68   10.2

Butterfly A3  1102.389.3

Butterfly A4893.34 16.4

Butterfly B1   820.2   10.54

Butterfly B2872.2   10.87

Butterfly B3488.2   16.79

Butterfly B4620.11 18.3

Butterfly B5982.78 12.98

Butterfly C1   720.32 12.67

Butterfly C2912.2   18.07

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


[R] averaging X of specific Y (latitude)

2012-12-15 Thread Elaine Kuo
Hello



I have a table describing butterfly range traits.

It is composed of three columns as below



Species name  range size (X)latitude of range midpoint (Y)



There are 11 kinds of butterflies.

Each has its range size, and the latitude of each range midpoint ranges
from 9 to 19.

I would like to have the average range size of every degree of latitude.

For example, the average range size of latitude degree 10 (10.0-10.99:
Butterfly A2, B1, B2)

Please kindly help with R code to calculate the average values.

Thank you.


Elaine


The details are as followed.



Butterfly A1  130.5 9.45

Butterfly A2  450.68   10.2

Butterfly A3  1102.389.3

Butterfly A4893.34 16.4

Butterfly B1   820.2   10.54

Butterfly B2872.2   10.87

Butterfly B3488.2   16.79

Butterfly B4620.11 18.3

Butterfly B5982.78 12.98

Butterfly C1   720.32 12.67

Butterfly C2912.2   18.07

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


Re: [R] [R-sig-Geo] averaging X of specific Y (latitude)

2012-12-15 Thread Elaine Kuo
Hello,

Yes, it is a data frame.

This is the first time to hear table function or cut function.
Please kindly point out how to use them.

By the way,
if the dataset (data frame) includes more than 2000 kinds of butterfly
range sizes and the latitude of range midpoints,
please kindly help with any suggestion to perform the task.
Thank you

Elaine

On Sun, Dec 16, 2012 at 12:20 PM, Hodgess, Erin hodge...@uhd.edu wrote:

 Hi!

 Is it a data frame, please?

 Have you tried the table function or cut function?

 Sincerely,
 Erin

 
 From: r-sig-geo-boun...@r-project.org [r-sig-geo-boun...@r-project.org]
 on behalf of Elaine Kuo [elaine.kuo...@gmail.com]
 Sent: Saturday, December 15, 2012 10:15 PM
 To: r-help@r-project.org; r-sig-geo
 Subject: [R-sig-Geo] averaging X of specific Y (latitude)

 Hello



 I have a table describing butterfly range traits.

 It is composed of three columns as below



 Species name  range size (X)latitude of range midpoint (Y)



 There are 11 kinds of butterflies.

 Each has its range size, and the latitude of each range midpoint ranges
 from 9 to 19.

 I would like to have the average range size of every degree of latitude.

 For example, the average range size of latitude degree 10 (10.0-10.99:
 Butterfly A2, B1, B2)

 Please kindly help with R code to calculate the average values.

 Thank you.


 Elaine


 The details are as followed.



 Butterfly A1  130.5 9.45

 Butterfly A2  450.68   10.2

 Butterfly A3  1102.389.3

 Butterfly A4893.34 16.4

 Butterfly B1   820.2   10.54

 Butterfly B2872.2   10.87

 Butterfly B3488.2   16.79

 Butterfly B4620.11 18.3

 Butterfly B5982.78 12.98

 Butterfly C1   720.32 12.67

 Butterfly C2912.2   18.07

 [[alternative HTML version deleted]]

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


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


Re: [R] change lm log(x) to glm poisson

2012-10-30 Thread Elaine Kuo
Hello,

Thanks for the book list.
Some are added.

   - Faraway. 2006. Extending the Linear Model With R: Generalized Linear,
   Mixed Effects and Nonparametric Regression Models (Texts in Statistical
   Science).
   - Venables and Ripley. 2002. Modern Applied Statistics with S (4th ed.).
   (Chapter 7)
   - Crawley. 2005. Statistics: An Introduction using R. (Chapter 13)


On Mon, Oct 29, 2012 at 11:35 AM, Mark Leeds marklee...@gmail.com wrote:

 Hi Josh and Elaine: John Fox's CAR book ( the companion  to his applied
 regression text ) is really great for implementing GLMs in R. It also has a
 brief but quality discussion of the theory
 behind them. His text goes into more detail. Dobson's Introduction to
 generalized linear models is also decent. So is Faraway's text but I don't
 remember the title.


 Mark








 On Sun, Oct 28, 20
 12 at 11:25 PM, Joshua Wiley jwiley.ps...@gmail.com wrote:

 Hi Elaine,

 If you want identical models, you need to use the same family and then
 the formula is the same.  Here is an example with a built in dataset:


 ## these two are identical
  coef(lm(mpg ~ hp + log(wt), data = mtcars))
  (Intercept)   hp  log(wt)
  38.86095585  -0.02808968 -13.06001270
  coef(glm(mpg ~ hp + log(wt), data = mtcars, family = gaussian))
  (Intercept)   hp  log(wt)
  38.86095585  -0.02808968 -13.06001270

 ## not identical
  coef(glm(mpg ~ hp + wt, data = mtcars, family = gaussian(link = log)))
 (Intercept)  hp  wt
  3.88335638 -0.00173717 -0.20851238

 I show the log link because the poisson family default to a log link,
 but that is equivalent to:
 log(E(y)) = Xb

 where X is your design matrix (intercept, A, B, log(C), log(D) for
 you).  In short the link function operates on the outcome, not the
 predictors so even though the poisson family includes a log link, it
 will not yield the same results as a log transformation of two of your
 predictors.

 I do not have any online references off the top of my head, but it
 seems like you may be well served by reading some about generalized
 linear models and the concept of link functions.

 Cheers,

 Josh


 On Sun, Oct 28, 2012 at 8:01 PM, Elaine Kuo elaine.kuo...@gmail.com
 wrote:
 
  Hello list,
 
  I am running a regression using
 
  lm(Y~A+B+log(C)+log(D))
 
 
  Now, I would like to test if glm can produce similar results.
  So the code was revised as
 
  glm(Y~A+B+C+D, family=poisson) (code 1)
 
 
  However, I found some example using glm for lm.
  It suggests that the code should be revised like
  glm(Y~A+B+log(C)+log(D), family=poisson) (code 2)
 
  Please kindly advise which  code is correct.
  Thank you.
 
  Elaine
 
  [[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.




 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 Programmer Analyst II, Statistical Consulting Group
 University of California, Los Angeles
 https://joshuawiley.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.




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


[R] change lm log(x) to glm poisson

2012-10-28 Thread Elaine Kuo
Hello list,

I am running a regression using

lm(Y~A+B+log(C)+log(D))


Now, I would like to test if glm can produce similar results.
So the code was revised as

glm(Y~A+B+C+D, family=poisson) (code 1)


However, I found some example using glm for lm.
It suggests that the code should be revised like
glm(Y~A+B+log(C)+log(D), family=poisson) (code 2)

Please kindly advise which  code is correct.
Thank you.

Elaine

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


[R] lm and glm

2012-10-23 Thread Elaine Kuo
Dear list,

I am making a linear regression of the following format.

lm(Y~X1+X2+log(X3)+log(X4))


Now I would like to check the linear regression above using generalized
linear model.
Please kindly if the following format is correct and thank you.
(If it is wrong, please indicate why.)

glm(Y~X1+X2+log(X3)+log(X4), family=poisson(link=log))

Also, please kindly suggest any references comparing the codes of  lm and
glm.

Elaine

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


[R] two indirect effects of path analysis

2012-10-06 Thread Elaine Kuo
Hello,

This is Elaine.

I am trying a path analysis using lavaan Package.

There are three explanatory variables: X, Z, and M.
The response variable is Y.
A, b, and c have direct effects on Y.

On the other hand, X and Z also have direct effects on M.
In other words, X and Z have indirect effects on Y.

I found the code example of lavaan package describes only one indirect
effect as below.
Please kindly advise how to modify it as two indirect effects.
Thank you.

Elaine

  set.seed(1234)
  X  -  rnorm(100)
  M  -  0.5*X  +  rnorm(100)
  Y  -  0.7*M  +  rnorm(100)
  Data  -  data.frame(X  = X,  Y  =  Y,  M  =  M)
  model  -  '  #  direct  effect
+ Y  ~  c*X
+ #  mediator
+ M  ~  a*X
+ Y  ~  b*M
+ #  indirect  effect  (a*b)
+ ab  :=  a*b
+ #  total  effect
+ total  :=  c  +  (a*b)
+ '
  fit  -  sem(model,  data=Data)
  summary(fit)

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


Re: [R] changing outlier shapes of boxplots using lattice

2012-09-28 Thread Elaine Kuo
Hello Ilai,

Thank you for the response.
It did help a lot.

However, a beginner to lattice has three questions.

Q1

Please kindly explain why in this case OP is using it with no at
argument,
so it is possible to display the median and the outliers with different pch?

Q2.
what is the relationship between package HH and graphic-drawing?
I checked ??HH and found little explanation on its function of
graphic-drawing.

Q3

Please kindly advise how to make outliers empty circle (pch=2) in this case
as the code below.
Thank you.

code

Diet.colors -
c(forestgreen,darkgreen,chocolate1,darkorange2,sienna2,

red2,firebrick3,saddlebrown,coral4,chocolate4,darkblue,navy,grey38)

levels(dataN$Diet_B) - diet.code


bwplot(MS_midpoint_lat~Diet_B, data=dataN,
xlab=list(Diet of Breeding Ground, cex = 1.4),
ylab = list(Latitudinal Midpoint Breeding Ground ,cex = 1.4),
lwd=1.5,
cex.lab=1.4, cex.axis=1.2,
font.axis=2,
cex=1.5,
las=1,
panel=panel.bwplot.intermediate.hh,
bty=l,
col=Diet.colors,
pch=rep(l,13),
scales=list(x=list(rot=90)),
par.settings=list(plot.symbol = list(pch = 2, cex =
2),box.umbrella=list(lty=1)))

Elaine


On Sat, Sep 29, 2012 at 2:44 AM, ilai ke...@math.montana.edu wrote:

 On Fri, Sep 28, 2012 at 6:57 AM, Richard M. Heiberger r...@temple.eduwrote:

 Elaine,

 For panel.bwplot you see that the central dot and the outlier dots are
 controlled by
 the same pch argument.


 ??? I don't think so...

 bwplot(rgamma(20,.1,1)~gl(2,10), pch=rep(17,2),
 panel = lattice::panel.bwplot)

 I think you mean panel.bwplot.intermidiate.hh ?

 BTW thank you for the useful HH package but in this case OP is using it
 with no at argument, so why not

 Diet.colors - c(forestgreen, darkgreen,chocolate1,darkorange2,
 sienna2,red2,firebrick3,saddlebrown,coral4,chocolate4,darkblue,navy,grey38)
  bwplot(rgamma(20*13,1,.1)~gl(13,20),
   fill = Diet.colors, pch = |,
   par.settings = list(box.umbrella=list(lty=1)))

 cheers



 I initially set the pch=| to match your first
 example with the horizontal
 indicator for the median.  I would be inclined to use the default circle
 for the outliers and
 therefore also for the median.

 Rich

 On Fri, Sep 28, 2012 at 7:13 AM, Sarah Goslee sarah.gos...@gmail.com
 wrote:

  I would guess that if you find the bit that says pch=| and change it
 to
  pch=1 it will solve your question, and that reading ?par will tell you
 why.
 
  Sarah
 
  On Thursday, September 27, 2012, Elaine Kuo wrote:
 
   Hello
  
   This is Elaine.
  
   I am using package lattice to generate boxplots.
   Using Richard's code, the display was almost perfect except the
 outlier
   shape.
   Based on the following code, the outliers are vertical lines.
   However, I want the outliers to be empty circles.
   Please kindly help how to modify the code to change the outlier
 shapes.
   Thank you.
  
   code
   package (lattice)
  
   dataN - data.frame(GE_distance=rnorm(260),
  
   Diet_B=factor(rep(1:13, each=20)))
  
   Diet.colors - c(forestgreen,
 darkgreen,chocolate1,darkorange2,
  
sienna2,red2,firebrick3,saddlebrown,coral4,
  
chocolate4,darkblue,navy,grey38)
  
   levels(dataN$Diet_B) - Diet.colors
  
   bwplot(GE_distance ~ Diet_B, data=dataN,
  
  xlab=list(Diet of Breeding Ground, cex = 1.4),
  
  ylab = list(
  
Distance between Centers of B and NB Range (1000 km),
  
cex = 1.4),
  
  panel=panel.bwplot.intermediate.hh,
  
  col=Diet.colors,
  
  pch=rep(|,13),
  
  scales=list(x=list(rot=90)),
  
  par.settings=list(box.umbrella=list(lty=1)))
  
   [[alternative HTML version deleted]]
  
   __
   R-help@r-project.org javascript:; 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.
  
 
 
  --
  Sarah Goslee
  http://www.stringpage.com
  http://www.sarahgoslee.com
  http://www.functionaldiversity.org
 
  [[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]]

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman

[R] changing outlier shapes of boxplots using lattice

2012-09-27 Thread Elaine Kuo
Hello

This is Elaine.

I am using package lattice to generate boxplots.
Using Richard's code, the display was almost perfect except the outlier
shape.
Based on the following code, the outliers are vertical lines.
However, I want the outliers to be empty circles.
Please kindly help how to modify the code to change the outlier shapes.
Thank you.

code
package (lattice)

dataN - data.frame(GE_distance=rnorm(260),

Diet_B=factor(rep(1:13, each=20)))

Diet.colors - c(forestgreen, darkgreen,chocolate1,darkorange2,

 sienna2,red2,firebrick3,saddlebrown,coral4,

 chocolate4,darkblue,navy,grey38)

levels(dataN$Diet_B) - Diet.colors

bwplot(GE_distance ~ Diet_B, data=dataN,

   xlab=list(Diet of Breeding Ground, cex = 1.4),

   ylab = list(

 Distance between Centers of B and NB Range (1000 km),

 cex = 1.4),

   panel=panel.bwplot.intermediate.hh,

   col=Diet.colors,

   pch=rep(|,13),

   scales=list(x=list(rot=90)),

   par.settings=list(box.umbrella=list(lty=1)))

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


Re: [R] boxplot of different colors

2012-09-25 Thread Elaine Kuo
hello Richard,

Thank a lot.
The plot is breathtaking.

I would like to make three modifications.
Please kindly help and thanks.

1. making outliers from dash to empty circle (pch=2)
I tried plot.symbol as the code below but failed.

2. making font size of axis (levels) larger to 1.2
unsure where to adjust in the code

3. making levels along x-axis horizontal instead of vertical
unsure where to adjust in the code.

Elaine

Code

dataN - data.frame(GE_distance=rnorm(260),

Diet_B=factor(rep(1:13, each=20)))

Diet.colors - c(forestgreen, darkgreen,chocolate1,darkorange2,

 sienna2,red2,firebrick3,saddlebrown,coral4,

 chocolate4,darkblue,navy,grey38)

levels(dataN$Diet_B) - Diet.colors

diet = list(lty=1,pch=1)

bwplot(GE_distance ~ Diet_B, data=dataN,

   xlab=list(Diet of Breeding Ground, cex = 1.4),

   ylab = list(

 Distance between Centers of B and NB Range (1000 km),

 cex = 1.4),

   panel=panel.bwplot.intermediate.hh,

   col=Diet.colors,

   pch=rep(|,13),

   scales=list(x=list(rot=90)),

   par.settings=list(box.umbrella=diet,plot.symbol = diet))




On Tue, Sep 25, 2012 at 11:48 AM, Richard M. Heiberger r...@temple.eduwrote:

 See ?panel.bwplot for pch=|.
 That explains that pch=| puts horizontal lines instead of dots at the
 median(and also at the
 outliers).
 The rep makes it into a vector to be indexed by
 panel.bwplot.intermediate.hh
 in each of its calls to panel.bwplot

 The names under each plot are the levels of the factor, in this example
 levels(Diet_B).
 You called them 1:13 in your example.  If you want to give them names do
 so as a factor.
 For example

 Control the staples with box.umbrella, again see ?panel.bwplot and
 ?trellis.par.get

 The revised example here does all three of your requests.

 dataN - data.frame(GE_distance=rnorm(260),
 Diet_B=factor(rep(1:13, each=20)))
 Diet.colors - c(forestgreen, darkgreen,chocolate1,darkorange2,
  sienna2,red2,firebrick3,saddlebrown,coral4,
  chocolate4,darkblue,navy,grey38)
 levels(dataN$Diet_B) - Diet.colors
 bwplot(GE_distance ~ Diet_B, data=dataN,
xlab=list(Diet of Breeding Ground, cex = 1.4),
ylab = list(
  Distance between Centers of B and NB Range (1000 km),
  cex = 1.4),
panel=panel.bwplot.intermediate.hh,
col=Diet.colors,
pch=rep(|,13),
scales=list(x=list(rot=90)),
par.settings=list(box.umbrella=list(lty=1)))


 On Mon, Sep 24, 2012 at 11:13 PM, Elaine Kuo elaine.kuo...@gmail.comwrote:

 Hello Richard,

 Your answer is a great help to my problem.
 The boxplot of 13 colors is very beautiful :)

 By the way, I have three subsequent questions of your code

 1. the meaning of  pch=rep(|,13)
 I read the R manual but could not interpret the part.
 pch means the point type in plot, but here not sure.

 2. how to write names under each box
 In boxplot, names can explain each box,
 but here names does not work.

 3. how to make staple from dash to solid line

 Thanks again

 Elaine

 On Tue, Sep 25, 2012 at 7:00 AM, Richard M. Heiberger r...@temple.eduwrote:

 ## I would do this in lattice using the panel.bwplot.intermediate.hh
 ## function from the HH package.

 ## install.packages(HH) ## if necessary
 library(HH)

 dataN - data.frame(GE_distance=rnorm(260),
 Diet_B=factor(rep(1:13, each=20)))
 Diet.colors - c(forestgreen, darkgreen,chocolate1,darkorange2,
   sienna2,red2,firebrick3,saddlebrown,coral4,
  chocolate4,darkblue,navy,grey38)
 bwplot(GE_distance ~ Diet_B, data=dataN,
xlab=list(Diet of Breeding Ground, cex = 1.4),
ylab = list(
  Distance between Centers of B and NB Range (1000 km),
  cex = 1.4),
panel=panel.bwplot.intermediate.hh,
col=Diet.colors,
pch=rep(|,13))


 On Mon, Sep 24, 2012 at 6:23 PM, Elaine Kuo elaine.kuo...@gmail.comwrote:

 Hello,

 I am making a boxplot of 13 boxes.
 I tried to color the box using 13 colors but failed.
 Only red and brown were displayed.
 Green, blue, and grey disappeared.

 Please kindly advise modification after checking the code below.
 Thank you in advance.

 Elaine

 R code
 # data input
 dataN

 -read.csv(H:/a_mig_distance_B_NB/R_data/Mig_bird_586_20120925.csv,header=T,
 row.names=1)
 dim(dataN)
 dataN[1,]
 str(dataN)

   # graph
 par(mai=c(1,1.03,0.4,0.4))

 obs.group-dataN$Diet_B

 par(new=T)

 boxplot(GE_distance~Diet_B, data=dataN,xlab=Diet  of  Breeding
  Ground,ylab=,
 yaxt=n,type=p,
 pch=1,lwd=0.95,
 cex.lab=1.4, cex.axis=1.2,
 font.axis=2,
 cex=1.5,
 las=1,
 bty=l,
 col=c(forestgreen,
 darkgreen,chocolate1,darkorange2,sienna2,
 red2,firebrick3,


 saddlebrown,coral4,chocolate4,darkblue,navy,grey38)[obs.group]))

 op = par(mar = c(5,5,4,2) + 0.1)
 title(ylab = Distance between Centers

[R] boxplot of different colors

2012-09-24 Thread Elaine Kuo
Hello,

I am making a boxplot of 13 boxes.
I tried to color the box using 13 colors but failed.
Only red and brown were displayed.
Green, blue, and grey disappeared.

Please kindly advise modification after checking the code below.
Thank you in advance.

Elaine

R code
# data input
dataN
-read.csv(H:/a_mig_distance_B_NB/R_data/Mig_bird_586_20120925.csv,header=T,
row.names=1)
dim(dataN)
dataN[1,]
str(dataN)

  # graph
par(mai=c(1,1.03,0.4,0.4))

obs.group-dataN$Diet_B

par(new=T)

boxplot(GE_distance~Diet_B, data=dataN,xlab=Diet  of  Breeding
 Ground,ylab=,
yaxt=n,type=p,
pch=1,lwd=0.95,
cex.lab=1.4, cex.axis=1.2,
font.axis=2,
cex=1.5,
las=1,
bty=l,
col=c(forestgreen, darkgreen,chocolate1,darkorange2,sienna2,
red2,firebrick3,

saddlebrown,coral4,chocolate4,darkblue,navy,grey38)[obs.group]))

op = par(mar = c(5,5,4,2) + 0.1)
title(ylab = Distance between Centers of B and NB Range (1000 km),
cex.lab = 1.4,line = 3)

axis(side=2,yaxp=c(0,2,4),cex.lab=1.4, cex.axis=1.2,font.axis=2,
las=1)

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


Re: [R] boxplot of different colors

2012-09-24 Thread Elaine Kuo
Hello Richard,

Your answer is a great help to my problem.
The boxplot of 13 colors is very beautiful :)

By the way, I have three subsequent questions of your code

1. the meaning of  pch=rep(|,13)
I read the R manual but could not interpret the part.
pch means the point type in plot, but here not sure.

2. how to write names under each box
In boxplot, names can explain each box,
but here names does not work.

3. how to make staple from dash to solid line

Thanks again

Elaine

On Tue, Sep 25, 2012 at 7:00 AM, Richard M. Heiberger r...@temple.eduwrote:

 ## I would do this in lattice using the panel.bwplot.intermediate.hh
 ## function from the HH package.

 ## install.packages(HH) ## if necessary
 library(HH)

 dataN - data.frame(GE_distance=rnorm(260),
 Diet_B=factor(rep(1:13, each=20)))
 Diet.colors - c(forestgreen, darkgreen,chocolate1,darkorange2,
  sienna2,red2,firebrick3,saddlebrown,coral4,
  chocolate4,darkblue,navy,grey38)
 bwplot(GE_distance ~ Diet_B, data=dataN,
xlab=list(Diet of Breeding Ground, cex = 1.4),
ylab = list(
  Distance between Centers of B and NB Range (1000 km),
  cex = 1.4),
panel=panel.bwplot.intermediate.hh,
col=Diet.colors,
pch=rep(|,13))


 On Mon, Sep 24, 2012 at 6:23 PM, Elaine Kuo elaine.kuo...@gmail.comwrote:

 Hello,

 I am making a boxplot of 13 boxes.
 I tried to color the box using 13 colors but failed.
 Only red and brown were displayed.
 Green, blue, and grey disappeared.

 Please kindly advise modification after checking the code below.
 Thank you in advance.

 Elaine

 R code
 # data input
 dataN

 -read.csv(H:/a_mig_distance_B_NB/R_data/Mig_bird_586_20120925.csv,header=T,
 row.names=1)
 dim(dataN)
 dataN[1,]
 str(dataN)

   # graph
 par(mai=c(1,1.03,0.4,0.4))

 obs.group-dataN$Diet_B

 par(new=T)

 boxplot(GE_distance~Diet_B, data=dataN,xlab=Diet  of  Breeding
  Ground,ylab=,
 yaxt=n,type=p,
 pch=1,lwd=0.95,
 cex.lab=1.4, cex.axis=1.2,
 font.axis=2,
 cex=1.5,
 las=1,
 bty=l,
 col=c(forestgreen, darkgreen,chocolate1,darkorange2,sienna2,
 red2,firebrick3,


 saddlebrown,coral4,chocolate4,darkblue,navy,grey38)[obs.group]))

 op = par(mar = c(5,5,4,2) + 0.1)
 title(ylab = Distance between Centers of B and NB Range (1000 km),
 cex.lab = 1.4,line = 3)

 axis(side=2,yaxp=c(0,2,4),cex.lab=1.4, cex.axis=1.2,font.axis=2,
 las=1)

 [[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]]

__
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] boxplot of different colors

2012-09-24 Thread Elaine Kuo
Hello Sarah,

Thanks for the suggestion of
table(obs.group).

I checked it and found no problems of the obs.group.

As for using dput(),
please kindly share some examples to display the colored graph in r-help.
In fact, some colors were assigned to all types of diets, like
A=red1
B=red2
C=green1
D=green4
E=darkgreen
F=orange3
G=darkorange2
H=navy
I=blue1

However, the boxplot displays as
A=red1
B=red2
C=green1
D=green4
E=red1
F=red2
G=green1
H=green4
I=red1.

I am wondering if there is any bug in showing too many colors for boxplot.

Elaine


On Tue, Sep 25, 2012 at 6:52 AM, Sarah Goslee sarah.gos...@gmail.comwrote:

 Hi Elaine,

 Without a reproducible example it's impossible to say, but I'd take a
 hard look at:
 table(obs.group)

 If that doesn't give you some insight, a small reproducible example
 included in your email using dput() would allow us to answer you more
 effectively.

 Sarah


 On Mon, Sep 24, 2012 at 6:23 PM, Elaine Kuo elaine.kuo...@gmail.com
 wrote:
  Hello,
 
  I am making a boxplot of 13 boxes.
  I tried to color the box using 13 colors but failed.
  Only red and brown were displayed.
  Green, blue, and grey disappeared.
 
  Please kindly advise modification after checking the code below.
  Thank you in advance.
 
  Elaine
 
  R code
  # data input
  dataN
 
 -read.csv(H:/a_mig_distance_B_NB/R_data/Mig_bird_586_20120925.csv,header=T,
  row.names=1)
  dim(dataN)
  dataN[1,]
  str(dataN)
 
# graph
  par(mai=c(1,1.03,0.4,0.4))
 
  obs.group-dataN$Diet_B
 
  par(new=T)
 
  boxplot(GE_distance~Diet_B, data=dataN,xlab=Diet  of  Breeding
   Ground,ylab=,
  yaxt=n,type=p,
  pch=1,lwd=0.95,
  cex.lab=1.4, cex.axis=1.2,
  font.axis=2,
  cex=1.5,
  las=1,
  bty=l,
  col=c(forestgreen,
 darkgreen,chocolate1,darkorange2,sienna2,
  red2,firebrick3,
 
 
 saddlebrown,coral4,chocolate4,darkblue,navy,grey38)[obs.group]))
 
  op = par(mar = c(5,5,4,2) + 0.1)
  title(ylab = Distance between Centers of B and NB Range (1000 km),
  cex.lab = 1.4,line = 3)
 
  axis(side=2,yaxp=c(0,2,4),cex.lab=1.4, cex.axis=1.2,font.axis=2,
  las=1)

 --
 Sarah Goslee
 http://www.functionaldiversity.org


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


[R] boxplot of multi box color

2012-09-24 Thread Elaine Kuo
Hello,

I want to draw a boxplot using 13 colors for 13 boxes.
Each box represents a type of diet of birds.
Y axis is the breeding range of the birds.

I checked the previous r-help and found a possible solution.

However, it did not work by showing error in ncol(Diet_B), Diet_B not
found.
Please kindly help with modification and thank you.
Also, if anything is unclear, please let me know.


code
# data input
dataN -read.csv(H:/Mig_bird_586_20120925.csv,header=T, row.names=1)
dataN$Diet_B -factor(dataN$Diet_B)

# graph
par(mai=c(1,1.03,0.4,0.4))
boxplot(GE_distance~Diet_B, data=dataN, col = rep(seq(ncol(Diet_B)) +
1, each = 1))

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


[R] To predict Y based on only one sample of X and Y

2012-08-27 Thread Elaine Kuo
Hello



I want to predict wing length using regression commands. (lm and predict)

The data details are as followed



Data:

Bird physiological data

1. body mass

2. body length

3. wing length



Data type:

Order A: consisting of 20 species,

body mass and length of all 20 species are measured

Order B: consisting of 2 species, body mass and length of only 1 species is
measured

Order C: consisting of 5 species, body mass and length of only 1 species is
measured



Method:

1.  for order A, using predict and lm

datam.lm -lm(Wing.Length~Body.mass+Body.Length)



However, for order B and C, please kindly advise any method to get wing
length based on body mass and length.

(phylogenic relationship is tentatively neglected)



Thank you


Elaine

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


[R] how to generate response variables using simple regression

2012-08-26 Thread Elaine Kuo
Hello,

I have weight and wing length data of 5 kinds of birds (B1 to B5).
Weight data (predictor) and wing data (response) were used to generated a
simple regression.
(using lm)

Now some weight data are found but without wing data (B6, B7).
I want to use the generated simple regression to produce wing data of B6
and B7 by their weight data.
Please kindly advise R code to carry it out.
Thank you.

Elaine

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


Re: [R] how to print km square in the form of km2

2012-02-29 Thread Elaine Kuo
Hello Rolf,

Thank you for the response.

I tried your command but it did not work.
 plot(1:10,ylab=y,xlab=**expression(plain(km)^2))

Please kindly advise any other method to make 2 in km2 become a uppercase
number.
Thanks again.

Elaine


On Tue, Feb 21, 2012 at 8:24 AM, Rolf Turner rolf.tur...@xtra.co.nz wrote:

 On 21/02/12 12:54, Elaine Kuo wrote:

 Hello,

 This is Elaine.

 I am drawing a plot with x-axis label with km square as the unit.
 Now I want to print km square in the form of km2 and output 2 as the
 uppercase.
 Please kindly help suggest command to show the uppercase.


 When you say as [the] uppercase I *think* you mean as a
 superscript.  Assuming that I am correct in my supposition,
 you can achieve what you want via the syntax shown in the
 following example:

plot(1:10,ylab=y,xlab=**expression(plain(km)^2))

 For details on how you do this sort of thing in general see:

?plotmath

 Be warned --- it's tricky!  I find that I always need to experiment
 quite a lot before I get it right.  Experimentation is cheap, but.

 HTH

cheers,

Rolf Turner


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


[R] how to print km square in the form of km2

2012-02-20 Thread Elaine Kuo
Hello,

This is Elaine.

I am drawing a plot with x-axis label with km square as the unit.
Now I want to print km square in the form of km2 and output 2 as the
uppercase.
Please kindly help suggest command to show the uppercase.

Thank you.

Elaine

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


[R] to check if a group of values is randomly distributed

2011-05-13 Thread elaine kuo
Dear list,

I have 603 numbers depicting range sizes of birds in Japan.
I would like to learn if the 603 range sizes are randomly distributed or
not, in order to check if they meet mid-domain effects.

Please kindly advise if any R package or function can check the fit.
Also, any more references are highly appreciated.
Thank you

Elaine

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


[R] How to calculate squared R of spatial autoregressive models

2010-11-21 Thread elaine kuo
Dear List,



I am comparing the squared R values of linear models and its spatial
autoregressive counterparts. (SARerror)

(1. lm (Y~X1)

2. lm (Y~ X1+X2)

3. lm(Y~X1+X2+X3))



The squared R values of linear models are generated by command summary (lm).


Similarly, I tried to produce those of spatial autoregressive models based
on

the squared Pearson’s correlation of explanatory and response variables. It
failed



The code is as followed.

Please kindly modify the code and thank you.



1. single predictor

sar.x1 -errorsarlm(Y~X1,data=datam.std,listw=nb8.w, na.action=na.omit,
method=Matrix, zero.policy=TRUE)

summary(sar.x1)

cor(sar.x1$X1, sar.x1$Y, method = pearson)



error message

error in cor(sar.x1$ X1, sar.x1$Y, method = pearson) :

  supply both 'x' and 'y' or a matrix-like 'x'



2. multiple predictors

sar.all -errorsarlm(Y~X1+X2+X3,data=datam.std,listw=nb8.w,
na.action=na.omit, method=Matrix, zero.policy=TRUE)

summary(sar.all)

cor(sar.all$X1+ sar.all$X2+ sar.all$X3, sar.x1$Y, method = pearson)



error message

error in cor(sar.all$X1+ sar.all$X2+ sar.all$X3, sar.x1$Y, method =
pearson) :

  supply both 'x' and 'y' or a matrix-like 'x'



Elaine

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


[R] discerning plot dots using colors

2010-10-26 Thread elaine kuo
Dear List,



I am using the command plot to present the relationship

between bird richness (Y axis) and elevation (X axis).



However, I would like to observe

the distributions of bird richness in different administrative areas (A, B,
C, …., G) in this plot.

For example, the dots in area A might fall in the upper right part of the
plot, while those in area B might appear in the middle of the elevation
range.



Please kindly advise how to differentiate the dots in distinct areas using
colors.

Thank you.



Elaine

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


[R] delta AIC for models with 2 variables using MuMIn

2010-10-12 Thread elaine kuo
Dear List,

I want to ask a AIC question based on package library(MuMIn)

The relative importance of 16 explanatory variables

are assessed using delta AIC in a generalized linear model.


Please kindly advise if it is possible to show models

with any two only certain variables.

Thank you.


Elaine

I asked a similar question and got a great help for models

with only one variable as below.

~~

In effect, you want

data(Cement)
lm1 - lm(y ~ ., data = Cement)
dd - dredge(lm1, subset = X1)

want - with(dd, is.na(X)  is.na(X2)  is.na(X3)  is.na(X4))
want
## how many models selected?
sum(want)
## OK selected just 1, show it
dd[want, , drop = FALSE]

Oh, actually, I suppose you could automate this, so it will return all
models with single variable:

dd - dredge(lm1)
parms - !is.na(dd[, -c(1, (ncol(dd) - c(0:7)))])
want - which(rowSums(parms) == 1)
dd[want, ]

Having said all this, I don't think this is a good way to do model
selection.

G

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


[R] Extracting data subset for plot

2010-10-11 Thread elaine kuo
Dear list,



I want to make a plot based on the following information, using the command
plot.

variable A for x axis : temperature (range: -20 degrees to 40 degree)

variable B for y axis : altitude (range: 50 m to 2500 m )



The data below 0 degree of X variable wants to be erased tentatively.

Please kindly advise the command to extract the data ranging from 0 degree
to 40 degrees.

Thank you.



Elaine

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


[R] How to set the limit of abline (regression line of lm)

2010-09-20 Thread elaine kuo
Dear List,



I ran a regression model using lm and produced a regression line using
abline.


The line ranges from -20 to 20 in x axis,

and the section I only want is from -20 to 0.



Please kindly advise any function in abline () to set the range of x axes.

Thank you



Elaine

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


[R] how to show the number of each axis interval (plot)

2010-09-20 Thread elaine kuo
Dear List,

I am using plot for homework.

The x-axis covered from 0 to 80, with 4 intervals.
However, the plot only showed 0, 40, 80.
20 and 60 disappeared.

Please kindly advise how to show 0, 20, 40, 60, 80 for the axis interval.

Thank you.

Elaine

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


Re: [R] how to plot y-axis on the right of x-axis

2010-08-25 Thread elaine kuo
Thank you.
The answers provides the right direction and a code was written accordingly.

One more request, if the label of axis X wants to be drawn from 5 to 1 (left
to right)
rather than 1 to 5, is it fine to change axis (4, at = NULL) ?
If so, which value should be input ?

Thanks again.

Elaine

code
plot(1:5,axes=FALSE)
axis(1)
axis(4)
box()




On Wed, Aug 25, 2010 at 5:39 PM, Jim Lemon j...@bitwrit.com.au wrote:

 On 08/25/2010 09:12 AM, elaine kuo wrote:

 Dear List,

 I have a richness data distributing across 20 N to 20 S latitude. (120
 E-140
 E longitude).


 I would like to draw the richness in the north hemisphere and a regression
 line in the plot
 (x-axis: latitude, y-axis: richness in the north hemisphere).
 The above demand is done using plot.

 Then, south hemisphere richness and regression are required to be
 generated
 using
 the same y-axis above but an x-axis on the left side of the y-axis.
 (The higher latitude in the south hemisphere, the left it would move)

 Please kindly share how to design the south plot and regression line for
 richness.
 Also, please advise if any more info is in need.

  Hi Elaine,
 Changing the position of the axes is easily done by changing the side and
 pos arguments of the axis function. If you want to move the y-axis to
 the right (or as you state it, the x axis to the left):

 # y axis on the left
 plot(1:5,axes=FALSE)
 axis(1)
 axis(2)
 # add a y axis one third of the way to the right
 xylim-par(usr)
 axis(2,pos=xylim[1]+diff(xylim[1:2])/3)
 # add another y axis two thirds of the way
 axis(4,pos=xylim[2]-diff(xylim[1:2])/3)
 # add one more on the right
 axis(4)

 You can move the x axis up and down using the same tricks.

 Jim


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


Re: [R] how to plot y-axis on the right of x-axis

2010-08-25 Thread elaine kuo
Yes, I appreciated your answers which well hit my questions. (esp the
perfect model parts).

About the plot part, one more question.
Is it possible to make the two plots (northern and southern richness)
sharing the same Y axis (latitude = 0, the equator) ?
In other words, southern richness would be on the left side of the Y axis,
while northern one on the right side.

Elaine


Two plot panels on the same device like:

layout(1:2)
plot(1:100)
plot(1:100)
layout(1)

=  Yes that's what I want

The second panel for southern species richness, do you mean you want the
plot to go like this:

plot(1:100, xlim = c(100,1))

=  Yes, too.

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


[R] how to plot y-axis on the right of x-axis

2010-08-24 Thread elaine kuo
Dear List,

I have a richness data distributing across 20 N to 20 S latitude. (120 E-140
E longitude).


I would like to draw the richness in the north hemisphere and a regression
line in the plot
(x-axis: latitude, y-axis: richness in the north hemisphere).
The above demand is done using plot.

Then, south hemisphere richness and regression are required to be generated
using
the same y-axis above but an x-axis on the left side of the y-axis.
(The higher latitude in the south hemisphere, the left it would move)

Please kindly share how to design the south plot and regression line for
richness.
Also, please advise if any more info is in need.

Elaine

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


Re: [R] AIC in MuMIn

2010-08-19 Thread elaine kuo
 
  Please kindly advise if it is possible to show the singular model with
  only one certain variable using the command subset. (or maybe others)
  I tried the command subset=X3 but it returned multiple models
  including X3.
 
 
  The above demand might look unnecessary when visual inspection offers
  the solution with few exp. variables.
  However, it is of great importance for recognizing AIC for each
  variable in the model selection with more than 10 variables.

 No, there isn't. The object returned by dredge is a data frame so you
 can subset it to your hearts content, but you'll need to select rows
 where you specify that all your variables (except the one you are
 interested in) are missing (NA). Without writing this all out, I don't
 know of a quick way of doing this sort of subsetting.

 In effect, you want

 data(Cement)
 lm1 - lm(y ~ ., data = Cement)
 dd - dredge(lm1, subset = X1)

 want - with(dd, is.na(X)  is.na(X2)  is.na(X3)  is.na(X4))
 want
 ## how many models selected?
 sum(want)
 ## OK selected just 1, show it
 dd[want, , drop = FALSE]

 Oh, actually, I suppose you could automate this, so it will return all
 models with single variable:

 dd - dredge(lm1)
 parms - !is.na(dd[, -c(1, (ncol(dd) - c(0:7)))])
 want - which(rowSums(parms) == 1)
 dd[want, ]

 Having said all this, I don't think this is a good way to do model
 selection.
 =


Thanks for the time-efficient formula.
Actually it is over my current ability to automate it, but it did save a lot
of time already.
Moreover, please kindly explain the command beginning with parms.
data (Cement) was checked but could not ensure why the row and the column
were set to be 1 and (ncol(dd) - c(0:7)).

Elaine

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


Re: [R] AIC in MuMIn

2010-08-18 Thread elaine kuo
 Hmmm. Thinking some more, I might not have answered your (unstated)
 question. What do your mean by GLM?

 = I meant generalized linear model as well. Thanks for the references.
The first one was mentioned first in my life time after keeping asking
the same question.


 I mean the Generalized Linear Model, not the General Linear Model. The
 Generalized one allows for non-normal responses and different
 mean-variance relationships and is the GLM of Nelder and Wedderburn
 (1972, J. Royal Statistical Society, Series A, 135(3),370-384) and the
 monograph by McCullagh and Wedderburn (1989, Generalized Linear Models,
 Chapman  Hall/CRC). The R function glm() fits these kinds of model.

 The General Linear Model (IIRC) was the linking of linear regression and
 anova into a single entity. The R function lm() fits these kinds of
 models.

 The linear model is a special case of the Generalized Linear Model when
 the Gaussian error is used with the identity link function. Hence a
 Gaussian GLM (my GLM) with the identity link fitted by glm() will give
 the same results as lm(), but it will do so in a very inefficient
 manner. As this was what your code was doing I suggested using lm()
 instead.


= Thanks for the important suggestion.
I tried both lm and glm until now but no one commented on the method.


 Elaine


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


Re: [R] AIC in MuMIn

2010-08-18 Thread elaine kuo


 
 Please suggest how to define subset in my case

 How would I know? I still haven't seen your data. You seem to be
 mistaken on what is and is not included in your model and you fitted it.
 What hope do we have...? However, given the model 'mig.stds' from above
 in this email:

  mig.stds -lm(SummerM_ratio ~ temp_max + evi_mean + topo_var +
   topo_mean + coast + Iso_index_0808,
   ## now tell R were to find the variables in formula
   data = datum.std)
  ## If you are fitting a Gaussian GLM it is better fitted with lm()

 If you want to consider dredged models containing temp_max, then you
 would do

 dredge(mig.stds, subset = temp_max)

 If you want models that contain temp_max and coast, then you'd do

 dredge(mig.stds, subset = temp_max  coast)

 or

 dredge(mig.stds, fixed = ~ temp_max + coast)

 The bits you include in subset or fixed are the names of your variables
 that you want in or out of the models. In your case, the names of the
 variables as input into the model formula. With 'subset' you need to use
 logical operators (and [], or [|]) whilst with 'fixed' you can specify
 a formula of variables that should be included or excluded in the same
 way you'd write any R formula.

 But, now having been told this, please note that this is *all* discussed
 on the ?dredge help page if you bother to read it. I've never used this
 package, and, OK, I have used R for going on for 11 or 12 years now so
 am used to reading help pages and understand the language a bit more you
 perhaps do, but you do seem to be asking questions or running into
 problems that are all covered by the help pages.

 = I posted it for help, after following the manual with the command dredge
 but receiving an error message two days ago.



  command   target-dredge(mig.stds,  subset  =  temp_max)

   error  in eval(expr, envir, enclos) : 'temp_max' not found

 One possible cause could be data = datam.std.
 datam.std was produced as the code below, which seemed to make it hard to
find explanatory variables.
 Please kindly share your experience in R, because I am unsure if my
assumption is logical or not.

Also, please kindly advise how to modify the command for dredging subset if
possible.
( command   target-dredge(mig.stds,  subset  =  temp_max))
Thank you in advance.

Elaine

code
library(MuMIn)
datam -read.csv(c:/migration/Mig_ratio_20100817.csv,header=T,
row.names=1)

 # std regression model (16 indep. variables)
  datam.sd-scale(datam)
  datam.std-as.data.frame(datam.sd)
  summary (datam.std)
  mean(datam.std)

# obtain standard deviation
sd(datam.std)

mig.stds
-lm(SummerM_ratio~temp_ran+temp_mean+temp_max+temp_min+evi_ran+evi_mean+evi_max+evi_min+prec_ran+prec_mean+prec_max+prec_min+topo_var+topo_mean+coast+Iso_index_0808,data=datam.std)

summary(mig.stds)

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


Re: [R] AIC in MuMIn

2010-08-18 Thread elaine kuo
A cause other than data based on standardized regression was identified.
It is that the manual command added with target - at the left hand side.


C1 did not work but C2 did.
C1 target-dredge(mig.stds,  subset  =  temp_max)

C2 dredge(mig.stds,  subset  =  temp_max)

Elaine

On Wed, Aug 18, 2010 at 5:37 PM, elaine kuo elaine.kuo...@gmail.com wrote:


 
 Please suggest how to define subset in my case

 How would I know? I still haven't seen your data. You seem to be
 mistaken on what is and is not included in your model and you fitted it.
 What hope do we have...? However, given the model 'mig.stds' from above
 in this email:

  mig.stds -lm(SummerM_ratio ~ temp_max + evi_mean + topo_var +
   topo_mean + coast + Iso_index_0808,
   ## now tell R were to find the variables in formula
   data = datum.std)
  ## If you are fitting a Gaussian GLM it is better fitted with lm()

 If you want to consider dredged models containing temp_max, then you
 would do

 dredge(mig.stds, subset = temp_max)

 If you want models that contain temp_max and coast, then you'd do

 dredge(mig.stds, subset = temp_max  coast)

 or

 dredge(mig.stds, fixed = ~ temp_max + coast)

 The bits you include in subset or fixed are the names of your variables
 that you want in or out of the models. In your case, the names of the
 variables as input into the model formula. With 'subset' you need to use
 logical operators (and [], or [|]) whilst with 'fixed' you can specify
 a formula of variables that should be included or excluded in the same
 way you'd write any R formula.

 But, now having been told this, please note that this is *all* discussed
 on the ?dredge help page if you bother to read it. I've never used this
 package, and, OK, I have used R for going on for 11 or 12 years now so
 am used to reading help pages and understand the language a bit more you
 perhaps do, but you do seem to be asking questions or running into
 problems that are all covered by the help pages.

 = I posted it for help, after following the manual with the command
 dredge but receiving an error message two days ago.



  command   target-dredge(mig.stds,  subset  =  temp_max)

error  in eval(expr, envir, enclos) : 'temp_max' not found

  One possible cause could be data = datam.std.
  datam.std was produced as the code below, which seemed to make it hard to
 find explanatory variables.
  Please kindly share your experience in R, because I am unsure if my
 assumption is logical or not.

 Also, please kindly advise how to modify the command for dredging subset if
 possible.
 ( command   target-dredge(mig.stds,  subset  =  temp_max))
 Thank you in advance.

 Elaine

 code
 library(MuMIn)
 datam -read.csv(c:/migration/Mig_ratio_20100817.csv,header=T,
 row.names=1)

  # std regression model (16 indep. variables)
   datam.sd-scale(datam)
   datam.std-as.data.frame(datam.sd)
   summary (datam.std)
   mean(datam.std)

 # obtain standard deviation
 sd(datam.std)

 mig.stds
 -lm(SummerM_ratio~temp_ran+temp_mean+temp_max+temp_min+evi_ran+evi_mean+evi_max+evi_min+prec_ran+prec_mean+prec_max+prec_min+topo_var+topo_mean+coast+Iso_index_0808,data=datam.std)

 summary(mig.stds)





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


Re: [R] AIC in MuMIn

2010-08-18 Thread elaine kuo
Yes, I tried the example in the ?dredge and agreed that something else
caused the mistake.

Aside from the cause which takes time to clarify (16 explanatory variables
in the model),
I would like to ask another question.

Please kindly advise if it is possible to show the singular model with only
one certain variable using the command subset. (or maybe others)
I tried the command subset=X3 but it returned multiple models including
X3.

The above demand might look unnecessary when visual inspection offers the
solution with few exp. variables.
However, it is of great importance for recognizing AIC for each variable in
the model selection with more than 10 variables.

Please kindly help and thank you in advance.

Elaine

code
library(MuMIn)

data(Cement)
lm1  -  lm(y  ~  .,  data  =  Cement)
dd  -  dredge(lm1,  beta  = FALSE,  eval  =  TRUE,  rank  =  AIC)
X3-dredge(lm1,  rank  =  AIC, subset=X3)

On Wed, Aug 18, 2010 at 9:18 PM, Gavin Simpson gavin.simp...@ucl.ac.ukwrote:

 On Wed, 2010-08-18 at 21:11 +0800, elaine kuo wrote:
  A cause other than data based on standardized regression
  was identified.
  It is that the manual command added with target - at the left hand
  side.

  C1 did not work but C2 did.
  C1 target-dredge(mig.stds,  subset  =  temp_max)
 
 
  C2 dredge(mig.stds,  subset  =  temp_max)

 Glad you have this working, but that can't possibly be the reason for
 the error. There must be something else going on. The only difference
 between the two calls is that you are storing the result somewhere, yet
 the error was coming from within the running of the dredge function.

 If everything works from within a new, clean R session then great.

 G

 
 
  Elaine
 
  On Wed, Aug 18, 2010 at 5:37 PM, elaine kuo elaine.kuo...@gmail.com
  wrote:
 
 
  
  Please suggest how to define subset in my case
 
 
  How would I know? I still haven't seen your data. You
  seem to be
  mistaken on what is and is not included in your model
  and you fitted it.
  What hope do we have...? However, given the model
  'mig.stds' from above
  in this email:
 
   mig.stds -lm(SummerM_ratio ~ temp_max + evi_mean +
  topo_var +
topo_mean + coast + Iso_index_0808,
## now tell R were to find the
  variables in formula
data = datum.std)
   ## If you are fitting a Gaussian GLM it is better
  fitted with lm()
 
 
  If you want to consider dredged models containing
  temp_max, then you
  would do
 
  dredge(mig.stds, subset = temp_max)
 
  If you want models that contain temp_max and coast,
  then you'd do
 
  dredge(mig.stds, subset = temp_max  coast)
 
  or
 
  dredge(mig.stds, fixed = ~ temp_max + coast)
 
  The bits you include in subset or fixed are the names
  of your variables
  that you want in or out of the models. In your case,
  the names of the
  variables as input into the model formula. With
  'subset' you need to use
  logical operators (and [], or [|]) whilst with
  'fixed' you can specify
  a formula of variables that should be included or
  excluded in the same
  way you'd write any R formula.
 
  But, now having been told this, please note that this
  is *all* discussed
  on the ?dredge help page if you bother to read it.
  I've never used this
  package, and, OK, I have used R for going on for 11 or
  12 years now so
  am used to reading help pages and understand the
  language a bit more you
  perhaps do, but you do seem to be asking questions or
  running into
  problems that are all covered by the help pages.
 
 
  = I posted it for help, after following the manual
  with the command dredge but receiving an error message
  two days ago.
 
   command   target-dredge(mig.stds,  subset  =
   temp_max)
 error  in eval(expr, envir, enclos) : 'temp_max' not found
 
 
   One possible cause could be data = datam.std.
   datam.std was produced as the code below, which seemed to
  make it hard to find explanatory variables.
   Please kindly share your experience in R, because I am unsure
  if my assumption is logical or not.
 
 
  Also, please kindly advise how to modify

[R] AIC in MuMIn

2010-08-17 Thread elaine kuo
Hello,

I am using package MuMIn to calculate AIC for a full model with 10
explanatory variables.
Thanks in advance in sharing your experience.

Q1
In the AIC list of all models, each model is differentiated by model number.
Please kindly advise if it is possible to
find the corresponding explanatory variable(s) for the model number.


Q2 error message
I tried to display sub-model with only temp_ran using the code below but
failed.
Please kindly suggest the potential failure cause.

code

rm(list=ls())



library(MuMIn)



datam -read.csv(c:/migration/Mig_ratio_20100817.csv,header=T,
row.names=1)



mig.stds -glm(datam.std$SummerM_ratio~
datam.std$temp_max++datam.std$evi_mean+datam.std$topo_var+datam.std$topo_mean+datam.std$coast+datam.std$Iso_index_0808,data=datam.std,family=gaussian)



target.model -  dredge(mig.stds, subset=datam.std$temp_ran)



error in eval(expr, envir, enclos), 'temp_ran' not found



Q3 showing sub-models for two assigned explanatory variables
The manual only explains how to exclude two variables.
Please advise how to contain submodels regarding certain two or more
variables.


Elaine

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


Re: [R] AIC in MuMIn

2010-08-17 Thread elaine kuo
Thank you.
Most of the answers solved the puzzles.

Q2


  I tried to display sub-model with only temp_ran using the code below but
  failed.
  Please kindly suggest the potential failure cause.
 
  code
 
  library(MuMIn)
  datam -read.csv(c:/migration/Mig_ratio_20100817.csv,header=T,
  row.names=1)


 mig.stds -lm(SummerM_ratio ~ temp_max + evi_mean + topo_var +
  topo_mean + coast + Iso_index_0808,
  ## now tell R were to find the variables in formula
  data = datum.std)
 ## If you are fitting a Gaussian GLM it is better fitted with lm()


 = Please explain why fitted lm is better for GLM.




 But temp_ran is not in your model...

  error in eval(expr, envir, enclos), 'temp_ran' not found

 When used properly (none of this datam.std$ business), subset will do
 what you want:

  dd2 - dredge(lm1, subset = X1)
  dd2
 Global model: lm(formula = y ~ ., data = Cement)
 ---
 Model selection table
(Int)X X1 X2  X3  X4 k   R.sq Adj.R.sq RSS
 3   52.58  1.4680 0.6623 4 0.9787   0.9744   57.90

 = Please suggest how to define subset in my case

Finally, it would be highly appreciated to recommend any references of R for
a beginner like me.


Elaine

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


[R] AIC for model selection in Package ‘MuMIn ’

2010-08-16 Thread elaine kuo
Dear List,

Ben's recommendation to MuMIn is of great importance to research with over
ten independent variables.

However, the criteria in this package for model selection are AICc
(second-order AIC) and QAIC (quasi-AIC).
Please kindly share if it is possible to carry AIC rather than the metrics
above using this package.
Thank you.

Elaine

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


Re: [R] AIC for model selection in Package â� �MuMInâ��

2010-08-16 Thread elaine kuo
Thanks for Ben.

Model selection by AIC is feasible by the code below.
One more question, when is it appropriate to carry out model averaging and
parameter averaging?

code
library(MuMIn)
data(Cement)
lm1  -  lm(y  ~  .,  data  =  Cement)
dd  -  dredge(lm1,  beta  = TRUE,  eval  =  TRUE,  rank  =  AIC)
print(dd)

Elaine

On Mon, Aug 16, 2010 at 9:21 PM, Ben Bolker bbol...@gmail.com wrote:

 elaine kuo elaine.kuo.tw at gmail.com writes:

 [re: MuMIn package]

  However, the criteria in this package for model selection are AICc
  (second-order AIC) and QAIC (quasi-AIC).
  Please kindly share if it is possible to carry AIC rather than the
 metrics
  above using this package.
  Thank you.

  I think you're misunderstanding the documentation.  The reason
 that AICc and QAIC are explicitly included in the package, and the
 package documentation, is that (unlike AIC and BIC) they are *not*
 implemented in base R.  If you simply use dredge(...,rank=AIC)
 that should work.

  good luck.

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

__
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] Independent variables omitted in lm and glm

2010-08-16 Thread elaine kuo
Dear List,



Some independent variable were missing in calculation using lm and glm
(gaussian).

(X= Y1+Y2+…..+Y16, Independent number: 16 variable)

However, those variables did work well in cor(X, Y) respectively.

str(dataframe) was also run to ensure that the variables were all numbers.



Moreover, the missing variables were different in lm and glm.

In lm, 3 factors were not taken into consideration.

In glm, only one of them was omitted.

(attached 2 shots)



Please kindly advise whether further info is in need to solve the issue.

Also, if similar problems have been encountered, please kindly share your
experience.

Thank you.


Elaine





Code

rm(list=ls())

library(MuMIn)



datam -read.csv(c:/migration/Mig_ratio_20100817.csv,header=T,
row.names=1)



dim(datam)

datam[1,]



# original regression model (16 indep. variables)

  Mig.lm
-lm(datam$SummerM_ratio~datam$temp_ran+datam$temp_mean+datam$temp_max+datam$temp_min+datam$evi_ran+datam$evi_mean+datam$evi_max+datam$evi_min+datam$prec_ran+datam$prec_mean+datam$prec_max+datam$prec_min+datam$topo_var+datam$topo_mean+datam$coast+datam$Iso_index_0808,data=datam)



  summary(mig.lm)



  mig.glm
-glm(datam$SummerM_ratio~datam$temp_ran+datam$temp_mean+datam$temp_max+datam$temp_min+datam$evi_ran+datam$evi_mean+datam$evi_max+datam$evi_min+datam$prec_ran+datam$prec_mean+datam$prec_max+datam$prec_min+datam$topo_var+datam$topo_mean+datam$coast+datam$Iso_index_0808,data=datam,family=gaussian)



  summary(mig.glm)

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


Re: [R] Independent variables omitted in lm and glm

2010-08-16 Thread elaine kuo
sorry I forget the attachments

Dear List,



 Some independent variable were missing in calculation using lm and glm
 (gaussian).

 (X= Y1+Y2+…..+Y16, Independent number: 16 variable)

 However, those variables did work well in cor(X, Y) respectively.

 str(dataframe) was also run to ensure that the variables were all numbers.



 Moreover, the missing variables were different in lm and glm.

 In lm, 3 factors were not taken into consideration.

 In glm, only one of them was omitted.

 (attached 2 shots)



 Please kindly advise whether further info is in need to solve the issue.

 Also, if similar problems have been encountered, please kindly share your
 experience.

 Thank you.


 Elaine





 Code

 rm(list=ls())

 library(MuMIn)



 datam -read.csv(c:/migration/Mig_ratio_20100817.csv,header=T,
 row.names=1)



 dim(datam)

 datam[1,]



 # original regression model (16 indep. variables)

   Mig.lm
 -lm(datam$SummerM_ratio~datam$temp_ran+datam$temp_mean+datam$temp_max+datam$temp_min+datam$evi_ran+datam$evi_mean+datam$evi_max+datam$evi_min+datam$prec_ran+datam$prec_mean+datam$prec_max+datam$prec_min+datam$topo_var+datam$topo_mean+datam$coast+datam$Iso_index_0808,data=datam)



   summary(mig.lm)



   mig.glm
 -glm(datam$SummerM_ratio~datam$temp_ran+datam$temp_mean+datam$temp_max+datam$temp_min+datam$evi_ran+datam$evi_mean+datam$evi_max+datam$evi_min+datam$prec_ran+datam$prec_mean+datam$prec_max+datam$prec_min+datam$topo_var+datam$topo_mean+datam$coast+datam$Iso_index_0808,data=datam,family=gaussian)



   summary(mig.glm)

__
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] how to display delta AIC of all models

2010-08-15 Thread elaine kuo
Dear all,

I am making model selection of generalised linear models based on delta
AIC,
using the command step(AIC).

Also, I would like to learn the explanatory powers of each independent
variable.
To phrase differently, it is in need to show the delta AIC of all models
rather than the final model with the least delta AIC.

Please kindly advise if it is possible to exhibit all delta AIC of different
combinations of the independent variables.
Thank you.

Elaine

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


Re: [R] what is scaling in plot

2010-08-14 Thread elaine kuo
code

rm(list=ls())
library(vegan)
library(MASS)

data(varespec)
print(varespec)
str(varespec)


#PCA
vare.pca  -  rda(varespec)
vare.pca
plot(vare.pca)
sum(apply(varespec, 2, var))
biplot(vare.pca,  scaling  =  -1)

Elaine

On Sat, Aug 14, 2010 at 10:48 AM, Ben Bolker bbol...@gmail.com wrote:

 elaine kuo elaine.kuo.tw at gmail.com writes:

  Pls kindly advise what scaling is in plot.
  Sometime it could be negative but sometimes it might be positive
  .(I guess it is the proportion between the plot and the margin)

   Your question is unclear. Please give more context and/or details.

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

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


  1   2   >