Re: [R] Function argument and scope

2016-11-13 Thread Jim Lemon
Hi Bernardo,
I don't think that your function is doing anything like you expect it to do:

test <- data.frame(var1=c("a","b","c"),var2=c("d","e","f"))
test
 var1 var2
1ad
2be
3cf

You have a data frame with two columns, the first thing you do is
extract the first value in the first column:

test[1,1]
[1] a
Levels: a b c

Okay, looks like the first column is a factor. The next operation,
strsplit, requires a character argument

strsplit(test[1,1]," ")
Error in strsplit(test[1, 1], " ") : non-character argument

Not what you have. Go back to the beginning and create the data frame
without the values becoming factors:

test <- data.frame(var1=c("a","b","c"),var2=c("d","e","f"),
 stringsAsFactors=FALSE)

> strsplit(test[1,1]," ")
[[1]]
[1] "a"

Now strsplit doesn't complain, but just gives you back the first
value. As it is only of length 1, the conditional fails and the
function returns the initial data frame. Try as I might, I cannot work
out what you are trying to do, so I will await further information.

Jim


On Mon, Nov 14, 2016 at 9:09 AM, Bernardo Doré  wrote:
> Hello list,
>
> my first post but I've been using this list as a help source for a while.
> Couldn't live without it.
>
> I am writing a function that takes a dataframe as an argument and in the
> end I intend to assign the result of some computation back to the
> dataframe. This is what I have so far:
>
> myFunction <- function(x){
>   y <- x[1,1]
>   z <- strsplit(as.character(y), split = " ")
>   if(length(z[[1]] > 1)){
> predictedWord <- z[[1]][length(z[[1]])]
> z <- z[[1]][-c(length(z[[1]]))]
> z <- paste(z, collapse = " ")
>   }
>   x[1,1] <- z
> }
>
> And lets say I create my dataframe like this:
> test <- data.frame(var1=c("a","b","c"),var2=c("d","e","f"))
>
> and then call
> myFunction(test)
>
> The problem is when I assign x[1,1] to y in the first operation inside the
> function, x becomes a dataframe inside the function scope and loses the
> reference to the dataframe "test" passed as argument. In the end when I
> assign z to what should be row 1 and column 1 of the "test" dataframe, it
> assigns to x inside the function scope and no modification is made on
> "test".
>
> I hope the problem statement is clear.
>
> Thank you,
>
> Bernardo Doré
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] question on mean, sum

2016-11-13 Thread Berend Hasselman

In addition to Petr's remarks:

- why are you doing sum(mtcars)[1]?  Do you want the sum of first column of 
mtcars? In that case you should do sum(mtcars[,1]).

- similar remarks apply to your use of  mean and sd.


Have you read an introduction to R?


Berend

> On 14 Nov 2016, at 04:01, moku...@sina.com wrote:
> 
> Hi, 
> I am working on functions such as sum(), mean() ... 
>> sum(mtcars)[1] 13942.2> mean(mtcars)[1] NAWarning message:In 
>> mean.default(mtcars) : NA> sd(mtcars)Error in is.data.frame(x) : ()'double'
> why got different reply?Is this a BUG for the current version of R?my version 
> info:version.string R version 3.3.1 (2016-06-21)
> 
> Thank you very much for the help.
> mokuram
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] question on mean, sum

2016-11-13 Thread PIKAL Petr
Hi

Your HTML formatted message is scrambled so it is hard to understand what is 
your problem. The probable cause is the fact that sum, mean and sd behave 
differently when applied to different objects (vector, data.frame, ...)

Post in plain text together with at least result of
str(mtcars)

Cheers
Petr


> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of
> moku...@sina.com
> Sent: Monday, November 14, 2016 4:01 AM
> To: r-help 
> Subject: [R] question on mean, sum
>
>  Hi,
> I am working on functions such as sum(), mean() ...
> > sum(mtcars)[1] 13942.2> mean(mtcars)[1] NAWarning message:In
> mean.default(mtcars) : NA> sd(mtcars)Error in is.data.frame(x) : ()'double'
> why got different reply?Is this a BUG for the current version of R?my version
> info:version.string R version 3.3.1 (2016-06-21)
>
> Thank you very much for the help.
> mokuram
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] question on mean, sum

2016-11-13 Thread mokuram
 Hi, 
I am working on functions such as sum(), mean() ... 
> sum(mtcars)[1] 13942.2> mean(mtcars)[1] NAWarning message:In 
> mean.default(mtcars) : NA> sd(mtcars)Error in is.data.frame(x) : ()'double'
why got different reply?Is this a BUG for the current version of R?my version 
info:version.string R version 3.3.1 (2016-06-21)

Thank you very much for the help.
mokuram

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics

2016-11-13 Thread Sidoti, Salvatore A.
Hi Jim,

Nice to see you again! First of all, apologies to all for bending the rules a 
bit with respect to the mailing list. I know this is a list for R programming 
specifically, and I have received some great advice in this regard in the past. 
I just thought this was an interesting applied problem that would generate some 
discussion about PCA in R.

Yes, that is an excellent question! Indeed, why not just volume? Since this is 
still a work in progress and we have not published as of yet, I would rather 
not be more specific about the type of animal at this time ;>}. Nonetheless, I 
can say that the animals I study change "size" depending on their feeding and 
hydration state. The abdomen in particular undergoes drastic size changes. That 
being said, there are key anatomical features that remain fixed in the adult.

Now, there *might* be a way to work volume into the PCA. Although volume is not 
a reliable metric since the abdomen size is so changeable while the animal is 
alive, but what about preserved specimens? I have many that have been 
marinating in ethanol for months. Wouldn't the tissues have equilibrated by 
now? Probably... I could measure volume by displacement or suspension, I 
suppose.

In the meantime, here's a few thoughts:

1)  Use the contribution % (known as C% hereafter) of each variable on 
principle components 1 and 2.

2)  The total contribution of a variable that explains the variations 
retained by PC1 an PC2 is calculated by:

sum(C%1 * eigenvalue1, C%2 * eigenvalue2)

3) Scale() to mean-center the columns of the data set.

4) Use these total contributions as the weights of an arithmetic mean.

For example, we have an animal with the following data (mean-centered):
weight: 1.334
interoc:-0.225
clength:0.046
cwidth: -0.847

The contributions of these variables on PC1 and PC2 are (% changed to 
proportions):
weight: 0.556
interoc:0.357
clength:0.493
cwidth: 0.291

To calculate size:
1.334(0.556) - 0.225(0.357) + 0.046(0.493) - 0.847(0.291) = 0.43758
Then divide by the sum of the weights:
0.43758 / 1.697 = 0.257855 = "animal size"

This value can then be used to rank the animal according to its size for 
further analysis...

Does this sound like a reasonable application of my PCA data?

Salvatore A. Sidoti
PhD Student
Behavioral Ecology

-Original Message-
From: Jim Lemon [mailto:drjimle...@gmail.com] 
Sent: Sunday, November 13, 2016 3:53 PM
To: Sidoti, Salvatore A. ; r-help mailing list 

Subject: Re: [R] Principle Component Analysis: Ranking Animal Size Based On 
Combined Metrics

Hi Salvatore,
If by "size" you mean volume, why not directly measure the volume of your 
animals? They appear to be fairly small. Sometimes working out what the 
critical value actually means can inform the way to measure it.

Jim


On Sun, Nov 13, 2016 at 4:46 PM, Sidoti, Salvatore A.
 wrote:
> Let's say I perform 4 measurements on an animal: three are linear 
> measurements in millimeters and the fourth is its weight in milligrams. So, 
> we have a data set with mixed units.
>
> Based on these four correlated measurements, I would like to obtain one 
> "score" or value that describes an individual animal's size. I considered 
> simply taking the geometric mean of these 4 measurements, and that would give 
> me a "score" - larger values would be for larger animals, etc.
>
> However, this assumes that all 4 of these measurements contribute equally to 
> an animal's size. Of course, more than likely this is not the case. I then 
> performed a PCA to discover how much influence each variable had on the 
> overall data set. I was hoping to use this analysis to refine my original 
> approach.
>
> I honestly do not know how to apply the information from the PCA to this 
> particular problem...
>
> I do know, however, that principle components 1 and 2 capture enough of the 
> variation to reduce the number of dimensions down to 2 (see analysis below 
> with the original data set).
>
> Note: animal weights were ln() transformed to increase correlation with the 3 
> other variables.
>
> df <- data.frame(
>   weight = log(1000*c(0.0980, 0.0622, 0.0600, 0.1098, 0.0538, 0.0701, 0.1138, 
> 0.0540, 0.0629, 0.0930,
>  0.0443, 0.1115, 0.1157, 0.0734, 0.0616, 0.0640, 0.0480, 0.1339, 
> 0.0547, 0.0844,
>  0.0431, 0.0472, 0.0752, 0.0604, 0.0713, 0.0658, 0.0538, 0.0585, 
> 0.0645, 0.0529,
>  0.0448, 0.0574, 0.0577, 0.0514, 0.0758, 0.0424, 0.0997, 0.0758, 
> 0.0649, 0.0465,
>  0.0748, 0.0540, 0.0819, 0.0732, 0.0725, 0.0730, 0.0777, 0.0630, 
> 0.0466)),
>   interoc = c(0.853, 0.865, 0.811, 0.840, 0.783, 0.868, 0.818, 0.847, 0.838, 
> 0.799,
>   0.737, 0.788, 0.731, 0.777, 0.863, 0.877, 0.814, 0.926, 0.767, 
> 0.746,
>   0.700, 0.768, 0.807, 0.753, 0.809, 0.788, 0.750, 0.815, 0.757, 
> 0.737,
>   

[R] Function argument and scope

2016-11-13 Thread Bernardo Doré
Hello list,

my first post but I've been using this list as a help source for a while.
Couldn't live without it.

I am writing a function that takes a dataframe as an argument and in the
end I intend to assign the result of some computation back to the
dataframe. This is what I have so far:

myFunction <- function(x){
  y <- x[1,1]
  z <- strsplit(as.character(y), split = " ")
  if(length(z[[1]] > 1)){
predictedWord <- z[[1]][length(z[[1]])]
z <- z[[1]][-c(length(z[[1]]))]
z <- paste(z, collapse = " ")
  }
  x[1,1] <- z
}

And lets say I create my dataframe like this:
test <- data.frame(var1=c("a","b","c"),var2=c("d","e","f"))

and then call
myFunction(test)

The problem is when I assign x[1,1] to y in the first operation inside the
function, x becomes a dataframe inside the function scope and loses the
reference to the dataframe "test" passed as argument. In the end when I
assign z to what should be row 1 and column 1 of the "test" dataframe, it
assigns to x inside the function scope and no modification is made on
"test".

I hope the problem statement is clear.

Thank you,

Bernardo Doré

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Question about expression parser for "return" statement

2016-11-13 Thread Jeff Newmiller
I find your response here inconsistent... either including `return` causes a 
"wasted" function call to occur (same result achieved slower) or the parser has 
an optimization in it to prevent the wasted function call (only behaviorally 
the same).

I carefully avoid using the return function in R. Both because using it before 
the end of a function usually makes the logic harder to follow and because I am 
under the impression that using it at the end of the function is a small but 
pointless waste of CPU cycles. That some people might be prone to writing a 
C-like use of "return;" which causes a function object to be returned only 
increases my aversion to using it. 
-- 
Sent from my phone. Please excuse my brevity.

On November 13, 2016 3:47:10 AM PST, Duncan Murdoch  
wrote:
>On 13/11/2016 12:50 AM, Dave DeBarr wrote:
>> I've noticed that if I don't include parentheses around the intended
>return
>> value for the "return" statement, R will assume the first
>parenthetical
>> expression is the intended return value ... even if that
>parenthetical
>> expression is only part of a larger expression.
>>
>> Is this intentional?
>
>Yes, return is just a function call that has side effects.  As far as 
>the parser is concerned,
>
>return ((1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance))
>
>is basically the same as
>
>f((1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance))
>
>Duncan Murdoch
>
>>
>> I'm guessing it is intentional; but since there is no warning about
>> ignoring the rest of the expression, it could lead to hard-to-find
>bugs.
>>
>> Thanks,
>> Dave
>>
>> Here's an example ...
>>
>> dnorm(2, 0, 1)
>> normalDensityFunction = function(x, Mean, Variance) {
>> # no parentheses surrounding the entire "return" value
>> return (1/sqrt(2*pi*Variance))*exp(-(1/2)*((x -
>Mean)^2)/Variance)
>> }
>> normalDensityFunction(2, 0, 1)# incorrect answer
>> normalDensityFunction = function(x, Mean, Variance) {
>> # parentheses surrounding the entire "return" value
>> return ((1/sqrt(2*pi*Variance))*exp(-(1/2)*((x -
>Mean)^2)/Variance))
>> }
>> normalDensityFunction(2, 0, 1)# correct answer
>>
>>  [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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 -- To UNSUBSCRIBE and more, see
>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 -- To UNSUBSCRIBE and more, see
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] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics

2016-11-13 Thread Michael Friendly

Salvatore,

I won't comment on whether to use log weight "to increase the 
correlation"  -- that depends on whether that makes sense, and whether 
the relationships with other variables is more nearly linear.


Try this with your pca of the correlation matrix:

biplot(pca_morpho)

You'll see that the  first component is defined largely by the
large correlations among length, interoc,and cwidth
while component2 is largely determined by weight.

You should probably do some reading on PCA or get some
statistical consulting at OSU to decide what to do with this.

 hope this helps

-Michael


On 11/13/16 12:46 AM, Sidoti, Salvatore A. wrote:

Let's say I perform 4 measurements on an animal: three are linear measurements 
in millimeters and the fourth is its weight in milligrams. So, we have a data 
set with mixed units.

Based on these four correlated measurements, I would like to obtain one "score" or value 
that describes an individual animal's size. I considered simply taking the geometric mean of these 
4 measurements, and that would give me a "score" - larger values would be for larger 
animals, etc.

However, this assumes that all 4 of these measurements contribute equally to an 
animal's size. Of course, more than likely this is not the case. I then 
performed a PCA to discover how much influence each variable had on the overall 
data set. I was hoping to use this analysis to refine my original approach.

I honestly do not know how to apply the information from the PCA to this 
particular problem...

I do know, however, that principle components 1 and 2 capture enough of the 
variation to reduce the number of dimensions down to 2 (see analysis below with 
the original data set).

Note: animal weights were ln() transformed to increase correlation with the 3 
other variables.

df <- data.frame(
  weight = log(1000*c(0.0980, 0.0622, 0.0600, 0.1098, 0.0538, 0.0701, 0.1138, 
0.0540, 0.0629, 0.0930,
 0.0443, 0.1115, 0.1157, 0.0734, 0.0616, 0.0640, 0.0480, 0.1339, 
0.0547, 0.0844,
 0.0431, 0.0472, 0.0752, 0.0604, 0.0713, 0.0658, 0.0538, 0.0585, 
0.0645, 0.0529,
 0.0448, 0.0574, 0.0577, 0.0514, 0.0758, 0.0424, 0.0997, 0.0758, 
0.0649, 0.0465,
 0.0748, 0.0540, 0.0819, 0.0732, 0.0725, 0.0730, 0.0777, 0.0630, 
0.0466)),
  interoc = c(0.853, 0.865, 0.811, 0.840, 0.783, 0.868, 0.818, 0.847, 0.838, 
0.799,
  0.737, 0.788, 0.731, 0.777, 0.863, 0.877, 0.814, 0.926, 0.767, 
0.746,
  0.700, 0.768, 0.807, 0.753, 0.809, 0.788, 0.750, 0.815, 0.757, 
0.737,
  0.759, 0.863, 0.747, 0.838, 0.790, 0.676, 0.857, 0.728, 0.743, 
0.870,
  0.787, 0.773, 0.829, 0.785, 0.746, 0.834, 0.829, 0.750, 0.842),
  cwidth = c(3.152, 3.046, 3.139, 3.181, 3.023, 3.452, 2.803, 3.050, 3.160, 
3.186,
 2.801, 2.862, 3.183, 2.770, 3.207, 3.188, 2.969, 3.033, 2.972, 
3.291,
 2.772, 2.875, 2.978, 3.094, 2.956, 2.966, 2.896, 3.149, 2.813, 
2.935,
 2.839, 3.152, 2.984, 3.037, 2.888, 2.723, 3.342, 2.562, 2.827, 
2.909,
 3.093, 2.990, 3.097, 2.751, 2.877, 2.901, 2.895, 2.721, 2.942),
  clength = c(3.889, 3.733, 3.762, 4.059, 3.911, 3.822, 3.768, 3.814, 3.721, 
3.794,
  3.483, 3.863, 3.856, 3.457, 3.996, 3.876, 3.642, 3.978, 3.534, 
3.967,
  3.429, 3.518, 3.766, 3.755, 3.706, 3.785, 3.607, 3.922, 3.453, 
3.589,
  3.508, 3.861, 3.706, 3.593, 3.570, 3.341, 3.916, 3.336, 3.504, 
3.688,
  3.735, 3.724, 3.860, 3.405, 3.493, 3.586, 3.545, 3.443, 3.640))

pca_morpho <- princomp(df, cor = TRUE)

summary(pca_morpho)

Importance of components:
Comp.1  Comp.2  Comp.3  
Comp.4
Standard deviation  1.6041070.8827323   0.7061206   
0.3860275
Proportion of Variance  0.6432900.1948041   0.1246516   
0.0372543
Cumulative Proportion   0.6432900.8380941   0.9627457   
1.000

Loadings:
Comp.1  Comp.2  Comp.3  Comp.4
weight  -0.371  0.907   -0.201
interoc -0.486  -0.227  -0.840
cwidth  -0.537  -0.349  0.466   -0.611
clength -0.582  0.278   0.761

Comp.1  Comp.2  Comp.3  Comp.4
SS loadings 1.001.001.001.00
Proportion Var  0.250.250.250.25
Cumulative Var  0.250.500.751.00

Any guidance will be greatly appreciated!

Salvatore A. Sidoti
PhD Student
The Ohio State University
Behavioral Ecology



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics

2016-11-13 Thread Jim Lemon
Hi Salvatore,
Depending upon your concept of "size" the use of the weighted sum may
well suit your purpose. The first principal component, being three
lengths and a mass, is likely to be strongly related to any sensible
concept of "size". My comment was meant to ensure that the local
definition of "size" was what you wanted. Using scaled values is a
good idea as it provides an intuitive measure of comparison within the
population. Remember that if your animal is long and thin, you have
already reduced the importance of the former measurement by scaling.

Jim


On Mon, Nov 14, 2016 at 12:37 PM, Sidoti, Salvatore A.
 wrote:
> Hi Jim,
>
> Nice to see you again! First of all, apologies to all for bending the rules a 
> bit with respect to the mailing list. I know this is a list for R programming 
> specifically, and I have received some great advice in this regard in the 
> past. I just thought this was an interesting applied problem that would 
> generate some discussion about PCA in R.
>
> Yes, that is an excellent question! Indeed, why not just volume? Since this 
> is still a work in progress and we have not published as of yet, I would 
> rather not be more specific about the type of animal at this time ;>}. 
> Nonetheless, I can say that the animals I study change "size" depending on 
> their feeding and hydration state. The abdomen in particular undergoes 
> drastic size changes. That being said, there are key anatomical features that 
> remain fixed in the adult.
>
> Now, there *might* be a way to work volume into the PCA. Although volume is 
> not a reliable metric since the abdomen size is so changeable while the 
> animal is alive, but what about preserved specimens? I have many that have 
> been marinating in ethanol for months. Wouldn't the tissues have equilibrated 
> by now? Probably... I could measure volume by displacement or suspension, I 
> suppose.
>
> In the meantime, here's a few thoughts:
>
> 1)  Use the contribution % (known as C% hereafter) of each variable on 
> principle components 1 and 2.
>
> 2)  The total contribution of a variable that explains the variations 
> retained by PC1 an PC2 is calculated by:
>
> sum(C%1 * eigenvalue1, C%2 * eigenvalue2)
>
> 3) Scale() to mean-center the columns of the data set.
>
> 4) Use these total contributions as the weights of an arithmetic mean.
>
> For example, we have an animal with the following data (mean-centered):
> weight: 1.334
> interoc:-0.225
> clength:0.046
> cwidth: -0.847
>
> The contributions of these variables on PC1 and PC2 are (% changed to 
> proportions):
> weight: 0.556
> interoc:0.357
> clength:0.493
> cwidth: 0.291
>
> To calculate size:
> 1.334(0.556) - 0.225(0.357) + 0.046(0.493) - 0.847(0.291) = 0.43758
> Then divide by the sum of the weights:
> 0.43758 / 1.697 = 0.257855 = "animal size"
>
> This value can then be used to rank the animal according to its size for 
> further analysis...
>
> Does this sound like a reasonable application of my PCA data?
>
> Salvatore A. Sidoti
> PhD Student
> Behavioral Ecology
>
> -Original Message-
> From: Jim Lemon [mailto:drjimle...@gmail.com]
> Sent: Sunday, November 13, 2016 3:53 PM
> To: Sidoti, Salvatore A. ; r-help mailing list 
> 
> Subject: Re: [R] Principle Component Analysis: Ranking Animal Size Based On 
> Combined Metrics
>
> Hi Salvatore,
> If by "size" you mean volume, why not directly measure the volume of your 
> animals? They appear to be fairly small. Sometimes working out what the 
> critical value actually means can inform the way to measure it.
>
> Jim
>
>
> On Sun, Nov 13, 2016 at 4:46 PM, Sidoti, Salvatore A.
>  wrote:
>> Let's say I perform 4 measurements on an animal: three are linear 
>> measurements in millimeters and the fourth is its weight in milligrams. So, 
>> we have a data set with mixed units.
>>
>> Based on these four correlated measurements, I would like to obtain one 
>> "score" or value that describes an individual animal's size. I considered 
>> simply taking the geometric mean of these 4 measurements, and that would 
>> give me a "score" - larger values would be for larger animals, etc.
>>
>> However, this assumes that all 4 of these measurements contribute equally to 
>> an animal's size. Of course, more than likely this is not the case. I then 
>> performed a PCA to discover how much influence each variable had on the 
>> overall data set. I was hoping to use this analysis to refine my original 
>> approach.
>>
>> I honestly do not know how to apply the information from the PCA to this 
>> particular problem...
>>
>> I do know, however, that principle components 1 and 2 capture enough of the 
>> variation to reduce the number of dimensions down to 2 (see analysis below 
>> with the original data set).
>>
>> Note: animal weights were ln() transformed to increase correlation with 

Re: [R] Question about using ggplot

2016-11-13 Thread Dominik Schneider
past versions of ggplot2 used to accept family as an argument directly, but
the latest ggplot2 (perhaps starting with v2?) requires method.args=list().
So the online sources you found using family directly were for an older
version of ggplot.

On Sun, Nov 13, 2016 at 8:18 AM,  wrote:

> Hi. I’m a student from South Korea, and I’m studying R by myself.
> While I am studying, I have a trouble dealing with ggplot(especially,
> about parameter ‘family’)
> > b <- biopsy
> > b$classn[b$class == "benign"] <- 0
> > b$classn[b$class == "malignant"] <- 1
> > ggplot(b, aes(x = V1, y = classn)) + geom_point(position =
> position_jitter(width = 0.3, height = 0.06), alpha = 0.4, shape = 21, size
> = 1.5) + stat_smooth(method = "glm", family = “bimomial")) #first code
> Warning: Ignoring unknown parameters: family
>
> While studying, I am wondering why there is a warning message. And also,
> there comes a wrong logistic model(Above picture). But in fact, I expect
> the below picture from the above code.
>
>
> And the below code yields ‘the model’ that I expected(below picture)
> ggplot(b, aes(x = V1, y = classn)) + geom_point(position =
> position_jitter(width = 0.3, height = 0.06), alpha = 0.4, shape = 21, size
> = 1.5) + stat_smooth(method = "glm", method.args = list(family =
> "binomial"))
>
>
>
>
> What’s wrong with the first code? When I searched about that from online,
> other people don’t seem to have a problem using family parameters.
> (I currently updated ggplot2, MASS, and sjPlot (Also, double checked it)
> Plus, I used code w/ or w/o using “”)
>
>
> I hope getting a good response from you.
> Thanks for reading my mail, and if my message has a rude expression, I’m
> sorry for my bad english skills..:(
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] Question about using ggplot

2016-11-13 Thread Ben Tupper
Hi,

It's hard to know for sure, but perhaps the spelling of 'binomial' is not 
correct?

Ben

> On Nov 13, 2016, at 10:18 AM, overholi...@ajou.ac.kr wrote:
> 
> Hi. I’m a student from South Korea, and I’m studying R by myself.
> While I am studying, I have a trouble dealing with ggplot(especially, about 
> parameter ‘family’)
>> b <- biopsy
>> b$classn[b$class == "benign"] <- 0
>> b$classn[b$class == "malignant"] <- 1
>> ggplot(b, aes(x = V1, y = classn)) + geom_point(position = 
>> position_jitter(width = 0.3, height = 0.06), alpha = 0.4, shape = 21, size = 
>> 1.5) + stat_smooth(method = "glm", family = “bimomial")) #first code
> Warning: Ignoring unknown parameters: family
> 
> While studying, I am wondering why there is a warning message. And also, 
> there comes a wrong logistic model(Above picture). But in fact, I expect the 
> below picture from the above code.
> 
> 
> And the below code yields ‘the model’ that I expected(below picture)
> ggplot(b, aes(x = V1, y = classn)) + geom_point(position = 
> position_jitter(width = 0.3, height = 0.06), alpha = 0.4, shape = 21, size = 
> 1.5) + stat_smooth(method = "glm", method.args = list(family = "binomial"))
> 
> 
> 
> 
> What’s wrong with the first code? When I searched about that from online, 
> other people don’t seem to have a problem using family parameters.
> (I currently updated ggplot2, MASS, and sjPlot (Also, double checked it)
> Plus, I used code w/ or w/o using “”)
> 
> 
> I hope getting a good response from you.
> Thanks for reading my mail, and if my message has a rude expression, I’m 
> sorry for my bad english skills..:(
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Question about using ggplot

2016-11-13 Thread overholic10
Hi. I’m a student from South Korea, and I’m studying R by myself.
While I am studying, I have a trouble dealing with ggplot(especially, about 
parameter ‘family’)
> b <- biopsy
> b$classn[b$class == "benign"] <- 0
> b$classn[b$class == "malignant"] <- 1
> ggplot(b, aes(x = V1, y = classn)) + geom_point(position = 
> position_jitter(width = 0.3, height = 0.06), alpha = 0.4, shape = 21, size = 
> 1.5) + stat_smooth(method = "glm", family = “bimomial")) #first code
Warning: Ignoring unknown parameters: family

While studying, I am wondering why there is a warning message. And also, there 
comes a wrong logistic model(Above picture). But in fact, I expect the below 
picture from the above code.


And the below code yields ‘the model’ that I expected(below picture)
ggplot(b, aes(x = V1, y = classn)) + geom_point(position = 
position_jitter(width = 0.3, height = 0.06), alpha = 0.4, shape = 21, size = 
1.5) + stat_smooth(method = "glm", method.args = list(family = "binomial"))




What’s wrong with the first code? When I searched about that from online, other 
people don’t seem to have a problem using family parameters.
(I currently updated ggplot2, MASS, and sjPlot (Also, double checked it)
Plus, I used code w/ or w/o using “”)


I hope getting a good response from you.
Thanks for reading my mail, and if my message has a rude expression, I’m sorry 
for my bad english skills..:(

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 use the fontchooser tcl tk widget ?

2016-11-13 Thread Cleber N.Borges

hello all r users,
somebody has a example how to use fontchooser widget?
I haven't success in my try :-(
Thanks
Cleber


> library( tcltk ) # in R-devel,

> tclVersion()
[1] "8.6.4"

> tclvalue( tcl('tk::fontchooser', 'show', command='' )  )
Error in (function (name, pos = -1L, envir = as.environment(pos), 
all.names = FALSE,  :

  unused argument ("{DejaVu Sans Mono} 26 bold italic")
Error in (function (name, pos = -1L, envir = as.environment(pos), 
all.names = FALSE,  :

  unused argument ("{DejaVu Sans Mono} 26 bold italic")
[1] ""
>


---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics

2016-11-13 Thread Jim Lemon
Hi Salvatore,
If by "size" you mean volume, why not directly measure the volume of
your animals? They appear to be fairly small. Sometimes working out
what the critical value actually means can inform the way to measure
it.

Jim


On Sun, Nov 13, 2016 at 4:46 PM, Sidoti, Salvatore A.
 wrote:
> Let's say I perform 4 measurements on an animal: three are linear 
> measurements in millimeters and the fourth is its weight in milligrams. So, 
> we have a data set with mixed units.
>
> Based on these four correlated measurements, I would like to obtain one 
> "score" or value that describes an individual animal's size. I considered 
> simply taking the geometric mean of these 4 measurements, and that would give 
> me a "score" - larger values would be for larger animals, etc.
>
> However, this assumes that all 4 of these measurements contribute equally to 
> an animal's size. Of course, more than likely this is not the case. I then 
> performed a PCA to discover how much influence each variable had on the 
> overall data set. I was hoping to use this analysis to refine my original 
> approach.
>
> I honestly do not know how to apply the information from the PCA to this 
> particular problem...
>
> I do know, however, that principle components 1 and 2 capture enough of the 
> variation to reduce the number of dimensions down to 2 (see analysis below 
> with the original data set).
>
> Note: animal weights were ln() transformed to increase correlation with the 3 
> other variables.
>
> df <- data.frame(
>   weight = log(1000*c(0.0980, 0.0622, 0.0600, 0.1098, 0.0538, 0.0701, 0.1138, 
> 0.0540, 0.0629, 0.0930,
>  0.0443, 0.1115, 0.1157, 0.0734, 0.0616, 0.0640, 0.0480, 0.1339, 
> 0.0547, 0.0844,
>  0.0431, 0.0472, 0.0752, 0.0604, 0.0713, 0.0658, 0.0538, 0.0585, 
> 0.0645, 0.0529,
>  0.0448, 0.0574, 0.0577, 0.0514, 0.0758, 0.0424, 0.0997, 0.0758, 
> 0.0649, 0.0465,
>  0.0748, 0.0540, 0.0819, 0.0732, 0.0725, 0.0730, 0.0777, 0.0630, 
> 0.0466)),
>   interoc = c(0.853, 0.865, 0.811, 0.840, 0.783, 0.868, 0.818, 0.847, 0.838, 
> 0.799,
>   0.737, 0.788, 0.731, 0.777, 0.863, 0.877, 0.814, 0.926, 0.767, 
> 0.746,
>   0.700, 0.768, 0.807, 0.753, 0.809, 0.788, 0.750, 0.815, 0.757, 
> 0.737,
>   0.759, 0.863, 0.747, 0.838, 0.790, 0.676, 0.857, 0.728, 0.743, 
> 0.870,
>   0.787, 0.773, 0.829, 0.785, 0.746, 0.834, 0.829, 0.750, 0.842),
>   cwidth = c(3.152, 3.046, 3.139, 3.181, 3.023, 3.452, 2.803, 3.050, 3.160, 
> 3.186,
>  2.801, 2.862, 3.183, 2.770, 3.207, 3.188, 2.969, 3.033, 2.972, 
> 3.291,
>  2.772, 2.875, 2.978, 3.094, 2.956, 2.966, 2.896, 3.149, 2.813, 
> 2.935,
>  2.839, 3.152, 2.984, 3.037, 2.888, 2.723, 3.342, 2.562, 2.827, 
> 2.909,
>  3.093, 2.990, 3.097, 2.751, 2.877, 2.901, 2.895, 2.721, 2.942),
>   clength = c(3.889, 3.733, 3.762, 4.059, 3.911, 3.822, 3.768, 3.814, 3.721, 
> 3.794,
>   3.483, 3.863, 3.856, 3.457, 3.996, 3.876, 3.642, 3.978, 3.534, 
> 3.967,
>   3.429, 3.518, 3.766, 3.755, 3.706, 3.785, 3.607, 3.922, 3.453, 
> 3.589,
>   3.508, 3.861, 3.706, 3.593, 3.570, 3.341, 3.916, 3.336, 3.504, 
> 3.688,
>   3.735, 3.724, 3.860, 3.405, 3.493, 3.586, 3.545, 3.443, 3.640))
>
> pca_morpho <- princomp(df, cor = TRUE)
>
> summary(pca_morpho)
>
> Importance of components:
> Comp.1  Comp.2  
> Comp.3  Comp.4
> Standard deviation  1.6041070.8827323   0.7061206   
> 0.3860275
> Proportion of Variance  0.6432900.1948041   0.1246516   
> 0.0372543
> Cumulative Proportion   0.6432900.8380941   0.9627457   
> 1.000
>
> Loadings:
> Comp.1  Comp.2  Comp.3  Comp.4
> weight  -0.371  0.907   -0.201
> interoc -0.486  -0.227  -0.840
> cwidth  -0.537  -0.349  0.466   -0.611
> clength -0.582  0.278   0.761
>
> Comp.1  Comp.2  Comp.3  Comp.4
> SS loadings 1.001.001.001.00
> Proportion Var  0.250.250.250.25
> Cumulative Var  0.250.500.751.00
>
> Any guidance will be greatly appreciated!
>
> Salvatore A. Sidoti
> PhD Student
> The Ohio State University
> Behavioral Ecology
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see

Re: [R] [FORGED] How to remove box in Venn plots (Vennerable package, uses grid) - similar to bty="n" in standard plots

2016-11-13 Thread Paul Murrell

Hi

Can you supply some example code?

You might get some joy from grid.ls() to identify the box followed by 
grid.remove() to get rid of it;  some example code would allow me to 
provide more detailed advice.


Paul

On 12/11/16 05:12, DE LAS HERAS Jose wrote:

I'm using the package Vennerable to make Venn diagrams, but it always
makes a box around the diagram.

Using standard R plots I could eliminate that by indicating


bty="n"


but it seems Vennerable uses the Grid package to generate its plots
and I'm not really familiar enough with Grid. I was looking at the
documentation but I can't seem to find a way to achieve that. I'd
even be happy drawing a white rectangle with wide lines to overplot
the box, but there must be a way to not draw the box in the first
place.


Anybody knows how?


Jose

--

Dr. Jose I. de las Heras The Wellcome Trust Centre for Cell Biology
Swann Building Max Born Crescent University of Edinburgh Edinburgh
EH9 3BF UK

Phone: +44 (0)131 6507090

Fax:  +44 (0)131 6507360



The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.



__ R-help@r-project.org
mailing list -- To UNSUBSCRIBE and more, see
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.



--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Question about expression parser for "return" statement

2016-11-13 Thread Duncan Murdoch

On 13/11/2016 7:58 AM, Duncan Murdoch wrote:

On 13/11/2016 6:47 AM, Duncan Murdoch wrote:

On 13/11/2016 12:50 AM, Dave DeBarr wrote:

I've noticed that if I don't include parentheses around the intended return
value for the "return" statement, R will assume the first parenthetical
expression is the intended return value ... even if that parenthetical
expression is only part of a larger expression.

Is this intentional?


Yes, return is just a function call that has side effects.  As far as
the parser is concerned,

return ((1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance))

is basically the same as

f((1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance))


By the way, out of curiosity I took a look at the source of CRAN
packages to see if this actually occurs.  It turns out that "return" is
used as a variable name often enough to make automatic tests tricky, so
I don't know the answer to my question.  However, I did turn up a number
of cases where people have code like this:

 if (name == "") return;

(from the bio.infer package), which never calls return(), so doesn't
actually do what the author likely intended


I searched the R sources and the sources of CRAN packages, and found 
this is a reasonably common problem:  it's in 111 packages, including 
one in base R.  I'll be emailing the maintainers to let them know.


I'll see about putting a check for this into R CMD check.

Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics

2016-11-13 Thread Bert Gunter
While you may get a reply here, this list is about R programming, not
about statistics. So

1. Do your homework and read a tutorial on PCA on the web or
elsewhere. Isn't this what a PhD student is supposed to do?

2. Post on a statistics list like stats.stackexchange.com.

3. Consult your professor or other local statistical resource.

Cheers,
Bert
Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sat, Nov 12, 2016 at 9:46 PM, Sidoti, Salvatore A.
 wrote:
> Let's say I perform 4 measurements on an animal: three are linear 
> measurements in millimeters and the fourth is its weight in milligrams. So, 
> we have a data set with mixed units.
>
> Based on these four correlated measurements, I would like to obtain one 
> "score" or value that describes an individual animal's size. I considered 
> simply taking the geometric mean of these 4 measurements, and that would give 
> me a "score" - larger values would be for larger animals, etc.
>
> However, this assumes that all 4 of these measurements contribute equally to 
> an animal's size. Of course, more than likely this is not the case. I then 
> performed a PCA to discover how much influence each variable had on the 
> overall data set. I was hoping to use this analysis to refine my original 
> approach.
>
> I honestly do not know how to apply the information from the PCA to this 
> particular problem...
>
> I do know, however, that principle components 1 and 2 capture enough of the 
> variation to reduce the number of dimensions down to 2 (see analysis below 
> with the original data set).
>
> Note: animal weights were ln() transformed to increase correlation with the 3 
> other variables.
>
> df <- data.frame(
>   weight = log(1000*c(0.0980, 0.0622, 0.0600, 0.1098, 0.0538, 0.0701, 0.1138, 
> 0.0540, 0.0629, 0.0930,
>  0.0443, 0.1115, 0.1157, 0.0734, 0.0616, 0.0640, 0.0480, 0.1339, 
> 0.0547, 0.0844,
>  0.0431, 0.0472, 0.0752, 0.0604, 0.0713, 0.0658, 0.0538, 0.0585, 
> 0.0645, 0.0529,
>  0.0448, 0.0574, 0.0577, 0.0514, 0.0758, 0.0424, 0.0997, 0.0758, 
> 0.0649, 0.0465,
>  0.0748, 0.0540, 0.0819, 0.0732, 0.0725, 0.0730, 0.0777, 0.0630, 
> 0.0466)),
>   interoc = c(0.853, 0.865, 0.811, 0.840, 0.783, 0.868, 0.818, 0.847, 0.838, 
> 0.799,
>   0.737, 0.788, 0.731, 0.777, 0.863, 0.877, 0.814, 0.926, 0.767, 
> 0.746,
>   0.700, 0.768, 0.807, 0.753, 0.809, 0.788, 0.750, 0.815, 0.757, 
> 0.737,
>   0.759, 0.863, 0.747, 0.838, 0.790, 0.676, 0.857, 0.728, 0.743, 
> 0.870,
>   0.787, 0.773, 0.829, 0.785, 0.746, 0.834, 0.829, 0.750, 0.842),
>   cwidth = c(3.152, 3.046, 3.139, 3.181, 3.023, 3.452, 2.803, 3.050, 3.160, 
> 3.186,
>  2.801, 2.862, 3.183, 2.770, 3.207, 3.188, 2.969, 3.033, 2.972, 
> 3.291,
>  2.772, 2.875, 2.978, 3.094, 2.956, 2.966, 2.896, 3.149, 2.813, 
> 2.935,
>  2.839, 3.152, 2.984, 3.037, 2.888, 2.723, 3.342, 2.562, 2.827, 
> 2.909,
>  3.093, 2.990, 3.097, 2.751, 2.877, 2.901, 2.895, 2.721, 2.942),
>   clength = c(3.889, 3.733, 3.762, 4.059, 3.911, 3.822, 3.768, 3.814, 3.721, 
> 3.794,
>   3.483, 3.863, 3.856, 3.457, 3.996, 3.876, 3.642, 3.978, 3.534, 
> 3.967,
>   3.429, 3.518, 3.766, 3.755, 3.706, 3.785, 3.607, 3.922, 3.453, 
> 3.589,
>   3.508, 3.861, 3.706, 3.593, 3.570, 3.341, 3.916, 3.336, 3.504, 
> 3.688,
>   3.735, 3.724, 3.860, 3.405, 3.493, 3.586, 3.545, 3.443, 3.640))
>
> pca_morpho <- princomp(df, cor = TRUE)
>
> summary(pca_morpho)
>
> Importance of components:
> Comp.1  Comp.2  
> Comp.3  Comp.4
> Standard deviation  1.6041070.8827323   0.7061206   
> 0.3860275
> Proportion of Variance  0.6432900.1948041   0.1246516   
> 0.0372543
> Cumulative Proportion   0.6432900.8380941   0.9627457   
> 1.000
>
> Loadings:
> Comp.1  Comp.2  Comp.3  Comp.4
> weight  -0.371  0.907   -0.201
> interoc -0.486  -0.227  -0.840
> cwidth  -0.537  -0.349  0.466   -0.611
> clength -0.582  0.278   0.761
>
> Comp.1  Comp.2  Comp.3  Comp.4
> SS loadings 1.001.001.001.00
> Proportion Var  0.250.250.250.25
> Cumulative Var  0.250.500.751.00
>
> Any guidance will be greatly appreciated!
>
> Salvatore A. Sidoti
> PhD Student
> The Ohio State University
> Behavioral Ecology
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 

Re: [R] Is this foreach behaviour correct?

2016-11-13 Thread Henrik Bengtsson
On Nov 13, 2016 13:54, "Henrik Bengtsson" 
wrote:
>
> It looks like a bug.  I don't think c.Date() is every called, because:
>
> > trace(c.Date, tracer = quote(message("c.Date() called")))
> Tracing function "c.Date" in package "base"
> [1] "c.Date"
>
> Tracing works:
>
> > c(as.Date(1L), as.Date(10001L))
> Tracing c.Date(as.Date(1L), as.Date(10001L)) on entry
> c.Date() called
> [1] "1997-05-19" "1997-05-20"
>
> but c.Date() is not called here:
>
> > x <- foreach(i=1:10100, .combine = function(...) c(...)) %do% {
as.Date(i) }
> > str(x)
>  num [1:101] 1 10001 10002 10003 10004 ...

Cut'n'paste error above. It is

x <- foreach(i=1:10100, .combine = "c") %do% { as.Date(i) }

that doesn't call c.Date(). Same if you try with .combine = c.

>
>
> The following hack works:
>
> > library("foreach")
> > library("zoo")
> > x <- foreach(i=1:10100, .combine = function(...) c(...)) %do% {
as.Date(i) }
> > str(x)
>  Date[1:101], format: "1997-05-19" "1997-05-20" "1997-05-21" "1997-05-22"
...
>
> Alternatively, one can use append() which works like c() if no other
> arguments are specified:
>
> > x <- foreach(i=1:10100, .combine = append) %do% { as.Date(i) }
> > str(x)
>  Date[1:101], format: "1997-05-19" "1997-05-20" "1997-05-21" "1997-05-22"
...
>
> It looks like foreach is treating the .combine = c case specially and
> someone fail to properly dispatch c() on the object (or something).
>
> /Henrik
>
>
> On Sun, Nov 13, 2016 at 7:14 AM, James Hirschorn
>  wrote:
> > I'm still not clear about whether this is a bug in foreach. Should
c.Date be invoked by foreach with .combine='c'?
> >
> > On 11/06/2016 07:02 PM, William Dunlap wrote:
> > Note that in the OP's example c.Date is never invoked.  c.Date is
called if .combine
> > calls c rather than if .combine is c:
> >
> >> library(zoo)
> >> trace(c.Date, quote(print(sys.call(
> > Tracing function "c.Date" in package "base"
> > [1] "c.Date"
> >> foreach(i=1:10003, .combine=c) %do% { as.Date(i) }
> > [1] 1 10001 10002 10003
> >> foreach(i=1:10003, .combine=function(...)c(...)) %do% { as.Date(i)
}
> > Tracing c.Date(...) on entry
> > eval(expr, envir, enclos)
> > Tracing c.Date(...) on entry
> > eval(expr, envir, enclos)
> > Tracing c.Date(...) on entry
> > eval(expr, envir, enclos)
> > [1] "1997-05-19" "1997-05-20" "1997-05-21" "1997-05-22"
> >
> >
> > Bill Dunlap
> > TIBCO Software
> > wdunlap tibco.com
> >
> > On Sun, Nov 6, 2016 at 2:20 PM, Duncan Murdoch > wrote:
> > On 06/11/2016 5:02 PM, Jim Lemon wrote:
> > hi James,
> > I think you have to have a starting date ("origin") for as.Date to
> > convert numbers to dates.
> >
> > That's true with the function in the base package, but the zoo package
also has an as.Date() function, which defaults the origin to "1970-01-01".
If James is using zoo his code would be okay.  If he's not, he would have
got an error, so I think he must have been.
> >
> > Duncan Murdoch
> >
> >
> >
> > Jim
> >
> > On Sun, Nov 6, 2016 at 12:10 PM, James Hirschorn
> > > wrote:
> > This seemed odd so I wanted to check:
> >
> >  > x <- foreach(i=1:10100, .combine='c') %do% { as.Date(i) }
> >
> > yields a numeric vector for x:
> >
> >  > class(x)
> > [1] "numeric"
> >
> > Should it not be a vector of Date?
> >
> > __
> > R-help@r-project.org mailing list -- To
UNSUBSCRIBE and more, see
> > 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 -- To
UNSUBSCRIBE and more, see
> > 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 -- To
UNSUBSCRIBE and more, see
> > 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 -- To UNSUBSCRIBE and more, see
> > 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.


Henrik

[[alternative HTML version deleted]]


Re: [R] Question about expression parser for "return" statement

2016-11-13 Thread Duncan Murdoch

On 13/11/2016 6:47 AM, Duncan Murdoch wrote:

On 13/11/2016 12:50 AM, Dave DeBarr wrote:

I've noticed that if I don't include parentheses around the intended return
value for the "return" statement, R will assume the first parenthetical
expression is the intended return value ... even if that parenthetical
expression is only part of a larger expression.

Is this intentional?


Yes, return is just a function call that has side effects.  As far as
the parser is concerned,

return ((1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance))

is basically the same as

f((1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance))


By the way, out of curiosity I took a look at the source of CRAN 
packages to see if this actually occurs.  It turns out that "return" is 
used as a variable name often enough to make automatic tests tricky, so 
I don't know the answer to my question.  However, I did turn up a number 
of cases where people have code like this:


if (name == "") return;

(from the bio.infer package), which never calls return(), so doesn't 
actually do what the author likely intended.


Duncan Murdoch



Duncan Murdoch



I'm guessing it is intentional; but since there is no warning about
ignoring the rest of the expression, it could lead to hard-to-find bugs.

Thanks,
Dave

Here's an example ...

dnorm(2, 0, 1)
normalDensityFunction = function(x, Mean, Variance) {
# no parentheses surrounding the entire "return" value
return (1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance)
}
normalDensityFunction(2, 0, 1)# incorrect answer
normalDensityFunction = function(x, Mean, Variance) {
# parentheses surrounding the entire "return" value
return ((1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance))
}
normalDensityFunction(2, 0, 1)# correct answer

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] Is this foreach behaviour correct?

2016-11-13 Thread Henrik Bengtsson
It looks like a bug.  I don't think c.Date() is every called, because:

> trace(c.Date, tracer = quote(message("c.Date() called")))
Tracing function "c.Date" in package "base"
[1] "c.Date"

Tracing works:

> c(as.Date(1L), as.Date(10001L))
Tracing c.Date(as.Date(1L), as.Date(10001L)) on entry
c.Date() called
[1] "1997-05-19" "1997-05-20"

but c.Date() is not called here:

> x <- foreach(i=1:10100, .combine = function(...) c(...)) %do% { 
> as.Date(i) }
> str(x)
 num [1:101] 1 10001 10002 10003 10004 ...


The following hack works:

> library("foreach")
> library("zoo")
> x <- foreach(i=1:10100, .combine = function(...) c(...)) %do% { 
> as.Date(i) }
> str(x)
 Date[1:101], format: "1997-05-19" "1997-05-20" "1997-05-21" "1997-05-22" ...

Alternatively, one can use append() which works like c() if no other
arguments are specified:

> x <- foreach(i=1:10100, .combine = append) %do% { as.Date(i) }
> str(x)
 Date[1:101], format: "1997-05-19" "1997-05-20" "1997-05-21" "1997-05-22" ...

It looks like foreach is treating the .combine = c case specially and
someone fail to properly dispatch c() on the object (or something).

/Henrik


On Sun, Nov 13, 2016 at 7:14 AM, James Hirschorn
 wrote:
> I'm still not clear about whether this is a bug in foreach. Should c.Date be 
> invoked by foreach with .combine='c'?
>
> On 11/06/2016 07:02 PM, William Dunlap wrote:
> Note that in the OP's example c.Date is never invoked.  c.Date is called if 
> .combine
> calls c rather than if .combine is c:
>
>> library(zoo)
>> trace(c.Date, quote(print(sys.call(
> Tracing function "c.Date" in package "base"
> [1] "c.Date"
>> foreach(i=1:10003, .combine=c) %do% { as.Date(i) }
> [1] 1 10001 10002 10003
>> foreach(i=1:10003, .combine=function(...)c(...)) %do% { as.Date(i) }
> Tracing c.Date(...) on entry
> eval(expr, envir, enclos)
> Tracing c.Date(...) on entry
> eval(expr, envir, enclos)
> Tracing c.Date(...) on entry
> eval(expr, envir, enclos)
> [1] "1997-05-19" "1997-05-20" "1997-05-21" "1997-05-22"
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Sun, Nov 6, 2016 at 2:20 PM, Duncan Murdoch 
> > wrote:
> On 06/11/2016 5:02 PM, Jim Lemon wrote:
> hi James,
> I think you have to have a starting date ("origin") for as.Date to
> convert numbers to dates.
>
> That's true with the function in the base package, but the zoo package also 
> has an as.Date() function, which defaults the origin to "1970-01-01".  If 
> James is using zoo his code would be okay.  If he's not, he would have got an 
> error, so I think he must have been.
>
> Duncan Murdoch
>
>
>
> Jim
>
> On Sun, Nov 6, 2016 at 12:10 PM, James Hirschorn
> > wrote:
> This seemed odd so I wanted to check:
>
>  > x <- foreach(i=1:10100, .combine='c') %do% { as.Date(i) }
>
> yields a numeric vector for x:
>
>  > class(x)
> [1] "numeric"
>
> Should it not be a vector of Date?
>
> __
> R-help@r-project.org mailing list -- To 
> UNSUBSCRIBE and more, see
> 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 -- To 
> UNSUBSCRIBE and more, see
> 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 -- To 
> UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] Question about expression parser for "return" statement

2016-11-13 Thread Duncan Murdoch

On 13/11/2016 12:50 AM, Dave DeBarr wrote:

I've noticed that if I don't include parentheses around the intended return
value for the "return" statement, R will assume the first parenthetical
expression is the intended return value ... even if that parenthetical
expression is only part of a larger expression.

Is this intentional?


Yes, return is just a function call that has side effects.  As far as 
the parser is concerned,


return ((1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance))

is basically the same as

f((1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance))

Duncan Murdoch



I'm guessing it is intentional; but since there is no warning about
ignoring the rest of the expression, it could lead to hard-to-find bugs.

Thanks,
Dave

Here's an example ...

dnorm(2, 0, 1)
normalDensityFunction = function(x, Mean, Variance) {
# no parentheses surrounding the entire "return" value
return (1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance)
}
normalDensityFunction(2, 0, 1)# incorrect answer
normalDensityFunction = function(x, Mean, Variance) {
# parentheses surrounding the entire "return" value
return ((1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance))
}
normalDensityFunction(2, 0, 1)# correct answer

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] Principle Component Analysis: Ranking Animal Size Based On Combined Metrics

2016-11-13 Thread Sidoti, Salvatore A.
Let's say I perform 4 measurements on an animal: three are linear measurements 
in millimeters and the fourth is its weight in milligrams. So, we have a data 
set with mixed units.

Based on these four correlated measurements, I would like to obtain one "score" 
or value that describes an individual animal's size. I considered simply taking 
the geometric mean of these 4 measurements, and that would give me a "score" - 
larger values would be for larger animals, etc.

However, this assumes that all 4 of these measurements contribute equally to an 
animal's size. Of course, more than likely this is not the case. I then 
performed a PCA to discover how much influence each variable had on the overall 
data set. I was hoping to use this analysis to refine my original approach.

I honestly do not know how to apply the information from the PCA to this 
particular problem...

I do know, however, that principle components 1 and 2 capture enough of the 
variation to reduce the number of dimensions down to 2 (see analysis below with 
the original data set).

Note: animal weights were ln() transformed to increase correlation with the 3 
other variables.

df <- data.frame(
  weight = log(1000*c(0.0980, 0.0622, 0.0600, 0.1098, 0.0538, 0.0701, 0.1138, 
0.0540, 0.0629, 0.0930,
 0.0443, 0.1115, 0.1157, 0.0734, 0.0616, 0.0640, 0.0480, 0.1339, 
0.0547, 0.0844,
 0.0431, 0.0472, 0.0752, 0.0604, 0.0713, 0.0658, 0.0538, 0.0585, 
0.0645, 0.0529,
 0.0448, 0.0574, 0.0577, 0.0514, 0.0758, 0.0424, 0.0997, 0.0758, 
0.0649, 0.0465,
 0.0748, 0.0540, 0.0819, 0.0732, 0.0725, 0.0730, 0.0777, 0.0630, 
0.0466)),
  interoc = c(0.853, 0.865, 0.811, 0.840, 0.783, 0.868, 0.818, 0.847, 0.838, 
0.799,
  0.737, 0.788, 0.731, 0.777, 0.863, 0.877, 0.814, 0.926, 0.767, 
0.746,
  0.700, 0.768, 0.807, 0.753, 0.809, 0.788, 0.750, 0.815, 0.757, 
0.737,
  0.759, 0.863, 0.747, 0.838, 0.790, 0.676, 0.857, 0.728, 0.743, 
0.870,
  0.787, 0.773, 0.829, 0.785, 0.746, 0.834, 0.829, 0.750, 0.842),
  cwidth = c(3.152, 3.046, 3.139, 3.181, 3.023, 3.452, 2.803, 3.050, 3.160, 
3.186,
 2.801, 2.862, 3.183, 2.770, 3.207, 3.188, 2.969, 3.033, 2.972, 
3.291,
 2.772, 2.875, 2.978, 3.094, 2.956, 2.966, 2.896, 3.149, 2.813, 
2.935,
 2.839, 3.152, 2.984, 3.037, 2.888, 2.723, 3.342, 2.562, 2.827, 
2.909,
 3.093, 2.990, 3.097, 2.751, 2.877, 2.901, 2.895, 2.721, 2.942),
  clength = c(3.889, 3.733, 3.762, 4.059, 3.911, 3.822, 3.768, 3.814, 3.721, 
3.794,
  3.483, 3.863, 3.856, 3.457, 3.996, 3.876, 3.642, 3.978, 3.534, 
3.967,
  3.429, 3.518, 3.766, 3.755, 3.706, 3.785, 3.607, 3.922, 3.453, 
3.589,
  3.508, 3.861, 3.706, 3.593, 3.570, 3.341, 3.916, 3.336, 3.504, 
3.688,
  3.735, 3.724, 3.860, 3.405, 3.493, 3.586, 3.545, 3.443, 3.640))

pca_morpho <- princomp(df, cor = TRUE)

summary(pca_morpho)

Importance of components:
Comp.1  Comp.2  Comp.3  
Comp.4
Standard deviation  1.6041070.8827323   0.7061206   
0.3860275
Proportion of Variance  0.6432900.1948041   0.1246516   
0.0372543
Cumulative Proportion   0.6432900.8380941   0.9627457   
1.000

Loadings:
Comp.1  Comp.2  Comp.3  Comp.4
weight  -0.371  0.907   -0.201
interoc -0.486  -0.227  -0.840   
cwidth  -0.537  -0.349  0.466   -0.611
clength -0.582  0.278   0.761

Comp.1  Comp.2  Comp.3  Comp.4
SS loadings 1.001.001.001.00
Proportion Var  0.250.250.250.25
Cumulative Var  0.250.500.751.00

Any guidance will be greatly appreciated!

Salvatore A. Sidoti
PhD Student
The Ohio State University
Behavioral Ecology

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] tcl('tk::fontchooser', 'show') : How to use? R-devel Tcl 8.6

2016-11-13 Thread Cleber N.Borges
Hello,
Somebody would indicate the correct way to use the option the
fontchooser widget into tcltk package (in R-devel, Tcl 8.6) ?
I tried to use as other traditional widgets but no success. (code below)
Thanks
Cleber

 > tt <- tktoplevel(); but <- ttkbutton( tt, text='Test'); tcl('pack', but )

 > tcl( but, 'configure', '-text' )
 -text text Text {} Test
 > tcl( but, 'configure', text=NULL )
 -text text Text {} Test
 > tcl( but, 'cget', '-text')
 Test
 >
 >
 > tcl('tk::fontchooser', 'show')

 > tcl( 'tk::fontchooser', 'configure', '-font')

 >
 >
 > sessionInfo()
R Under development (unstable) (2016-11-01 r71616)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7600)

locale:
[1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252
LC_MONETARY=Portuguese_Brazil.1252
[4] LC_NUMERIC=C LC_TIME=Portuguese_Brazil.1252

attached base packages:
[1] tcltk stats graphics  grDevices utils datasets methods
base

loaded via a namespace (and not attached):
[1] tools_3.4.0
 >




---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Question about expression parser for "return" statement

2016-11-13 Thread Dave DeBarr
I've noticed that if I don't include parentheses around the intended return
value for the "return" statement, R will assume the first parenthetical
expression is the intended return value ... even if that parenthetical
expression is only part of a larger expression.

Is this intentional?

I'm guessing it is intentional; but since there is no warning about
ignoring the rest of the expression, it could lead to hard-to-find bugs.

Thanks,
Dave

Here's an example ...

dnorm(2, 0, 1)
normalDensityFunction = function(x, Mean, Variance) {
# no parentheses surrounding the entire "return" value
return (1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance)
}
normalDensityFunction(2, 0, 1)# incorrect answer
normalDensityFunction = function(x, Mean, Variance) {
# parentheses surrounding the entire "return" value
return ((1/sqrt(2*pi*Variance))*exp(-(1/2)*((x - Mean)^2)/Variance))
}
normalDensityFunction(2, 0, 1)# correct answer

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.