Re: [R] loop for comparing two or more groups using bootstrapping

2018-09-11 Thread Marna Wagley
Thank you Jim, it worked. I am very grateful for your help.
Thanks
KG

On Tue, Sep 11, 2018 at 3:51 PM Jim Lemon  wrote:

> Hi Kristi,
> My fault, I only worked out how to assign the values to the names and pick
> out the columns of daT for the calculations. I think this does what you
> want, but I can't guarantee the result.
>
> daT<-structure(list(year1=c(0.417,0.538,0.69,0.688,0.688,0.606,
> 0.667,0.7,0.545,0.462,0.711,0.642,0.744,0.604,0.612,
> 0.667,0.533,0.556,0.444,0.526,0.323,0.308,0.195,0.333,
> 0.323,0.256,0.345,0.205,0.286,0.706,0.7,0.6,0.571,0.364,
> 0.429,0.326,0.571,0.424,0.341,0.387,0.341,0.324,0.696,
> 0.696,0.583,0.556,0.645,0.435,0.471,0.556),year2=c(0.385,
> 0.552,0.645,0.516,0.629,0.595,0.72,0.638,0.557,0.588,
> 0.63,0.744,0.773,0.571,0.723,0.769,0.667,0.667,0.526,
> 0.476,0.294,0.323,0.222,0.556,0.263,0.37,0.357,0.25,
> 0.323,0.778,0.667,0.636,0.583,0.432,0.412,0.333,0.571,
> 0.39,0.4,0.452,0.326,0.471,0.7,0.75,0.615,0.462,0.556,
> 0.4,0.696,0.465),year3=c(0.435,0.759,0.759,0.759,0.714,
> 0.593,0.651,0.683,0.513,0.643,0.652,0.757,0.791,0.649,
> 0.78,0.5,0.5,0.5,0.533,0.429,0.333,0.286,0.231,0.533,
> 0.303,0.417,0.333,0.333,0.357,0.909,1,0.952,0.8,0.556,
> 0.529,0.562,0.762,0.513,0.733,0.611,0.733,0.647,0.909,
> 0.857,0.8,0.556,0.588,0.562,0.857,0.513),year4=c(0.333,
> 0.533,0.6,0.483,0.743,0.5,0.691,0.619,0.583,0.385,0.653,
> 0.762,0.844,0.64,0.667,0.571,0.571,0.615,0.421,0.5,0.205,
> 0.308,0.25,0.6,0.242,0.308,0.276,0.235,0.211,0.9,0.632,
> 0.72,0.727,0.356,0.5,0.368,0.5,0.41,0.562,0.514,0.4,
> 0.409,0.632,0.72,0.727,0.4,0.5,0.421,0.5,0.462)),.Names=c("year1",
> "year2","year3","year4"),row.names=c(NA,-50L),class="data.frame")
> colname.mat<-combn(paste0("year",1:4),2)
> samplenames<-apply(colname.mat,2,paste,collapse="")
> k<-1
> meandiff<-function(x) return(mean(x[[1]])-mean(x[[2]]))
> for(column in 1:ncol(colname.mat)) {
>  assign(samplenames[column],
>   replicate(k,data.frame(sample(daT[,colname.mat[1,column]],3,TRUE),
>sample(daT[,colname.mat[2,column]],3,TRUE
>  meandiffs<-unlist(apply(get(samplenames[column]),2,meandiff))
>  cat(samplenames[column],"\n")
>  cat("mean diff =",mean(meandiffs),"95% CI =",
>   quantile(meandiffs,c(0.025,0.975)),"\n")
>  png(paste0(samplenames[column],".png")
>  hist(meandiffs)
>  dev.off()
> }
>
> You should get a printout of the means and CIs and  bunch of PNG files with
> the histograms.
>
> Jim
>
>
> On Tue, Sep 11, 2018 at 11:55 PM Kristi Glover 
> wrote:
>
> > Dear Jim,
> >
> > Thank you very much for the code. I run it but it gave me row names
> > like "year224", "year142".
> >
> > are these the difference between columns? If we want to get bootstrapping
> > means of difference between years (year2-year1; year3-year1), its CI and
> > exact p value, how can we get it?
> >
> > thanks
> >
> > KG
> >
> > 
> >
> > head(daT)
> >
> > colname.mat<-combn(paste0("year",1:4),2)
> >
> > samplenames<-apply(colname.mat,2,paste,collapse="")
> >
> > k<-10
> >
> > for(column in 1:ncol(colname.mat)) {
> >
> >  assign(samplenames[column],replicate(k,sample(unlist(daT[,colname.mat[,
> > column]]),3,TRUE)))
> >
> > }
> >
> > > get(samplenames[1])
> >  [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9] [,10]
> > year224 0.556 0.667 0.571 0.526 0.629 0.696 0.323 0.526 0.256 0.667
> > year142 0.324 0.324 0.706 0.638 0.600 0.294 0.612 0.688 0.432 0.387
> > year237 0.571 0.696 0.629 0.471 0.462 0.471 0.452 0.595 0.333 0.435
> >
> >
> >
> >
> > --
> > *From:* Jim Lemon 
> > *Sent:* September 11, 2018 1:44 AM
> > *To:* Kristi Glover
> > *Cc:* r-help mailing list
> > *Subject:* Re: [R] loop for comparing two or more groups using
> > bootstrapping
> >
> > Hi Kristy,
> > Try this:
> >
> > colname.mat<-combn(paste0("year",1:4),2)
> > samplenames<-apply(colname.mat,2,paste,collapse="")
> > k<-1
> > for(column in 1:ncol(colname.mat)) {
> >
> >
> assign(samplenames[column],replicate(k,sample(unlist(daT[,colname.mat[,column]]),3,TRUE)))
> > }
> >
> > Then use get(samplenames[1]) and so on to access the values.
> >
> > Jim
> > On Tue, Sep 11, 2018 at 4:52 PM Kristi Glover  >
> > wrote:
> > >
> > > Hi R users,
> > >
> > > I was trying to test a null hypothesis of difference between two groups
> > was 0. I have many years data, such as year1, year2,, year3, year4 and I
> > was trying to compare between year1 and year2, year1 and year3, year2 and
> > year3 and so on and have used following code with an example data.
> > >
> > >
> > > I tried to make a loop but did not work to compare between many years,
> > and also want to obtain the exact p value. Would you mind to help me to
> > make a loop?
> > >
> > > Thanks for your help.
> > >
> > >
> > > KG
> > >
> > >
> > > daT<-structure(list(year1 = c(0.417, 0.538, 0.69, 0.688, 0.688, 0.606,
> > > 0.667, 0.7, 0.545, 0.462, 0.711, 0.642, 0.744, 0.604, 0.612,
> > > 0.667, 0.533, 0.556, 0.444, 0.526, 0.323, 0.308, 0.195, 0.333,
> > > 0.323, 0.256, 0.345, 0.205, 0.286, 0.706, 0.7, 

[R] Correcting dates in research / medical record using R

2018-09-11 Thread Nicola Cecchino
Hi,

I'm not that well versed with R - I'm trying to correct the dates of 
service in a de-identified research medical record of several subjects.  
The correct dates come from a csv file, in the VisitDate column,  that 
looks like this in Excel.  The empty cells have other data in them that 
I don't need and the  file name is DateR.csv:


Id1 Id2 




VisitDate
12345   12345   




4/3/2018


The research medical record is a text file and the "DATE OF SERVICE" in 
the top matter is in error in all of the subjects and needs to be 
replaced with the "VisitDate" in the csv file.  The file name for the 
medical records is test3.NEW.  Here is a screen grab of the top matter 
of the research medical record; below this data excerpt is other 
gathered data for that subject:




PATIENT NAME: CONFIDENTIAL,#12345
PATIENT ID #: 12345
DATE OF SERVICE: 04/10/2018
ACCESSION NUMBER: RR1234567

TEST PROCEDURE    HIGH/LOW  TEST RESULTS   UNITS NORMAL VALUES


As described above, I need to update the text file DATE OF SERVICE:  
date with the VisitDate in the csv file.

I made several attempts at this to failure and so now I turn to you.  
Here is the code that exhibits my attempts:


clinicVdate <- read.csv("DateR.csv")

rownames(clinicVdate) <- as.character(clinicVdate[,'Id2'])

Id2 <- NA

input_data <- readLines("D:/test/test3.NEW")
output_data <- c()

for(input_line in input_data){
   output_line = input_line
   if(length(grep('PATIENT ID #:', input_line))>0)  {
     Id2 = as.character(strsplit(input_line, ':')[[1]][2])
   }

   if (length(grep( 'DATE OF SERVICE: ', input_line))){

     output_line = paste('DATE OF SERVICE', clinicVdate[Id2, 
'VisitDate'], sep=':')

   }
   output_data = paste(output_data, output_line, sep='\n')
}

cat(output_data)


The results of the above remove the erroneous date and replace it with 
NA.  Here is an example of the results:




PATIENT NAME: CONFIDENTIAL,#12345
PATIENT ID #: 12345
DATE OF SERVICE: NA
ACCESSION NUMBER: RR1234567

TEST PROCEDURE    HIGH/LOW  TEST RESULTS   UNITS NORMAL VALUES


Where am I going wrong?  If I didn't pose my question appropriately, 
please let me know too!!  Any help with this would be greatly appreciated!!

Kind regards,

Nic Cecchino




[[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] Undesired tick marks on top, right axes [RESOLVED]

2018-09-11 Thread Rich Shepard

On Tue, 11 Sep 2018, Bert Gunter wrote:


You do that. Your error is obvious.


Bert,

  Yep. Forgot to remove the 'p' from the type attribute.

Mea culpa!

Rich

__
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] Undesired tick marks on top, right axes

2018-09-11 Thread Bert Gunter
You do that. Your error is obvious.
-- Bert


On Tue, Sep 11, 2018 at 5:39 PM Rich Shepard  wrote:
>
> On Tue, 11 Sep 2018, Bert Gunter wrote:
>
> > As I thought, you did not do what I told you to.
> > Look *carefully* at the two to see your error.
>
> Bert,
>
>You're correct, of course. After moving the tck parameter in front of the
> x list the right-side ticks are gone. Unfortunately, so are the data: the
> panel is empty.
>
>Corrected command:
>
> rain.all.sum <- xyplot(Sum ~ Month, data=agg.all, col = 'black', type = 'p, 
> h',
> main = 'Monthly Total Precipitation\n2005-2018',
> xlab = 'Year and Month', ylab = 'Precipitation (in)',
> scales = list(tck = c(1,0), x = list(at = 
> seq(1,162,by=6),
>cex = 0.7, rot = 90)))
>
>Tomorrow I'll work on why the panel display disappeared along with the
> right axes tick marks. Parentheses all match according to emacs.
>
> Thanks,
>
> Rich
>
> __
> 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] Undesired tick marks on top, right axes

2018-09-11 Thread Rich Shepard

On Tue, 11 Sep 2018, Bert Gunter wrote:


As I thought, you did not do what I told you to.
Look *carefully* at the two to see your error.


Bert,

  You're correct, of course. After moving the tck parameter in front of the
x list the right-side ticks are gone. Unfortunately, so are the data: the
panel is empty.

  Corrected command:

rain.all.sum <- xyplot(Sum ~ Month, data=agg.all, col = 'black', type = 'p, h',
   main = 'Monthly Total Precipitation\n2005-2018',
   xlab = 'Year and Month', ylab = 'Precipitation (in)',
   scales = list(tck = c(1,0), x = list(at = 
seq(1,162,by=6),
  cex = 0.7, rot = 90)))

  Tomorrow I'll work on why the panel display disappeared along with the
right axes tick marks. Parentheses all match according to emacs.

Thanks,

Rich

__
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] Undesired tick marks on top, right axes

2018-09-11 Thread Bert Gunter
As I thought, you did not do what I told you to.

Look *carefully* at the two to see your error.

-- Bert


On Tue, Sep 11, 2018 at 5:01 PM Rich Shepard  wrote:
>
> On Tue, 11 Sep 2018, Bert Gunter wrote:
>
> > Not when I run your code with the tck specification added. Show us
> > your xyplot invocation. It should be
> > scales = list(tck = c(1,0), x= etc.)
>
> Bert,
>
>Command:
>
> rain.all.sum <- xyplot(Sum ~ Month, data=agg.all, col = 'black', type = 'h',
> main = 'Monthly Total Precipitation\n2005-2018',
> xlab = 'Year and Month', ylab = 'Precipitation (in)',
> scales = list(x = list(tck = c(1, 0), at = 
> seq(1,162,by=6),
>cex = 0.7, rot = 90)))
>
> rain.all.sum.pdf attached.
>
> Regards,
>
> Rich
> __
> 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] Undesired tick marks on top, right axes

2018-09-11 Thread Rich Shepard

On Tue, 11 Sep 2018, Bert Gunter wrote:


Not when I run your code with the tck specification added. Show us
your xyplot invocation. It should be
scales = list(tck = c(1,0), x= etc.)


Bert,

  Command:

rain.all.sum <- xyplot(Sum ~ Month, data=agg.all, col = 'black', type = 'h',
   main = 'Monthly Total Precipitation\n2005-2018',
   xlab = 'Year and Month', ylab = 'Precipitation (in)',
   scales = list(x = list(tck = c(1, 0), at = 
seq(1,162,by=6),
  cex = 0.7, rot = 90)))

rain.all.sum.pdf attached.

Regards,

Rich


rain.all.sum.pdf
Description: Adobe PDF document
__
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] Hierarchical Cluster Analysis

2018-09-11 Thread Jim Lemon
agnes (cluster)

Jim
On Wed, Sep 12, 2018 at 8:10 AM Bryan Mac  wrote:
>
>
> Bryan Mac
> Data Scientist
> Research Analytics
> Ipsos Insight LLC
>
>
>
>
>
> [[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] Undesired tick marks on top, right axes

2018-09-11 Thread Bert Gunter
??

Not when I run your code with the tck specification added. Show us
your xyplot invocation. It should be
scales = list(tck = c(1,0), x= etc.)

Bert

On Tue, Sep 11, 2018 at 3:51 PM Rich Shepard  wrote:
>
> On Tue, 11 Sep 2018, Bert Gunter wrote:
>
> > Adding
> > tck = c(1, 0)
> > to the "scales ="  list will probably solve your problem.
>
> Bert,
>
>How interesting. This removed the tick marks on top but left them on the
> right axes. Will think more about this.
>
> Regards,
>
> Rich
>
> __
> 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] Remove plot axis values in dotplot graph

2018-09-11 Thread Jim Lemon
Hi Abou,
Surprisingly you can't omit the x axis in dotchart. This hack will work:

sink("dotchar_noax.R")
sink()

Edit the resulting file by joining the first two lines with the
assignment symbol (<-), delete the two lines at the bottom and comment
out the line "axis(1)".

source("dotchart.noax.R")
dotchart.noax(scores,cex=1.5, pch = 18, col=c(1:3), xaxt = "n", main="Dot Plot
 child’s cough data", xlab="cough Scores")
library(plotrix)
staxlab(1,0:16)

I used "staxlab" so that you could have all of the labels 0:16.

Jim


On Wed, Sep 12, 2018 at 5:57 AM AbouEl-Makarim Aboueissa
 wrote:
>
> Dear All:
>
> One more thing. I want to Remove the plot x-axis values in dotplot graph. I
> am trying to use xaxt = "n", but it seems NOT working. Also after removing
> the x-axis values, I want to use the command axis(1, at=0:16, cex.axis=1)
> to add x-axis values from 0 to 16, but it seems not working as expect.
>
>
>
> Honey.Dosage<-c(12,11,15,11,10,13,10,4,15,16,9,14,10,6,10,8,11,12,12,8,12,9,11,15,10,15,9,13,8,12,10,8,9,5,12)
>
> DM.Dosage<-c(4,6,9,4,7,7,7,9,12,10,11,6,3,4,9,12,7,6,8,12,12,4,12,13,7,10,13,9,4,4,10,15,9)
>
> No.Dosage<-c(5,8,6,1,0,8,12,8,7,7,1,6,7,7,12,7,9,7,9,5,11,9,5,6,8,8,6,7,10,9,4,8,7,3,1,4,3)
>
> scores<-c(Honey.Dosage,DM.Dosage,No.Dosage)
>
> min(scores)
> max(scores)
>
> dotchart(scores,cex=1.5, pch = 18, col=c(1:3), xaxt = "n", main="Dot Plot
> child’s cough data", xlab="cough Scores")
>
> axis(1, at=0:16, cex.axis=1.5)
>
>
>
>
> with many thanks
> abou
> __
>
>
> *AbouEl-Makarim Aboueissa, PhD*
>
> *Professor of Statistics*
> *Graduate Coordinator*
>
> *Department of Mathematics and Statistics*
> *University of Southern Maine*
>
> [[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] Increasing size of label in Taylor plot of Plotrix package

2018-09-11 Thread Jim Lemon
Hi Sonam,
You're right. Although the cex.axis argument is present, it doesn't
seem to be used. I will have to debug this, which may take a day or
two.

Jim

On Tue, Sep 11, 2018 at 6:37 PM Sonam Sandeep Dash
 wrote:
>
> Respected Sir,
> I have created a Taylor plot using the plotrix package. However, I am unable 
> to increase the size of labels of axis. I have tried so many ways but all are 
> in vein. There is no change to size of label of either axis. Kindly tell me 
> the procedure to do the same.
> Thank you,
>
> Regards:
> Sonam Sandeep Dash
> Research scholar
> School of Water Resources
> Indian Institute of Technology, Kharagpur
> West Bengal-721302

__
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] loop for comparing two or more groups using bootstrapping

2018-09-11 Thread Jim Lemon
Hi Kristi,
My fault, I only worked out how to assign the values to the names and pick
out the columns of daT for the calculations. I think this does what you
want, but I can't guarantee the result.

daT<-structure(list(year1=c(0.417,0.538,0.69,0.688,0.688,0.606,
0.667,0.7,0.545,0.462,0.711,0.642,0.744,0.604,0.612,
0.667,0.533,0.556,0.444,0.526,0.323,0.308,0.195,0.333,
0.323,0.256,0.345,0.205,0.286,0.706,0.7,0.6,0.571,0.364,
0.429,0.326,0.571,0.424,0.341,0.387,0.341,0.324,0.696,
0.696,0.583,0.556,0.645,0.435,0.471,0.556),year2=c(0.385,
0.552,0.645,0.516,0.629,0.595,0.72,0.638,0.557,0.588,
0.63,0.744,0.773,0.571,0.723,0.769,0.667,0.667,0.526,
0.476,0.294,0.323,0.222,0.556,0.263,0.37,0.357,0.25,
0.323,0.778,0.667,0.636,0.583,0.432,0.412,0.333,0.571,
0.39,0.4,0.452,0.326,0.471,0.7,0.75,0.615,0.462,0.556,
0.4,0.696,0.465),year3=c(0.435,0.759,0.759,0.759,0.714,
0.593,0.651,0.683,0.513,0.643,0.652,0.757,0.791,0.649,
0.78,0.5,0.5,0.5,0.533,0.429,0.333,0.286,0.231,0.533,
0.303,0.417,0.333,0.333,0.357,0.909,1,0.952,0.8,0.556,
0.529,0.562,0.762,0.513,0.733,0.611,0.733,0.647,0.909,
0.857,0.8,0.556,0.588,0.562,0.857,0.513),year4=c(0.333,
0.533,0.6,0.483,0.743,0.5,0.691,0.619,0.583,0.385,0.653,
0.762,0.844,0.64,0.667,0.571,0.571,0.615,0.421,0.5,0.205,
0.308,0.25,0.6,0.242,0.308,0.276,0.235,0.211,0.9,0.632,
0.72,0.727,0.356,0.5,0.368,0.5,0.41,0.562,0.514,0.4,
0.409,0.632,0.72,0.727,0.4,0.5,0.421,0.5,0.462)),.Names=c("year1",
"year2","year3","year4"),row.names=c(NA,-50L),class="data.frame")
colname.mat<-combn(paste0("year",1:4),2)
samplenames<-apply(colname.mat,2,paste,collapse="")
k<-1
meandiff<-function(x) return(mean(x[[1]])-mean(x[[2]]))
for(column in 1:ncol(colname.mat)) {
 assign(samplenames[column],
  replicate(k,data.frame(sample(daT[,colname.mat[1,column]],3,TRUE),
   sample(daT[,colname.mat[2,column]],3,TRUE
 meandiffs<-unlist(apply(get(samplenames[column]),2,meandiff))
 cat(samplenames[column],"\n")
 cat("mean diff =",mean(meandiffs),"95% CI =",
  quantile(meandiffs,c(0.025,0.975)),"\n")
 png(paste0(samplenames[column],".png")
 hist(meandiffs)
 dev.off()
}

You should get a printout of the means and CIs and  bunch of PNG files with
the histograms.

Jim


On Tue, Sep 11, 2018 at 11:55 PM Kristi Glover 
wrote:

> Dear Jim,
>
> Thank you very much for the code. I run it but it gave me row names
> like "year224", "year142".
>
> are these the difference between columns? If we want to get bootstrapping
> means of difference between years (year2-year1; year3-year1), its CI and
> exact p value, how can we get it?
>
> thanks
>
> KG
>
> 
>
> head(daT)
>
> colname.mat<-combn(paste0("year",1:4),2)
>
> samplenames<-apply(colname.mat,2,paste,collapse="")
>
> k<-10
>
> for(column in 1:ncol(colname.mat)) {
>
>  assign(samplenames[column],replicate(k,sample(unlist(daT[,colname.mat[,
> column]]),3,TRUE)))
>
> }
>
> > get(samplenames[1])
>  [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9] [,10]
> year224 0.556 0.667 0.571 0.526 0.629 0.696 0.323 0.526 0.256 0.667
> year142 0.324 0.324 0.706 0.638 0.600 0.294 0.612 0.688 0.432 0.387
> year237 0.571 0.696 0.629 0.471 0.462 0.471 0.452 0.595 0.333 0.435
>
>
>
>
> --
> *From:* Jim Lemon 
> *Sent:* September 11, 2018 1:44 AM
> *To:* Kristi Glover
> *Cc:* r-help mailing list
> *Subject:* Re: [R] loop for comparing two or more groups using
> bootstrapping
>
> Hi Kristy,
> Try this:
>
> colname.mat<-combn(paste0("year",1:4),2)
> samplenames<-apply(colname.mat,2,paste,collapse="")
> k<-1
> for(column in 1:ncol(colname.mat)) {
>
>  
> assign(samplenames[column],replicate(k,sample(unlist(daT[,colname.mat[,column]]),3,TRUE)))
> }
>
> Then use get(samplenames[1]) and so on to access the values.
>
> Jim
> On Tue, Sep 11, 2018 at 4:52 PM Kristi Glover 
> wrote:
> >
> > Hi R users,
> >
> > I was trying to test a null hypothesis of difference between two groups
> was 0. I have many years data, such as year1, year2,, year3, year4 and I
> was trying to compare between year1 and year2, year1 and year3, year2 and
> year3 and so on and have used following code with an example data.
> >
> >
> > I tried to make a loop but did not work to compare between many years,
> and also want to obtain the exact p value. Would you mind to help me to
> make a loop?
> >
> > Thanks for your help.
> >
> >
> > KG
> >
> >
> > daT<-structure(list(year1 = c(0.417, 0.538, 0.69, 0.688, 0.688, 0.606,
> > 0.667, 0.7, 0.545, 0.462, 0.711, 0.642, 0.744, 0.604, 0.612,
> > 0.667, 0.533, 0.556, 0.444, 0.526, 0.323, 0.308, 0.195, 0.333,
> > 0.323, 0.256, 0.345, 0.205, 0.286, 0.706, 0.7, 0.6, 0.571, 0.364,
> > 0.429, 0.326, 0.571, 0.424, 0.341, 0.387, 0.341, 0.324, 0.696,
> > 0.696, 0.583, 0.556, 0.645, 0.435, 0.471, 0.556), year2 = c(0.385,
> > 0.552, 0.645, 0.516, 0.629, 0.595, 0.72, 0.638, 0.557, 0.588,
> > 0.63, 0.744, 0.773, 0.571, 0.723, 0.769, 0.667, 0.667, 0.526,
> > 0.476, 0.294, 0.323, 0.222, 0.556, 0.263, 0.37, 0.357, 0.25,
> > 0.323, 0.778, 0.667, 0.636, 0.583, 

Re: [R] Undesired tick marks on top, right axes

2018-09-11 Thread Rich Shepard

On Tue, 11 Sep 2018, Bert Gunter wrote:


Adding
tck = c(1, 0)
to the "scales ="  list will probably solve your problem.


Bert,

  How interesting. This removed the tick marks on top but left them on the
right axes. Will think more about this.

Regards,

Rich

__
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] getting 21 very different colours

2018-09-11 Thread Achim Zeileis

Have a look at the Polychrome package by Kevin Coombes and Guy Brock:
https://CRAN.R-project.org/package=Polychrome

This employs the LUV space (with HCL = polar LUV) to get many distinct 
distinguishable colors. For a few first steps, see:

https://CRAN.R-project.org/web/packages/Polychrome/vignettes/polychrome.html

On Wed, 12 Sep 2018, Zach Simpson wrote:


Hi Federico

For a possible alternative, the scico package provides a nice
collection of color palettes that are designed to be both color-blind
friendly and differentiable:

https://www.data-imaginist.com/2018/scico-and-the-colour-conundrum/

You could generate a vector of 21 colors (spaced as far apart as
possible on the palette) to pass to your plot arguments with something
like:

library(scico)
scico(21, palette = 'oleron')

Not sure if this works for your case though. But maybe another feature
(shape?) could help differentiate the 21 points.

Hope this helps,
Zach Simpson


Message: 11
Date: Tue, 11 Sep 2018 07:34:51 +
From: Federico Calboli 
To: "r-help@r-project.org" 
Subject: [R] getting 21 very different colours
Message-ID: <08a6397b-4d67-4195-a53a-1fd394f72...@kuleuven.be>
Content-Type: text/plain; charset="utf-8"

Hi All,

I am plotting a scatterplot of 21 populations, and I am using 
rainbow(21)[pops.col] to generate 21 colours for the plot (which works).  Maybe 
it is because I can really process few colours at a time, but the differences 
between the colours are not as strong as I’d like.  I can specify start and end 
for rainbow(), but if anything that looks worse if I do not just stick to 0 and 
1.

Is there a way of getting a set of 21 colours that maximises the differences 
between them?

I could pick them by hand, but that is about 15 colours more than I know (I 
have a detailed colourchart, but the visual differences between ’skyblue’ and 
’slategrey’ elude me when plotted as dots on a plot).

Cheers

F
--
Federico Calboli
LBEG - Laboratory of Biodiversity and Evolutionary Genomics
Charles Deberiotstraat 32 box 2439
3000 Leuven
+32 16 32 87 67


__
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] Undesired tick marks on top, right axes

2018-09-11 Thread Rich Shepard

On Tue, 11 Sep 2018, Bert Gunter wrote:


Well, you might try ?xyplot -- in particular the "scales" list section
and in particular there the "tck" parameter. Adding
tck = c(1, 0)
to the "scales ="  list will probably solve your problem.


Bert,

  I missed the end of the tck description in the book (the same text as the
help file but with more information) where it mentions that tck can be a
vector of length 2 where the first element affects the left/bottom axes and
the second element affects the right/top axes. I also did not grok turning
the first element on and the second element off.

  Now I wonder why this wasn't an issue before now in the xyplots I created.

Thanks much,

Rich

__
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] getting 21 very different colours

2018-09-11 Thread Zach Simpson
Hi Federico

For a possible alternative, the scico package provides a nice
collection of color palettes that are designed to be both color-blind
friendly and differentiable:

https://www.data-imaginist.com/2018/scico-and-the-colour-conundrum/

You could generate a vector of 21 colors (spaced as far apart as
possible on the palette) to pass to your plot arguments with something
like:

library(scico)
scico(21, palette = 'oleron')

Not sure if this works for your case though. But maybe another feature
(shape?) could help differentiate the 21 points.

Hope this helps,
Zach Simpson

> Message: 11
> Date: Tue, 11 Sep 2018 07:34:51 +
> From: Federico Calboli 
> To: "r-help@r-project.org" 
> Subject: [R] getting 21 very different colours
> Message-ID: <08a6397b-4d67-4195-a53a-1fd394f72...@kuleuven.be>
> Content-Type: text/plain; charset="utf-8"
>
> Hi All,
>
> I am plotting a scatterplot of 21 populations, and I am using 
> rainbow(21)[pops.col] to generate 21 colours for the plot (which works).  
> Maybe it is because I can really process few colours at a time, but the 
> differences between the colours are not as strong as I’d like.  I can specify 
> start and end for rainbow(), but if anything that looks worse if I do not 
> just stick to 0 and 1.
>
> Is there a way of getting a set of 21 colours that maximises the differences 
> between them?
>
> I could pick them by hand, but that is about 15 colours more than I know (I 
> have a detailed colourchart, but the visual differences between ’skyblue’ and 
> ’slategrey’ elude me when plotted as dots on a plot).
>
> Cheers
>
> F
> --
> Federico Calboli
> LBEG - Laboratory of Biodiversity and Evolutionary Genomics
> Charles Deberiotstraat 32 box 2439
> 3000 Leuven
> +32 16 32 87 67

__
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] Undesired tick marks on top, right axes

2018-09-11 Thread Bert Gunter
Well, you might try ?xyplot -- in particular the "scales" list section
and in particular there the "tck" parameter. Adding
tck = c(1, 0)
to the "scales ="  list will probably solve your problem.

-- Bert


On Tue, Sep 11, 2018 at 2:46 PM Rich Shepard  wrote:
>
>Every lattice xyplot() I've created before this one has tick marks on only
> the left and bottom axes. The current plot has sprouted tick marks on the
> top and right side, too, and I want to remove them. I've not found an answer
> to this issue in Deepayan's book or on the web. I would appreciate also
> learning why the extra tick marks appeared. The dput() data are included.
>
>The plotting command;
>
> rain.all.sum <- xyplot(Sum ~ Month, data=agg.all, col = 'black', type = 'h',
> main = 'Monthly Total Precipitation\n2005-2018',
> xlab = 'Year and Month', ylab = 'Precipitation (in)',
> scales = list(x = list(at = seq(1,162,by=6), cex = 
> 0.7, rot = 90)))
>
> plot(rain.all.sum)
>
>The data:
>
> structure(list(Month = structure(1:162, .Label = c("2005-01",
> "2005-02", "2005-03", "2005-04", "2005-05", "2005-06", "2005-07",
> "2005-08", "2005-09", "2005-10", "2005-11", "2005-12", "2006-01",
> "2006-02", "2006-03", "2006-04", "2006-05", "2006-06", "2006-07",
> "2006-08", "2006-09", "2006-10", "2006-11", "2006-12", "2007-01",
> "2007-02", "2007-03", "2007-04", "2007-05", "2007-06", "2007-07",
> "2007-08", "2007-09", "2007-10", "2007-11", "2007-12", "2008-01",
> "2008-02", "2008-03", "2008-04", "2008-05", "2008-06", "2008-07",
> "2008-08", "2008-09", "2008-10", "2008-11", "2008-12", "2009-01",
> "2009-02", "2009-03", "2009-04", "2009-05", "2009-06", "2009-07",
> "2009-08", "2009-09", "2009-10", "2009-11", "2009-12", "2010-01",
> "2010-02", "2010-03", "2010-04", "2010-05", "2010-06", "2010-07",
> "2010-08", "2010-09", "2010-10", "2010-11", "2010-12", "2011-01",
> "2011-02", "2011-03", "2011-04", "2011-05", "2011-06", "2011-07",
> "2011-08", "2011-09", "2011-10", "2011-11", "2011-12", "2012-01",
> "2012-02", "2012-03", "2012-04", "2012-05", "2012-06", "2012-07",
> "2012-08", "2012-09", "2012-10", "2012-11", "2012-12", "2013-01",
> "2013-02", "2013-03", "2013-04", "2013-05", "2013-06", "2013-07",
> "2013-08", "2013-09", "2013-10", "2013-11", "2013-12", "2014-01",
> "2014-02", "2014-03", "2014-04", "2014-05", "2014-06", "2014-07",
> "2014-08", "2014-09", "2014-10", "2014-11", "2014-12", "2015-01",
> "2015-02", "2015-03", "2015-04", "2015-05", "2015-06", "2015-07",
> "2015-08", "2015-09", "2015-10", "2015-11", "2015-12", "2016-01",
> "2016-02", "2016-03", "2016-04", "2016-05", "2016-06", "2016-07",
> "2016-08", "2016-09", "2016-10", "2016-11", "2016-12", "2017-01",
> "2017-02", "2017-03", "2017-04", "2017-05", "2017-06", "2017-07",
> "2017-08", "2017-09", "2017-10", "2017-11", "2017-12", "2018-01",
> "2018-02", "2018-03", "2018-04", "2018-05", "2018-06"), class = "factor"),
>  Sum = c(53.51, 24.2, 88.54, 72.85, 77.3, 49.19, 8.77, 5.75,
>  27.83, 79.75, 123.89, 168.29, 229.69, 70.91, 74.15, 62.3,
>  43.56, 35.08, 3.6, 2.76, 26.83, 47.72, 293.23, 139.84, 103.48,
>  120.91, 85.96, 55.91, 26.56, 29.44, 9.9, 15.38, 33.47, 93.6,
>  105.61, 277.41, 279.38, 144.26, 220.88, 149.75, 82.28, 55.87,
>  5.29, 52.27, 21.1, 64.76, 182.31, 207.13, 196.29, 89.27,
>  187.72, 111.67, 111.72, 38.19, 6.07, 15.25, 52.46, 127.75,
>  208.43, 146.62, 169.34, 94.54, 154.21, 131.39, 151.27, 135.46,
>  9.98, 8.72, 86.67, 142.04, 225.61, 274.93, 196.68, 153.24,
>  263.54, 231.49, 122.23, 58.26, 34.65, 2.96, 28.21, 103.92,
>  217.52, 166.16, 305.27, 168.73, 333.28, 145.68, 101.2, 127.77,
>  15.41, 1.85, 3.49, 245.99, 272.35, 297.05, 177.17, 105.71,
>  118.44, 136.34, 161.01, 53.31, 1.15, 23.43, 200.97, 69.12,
>  158.51, 131.67, 156.95, 266.38, 291.7, 147.15, 101.49, 78.89,
>  26.99, 24.35, 35.76, 210.2, 225.55, 282.85, 153.91, 148.13,
>  187.03, 133.99, 62.28, 17.58, 13.41, 35.58, 47.04, 154.92,
>  317.77, 604.04, 288.91, 210.86, 266.04, 121.62, 78.17, 85.96,
>  29.84, 7.02, 72.13, 404.33, 247.71, 255.5, 138.22, 339.5,
>  368.99, 209.41, 110.08, 63.9, 0.62, 6.97, 133.75, 227.1,
>  312.99, 178.58, 255.8, 155.05, 135.27, 225.55, 15.23, 1.58
>  ), Median = c(0.01, 0, 0, 0.1, 0.1, 0, 0, 0, 0, 0.02, 0.1,
>  0.04, 0.5, 0, 0.1, 0.07, 0, 0, 0, 0, 0, 0, 0.57, 0.03, 0,
>  0.2, 0.055, 0, 0, 0, 0, 0, 0, 0, 0, 0.21, 0.21, 0.02, 0.2,
>  0.11, 0.02, 0, 0, 0, 0, 0, 0.1, 0.165, 0.01, 0.01, 0.15,
>  0.01, 0, 0, 0, 0, 0, 0.02, 0.125, 0, 0.1, 0.08, 0.055, 0.1,
>  0.13, 0.01, 0, 0, 0, 0, 0.2, 0.17, 0.02, 0.07, 0.23, 0.15,
>  0.06, 0, 0, 0, 0, 0.03, 0.1, 0, 0.1, 0.1, 0.2, 0.07, 0, 0.02,
>  0, 0, 0, 0.04, 0.115, 0.24, 0.02, 0.03, 0.01, 0.01, 0.02,
>  0, 0, 0, 0, 0, 0.02, 0, 0, 0.2, 0.18, 0.05, 0, 0, 0, 0, 0,
>  0.08, 0.07, 0.1, 0, 0.01, 0, 0.02, 0, 0, 0, 0, 0, 0, 0.09,
>  0.4, 0.18, 0.1, 0.2, 0, 0, 0, 0, 

[R] Hierarchical Cluster Analysis

2018-09-11 Thread Bryan Mac


Bryan Mac
Data Scientist
Research Analytics
Ipsos Insight LLC





[[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] Undesired tick marks on top, right axes

2018-09-11 Thread Rich Shepard

  Every lattice xyplot() I've created before this one has tick marks on only
the left and bottom axes. The current plot has sprouted tick marks on the
top and right side, too, and I want to remove them. I've not found an answer
to this issue in Deepayan's book or on the web. I would appreciate also
learning why the extra tick marks appeared. The dput() data are included.

  The plotting command;

rain.all.sum <- xyplot(Sum ~ Month, data=agg.all, col = 'black', type = 'h',
   main = 'Monthly Total Precipitation\n2005-2018',
   xlab = 'Year and Month', ylab = 'Precipitation (in)',
   scales = list(x = list(at = seq(1,162,by=6), cex = 0.7, 
rot = 90)))

plot(rain.all.sum)

  The data:

structure(list(Month = structure(1:162, .Label = c("2005-01", 
"2005-02", "2005-03", "2005-04", "2005-05", "2005-06", "2005-07", 
"2005-08", "2005-09", "2005-10", "2005-11", "2005-12", "2006-01", 
"2006-02", "2006-03", "2006-04", "2006-05", "2006-06", "2006-07", 
"2006-08", "2006-09", "2006-10", "2006-11", "2006-12", "2007-01", 
"2007-02", "2007-03", "2007-04", "2007-05", "2007-06", "2007-07", 
"2007-08", "2007-09", "2007-10", "2007-11", "2007-12", "2008-01", 
"2008-02", "2008-03", "2008-04", "2008-05", "2008-06", "2008-07", 
"2008-08", "2008-09", "2008-10", "2008-11", "2008-12", "2009-01", 
"2009-02", "2009-03", "2009-04", "2009-05", "2009-06", "2009-07", 
"2009-08", "2009-09", "2009-10", "2009-11", "2009-12", "2010-01", 
"2010-02", "2010-03", "2010-04", "2010-05", "2010-06", "2010-07", 
"2010-08", "2010-09", "2010-10", "2010-11", "2010-12", "2011-01", 
"2011-02", "2011-03", "2011-04", "2011-05", "2011-06", "2011-07", 
"2011-08", "2011-09", "2011-10", "2011-11", "2011-12", "2012-01", 
"2012-02", "2012-03", "2012-04", "2012-05", "2012-06", "2012-07", 
"2012-08", "2012-09", "2012-10", "2012-11", "2012-12", "2013-01", 
"2013-02", "2013-03", "2013-04", "2013-05", "2013-06", "2013-07", 
"2013-08", "2013-09", "2013-10", "2013-11", "2013-12", "2014-01", 
"2014-02", "2014-03", "2014-04", "2014-05", "2014-06", "2014-07", 
"2014-08", "2014-09", "2014-10", "2014-11", "2014-12", "2015-01", 
"2015-02", "2015-03", "2015-04", "2015-05", "2015-06", "2015-07", 
"2015-08", "2015-09", "2015-10", "2015-11", "2015-12", "2016-01", 
"2016-02", "2016-03", "2016-04", "2016-05", "2016-06", "2016-07", 
"2016-08", "2016-09", "2016-10", "2016-11", "2016-12", "2017-01", 
"2017-02", "2017-03", "2017-04", "2017-05", "2017-06", "2017-07", 
"2017-08", "2017-09", "2017-10", "2017-11", "2017-12", "2018-01", 
"2018-02", "2018-03", "2018-04", "2018-05", "2018-06"), class = "factor"),

Sum = c(53.51, 24.2, 88.54, 72.85, 77.3, 49.19, 8.77, 5.75,
27.83, 79.75, 123.89, 168.29, 229.69, 70.91, 74.15, 62.3,
43.56, 35.08, 3.6, 2.76, 26.83, 47.72, 293.23, 139.84, 103.48,
120.91, 85.96, 55.91, 26.56, 29.44, 9.9, 15.38, 33.47, 93.6,
105.61, 277.41, 279.38, 144.26, 220.88, 149.75, 82.28, 55.87,
5.29, 52.27, 21.1, 64.76, 182.31, 207.13, 196.29, 89.27,
187.72, 111.67, 111.72, 38.19, 6.07, 15.25, 52.46, 127.75,
208.43, 146.62, 169.34, 94.54, 154.21, 131.39, 151.27, 135.46,
9.98, 8.72, 86.67, 142.04, 225.61, 274.93, 196.68, 153.24,
263.54, 231.49, 122.23, 58.26, 34.65, 2.96, 28.21, 103.92,
217.52, 166.16, 305.27, 168.73, 333.28, 145.68, 101.2, 127.77,
15.41, 1.85, 3.49, 245.99, 272.35, 297.05, 177.17, 105.71,
118.44, 136.34, 161.01, 53.31, 1.15, 23.43, 200.97, 69.12,
158.51, 131.67, 156.95, 266.38, 291.7, 147.15, 101.49, 78.89,
26.99, 24.35, 35.76, 210.2, 225.55, 282.85, 153.91, 148.13,
187.03, 133.99, 62.28, 17.58, 13.41, 35.58, 47.04, 154.92,
317.77, 604.04, 288.91, 210.86, 266.04, 121.62, 78.17, 85.96,
29.84, 7.02, 72.13, 404.33, 247.71, 255.5, 138.22, 339.5,
368.99, 209.41, 110.08, 63.9, 0.62, 6.97, 133.75, 227.1,
312.99, 178.58, 255.8, 155.05, 135.27, 225.55, 15.23, 1.58
), Median = c(0.01, 0, 0, 0.1, 0.1, 0, 0, 0, 0, 0.02, 0.1,
0.04, 0.5, 0, 0.1, 0.07, 0, 0, 0, 0, 0, 0, 0.57, 0.03, 0,
0.2, 0.055, 0, 0, 0, 0, 0, 0, 0, 0, 0.21, 0.21, 0.02, 0.2,
0.11, 0.02, 0, 0, 0, 0, 0, 0.1, 0.165, 0.01, 0.01, 0.15,
0.01, 0, 0, 0, 0, 0, 0.02, 0.125, 0, 0.1, 0.08, 0.055, 0.1,
0.13, 0.01, 0, 0, 0, 0, 0.2, 0.17, 0.02, 0.07, 0.23, 0.15,
0.06, 0, 0, 0, 0, 0.03, 0.1, 0, 0.1, 0.1, 0.2, 0.07, 0, 0.02,
0, 0, 0, 0.04, 0.115, 0.24, 0.02, 0.03, 0.01, 0.01, 0.02,
0, 0, 0, 0, 0, 0.02, 0, 0, 0.2, 0.18, 0.05, 0, 0, 0, 0, 0,
0.08, 0.07, 0.1, 0, 0.01, 0, 0.02, 0, 0, 0, 0, 0, 0, 0.09,
0.4, 0.18, 0.1, 0.2, 0, 0, 0, 0, 0, 0, 0.29, 0.09, 0.09,
0, 0.26, 0.3, 0.16, 0, 0, 0, 0, 0, 0, 0.25, 0, 0.16, 0.03,
0.02, 0.08, 0, 0), Max = c(3, 1.1, 3.2, 1.2, 1.6, 1.48, 0.8,
0.6, 3.2, 4.9, 3.1, 3.63, 3.4, 2.6, 2, 3.25, 1.6, 2.1, 0.4,
0.5, 1.1, 2, 6.6, 3.2, 3.6, 5.8, 2.3, 1.7, 1.3, 1.2, 1, 2.1,
2, 3, 3, 5.9, 3.3, 2.9, 5.2, 1.8, 1.4, 2.2, 0.6, 2.5, 1.02,
2, 4.4, 3.6, 5.3, 2.2, 2.7, 2.5, 1.5, 1.4, 0.8, 1.4, 1.4,
2.11, 

[R] Remove plot axis values in dotplot graph

2018-09-11 Thread AbouEl-Makarim Aboueissa
Dear All:

One more thing. I want to Remove the plot x-axis values in dotplot graph. I
am trying to use xaxt = "n", but it seems NOT working. Also after removing
the x-axis values, I want to use the command axis(1, at=0:16, cex.axis=1)
to add x-axis values from 0 to 16, but it seems not working as expect.



Honey.Dosage<-c(12,11,15,11,10,13,10,4,15,16,9,14,10,6,10,8,11,12,12,8,12,9,11,15,10,15,9,13,8,12,10,8,9,5,12)

DM.Dosage<-c(4,6,9,4,7,7,7,9,12,10,11,6,3,4,9,12,7,6,8,12,12,4,12,13,7,10,13,9,4,4,10,15,9)

No.Dosage<-c(5,8,6,1,0,8,12,8,7,7,1,6,7,7,12,7,9,7,9,5,11,9,5,6,8,8,6,7,10,9,4,8,7,3,1,4,3)

scores<-c(Honey.Dosage,DM.Dosage,No.Dosage)

min(scores)
max(scores)

dotchart(scores,cex=1.5, pch = 18, col=c(1:3), xaxt = "n", main="Dot Plot
child’s cough data", xlab="cough Scores")

axis(1, at=0:16, cex.axis=1.5)




with many thanks
abou
__


*AbouEl-Makarim Aboueissa, PhD*

*Professor of Statistics*
*Graduate Coordinator*

*Department of Mathematics and Statistics*
*University of Southern Maine*

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

2018-09-11 Thread AbouEl-Makarim Aboueissa
Dear  Rui:

thank you very much

abou
__


*AbouEl-Makarim Aboueissa, PhD*

*Professor of Statistics*
*Graduate Coordinator*

*Department of Mathematics and Statistics*
*University of Southern Maine*



On Tue, Sep 11, 2018 at 2:24 PM Rui Barradas  wrote:

> Hello,
>
> Use function text() with the return of barplot() as x value and
> Number.of.Death as y.
> Note that the limits of the y axis are not the automatic ones.
>
>
>
> bp <- barplot(Number.of.Death, names.arg=Cause.of.Death, main="Bar Graph
> for
> Death Data", ylab="Number of Death", xlab="Cause of Death", ylim = c(0,
> 500))
>
> text(x = bp, y = Number.of.Death, labels = Number.of.Death, pos = 3)
>
>
> Hope this helps,
>
> Rui Barradas
>
> On 11-09-2018 19:02, AbouEl-Makarim Aboueissa wrote:
> > Dear All:
> >
> >
> > I do need your help on how to add frequency to bar plot on the top of
> each
> > bar.
> >
> >
> > here is the R code.
> >
> >
> > *Number.of.Death <- c(432, 217,93, 34, 224)# Number of Death*
> >
> > *Cause.of.Death <- c("Heart disease", "Cancer", "Stroke", "Accidents",
> > "Other")  *
> >
> > *barplot(Number.of.Death, names.arg=Cause.of.Death, main="Bar Grapg for
> > Death Data", ylab="Number of Death", xlab="Cause of Death") *
> >
> >
> >
> > Thank you very much for your help in advance.
> >
> >
> > with many thanks
> > abou
> > __
> >
> >
> > *AbouEl-Makarim Aboueissa, PhD*
> >
> > *Professor of Statistics*
> > *Graduate Coordinator*
> >
> > *Department of Mathematics and Statistics*
> > *University of Southern Maine*
> >
> >   [[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.
> >
>

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

2018-09-11 Thread AbouEl-Makarim Aboueissa
Dear Bert:

thank you very much

abou
__


*AbouEl-Makarim Aboueissa, PhD*

*Professor of Statistics*
*Graduate Coordinator*

*Department of Mathematics and Statistics*
*University of Southern Maine*



On Tue, Sep 11, 2018 at 2:47 PM Bert Gunter  wrote:

> Not quite -- he wanted the frequencies not the counts. So something
> like this (using the adj argument to center the frequencies above each
> bar:
>
> bp <-barplot(Number.of.Death, names.arg=Cause.of.Death, main="Bar
> Graph for Death Data", ylab="Number of Deaths", xlab="Cause of Death",
> ylim = c(0,500) )
>
> text(bp, y = Number.of.Death + 30, adj = .5,
>  lab = round(Number.of.Death/sum(Number.of.Death),2))
>
> Cheers,
> Bert
>
> "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 Tue, Sep 11, 2018 at 11:02 AM AbouEl-Makarim Aboueissa
>  wrote:
> >
> > Dear All:
> >
> >
> > I do need your help on how to add frequency to bar plot on the top of
> each
> > bar.
> >
> >
> > here is the R code.
> >
> >
> > *Number.of.Death <- c(432, 217,93, 34, 224)# Number of Death*
> >
> > *Cause.of.Death <- c("Heart disease", "Cancer", "Stroke", "Accidents",
> > "Other")  *
> >
> > *barplot(Number.of.Death, names.arg=Cause.of.Death, main="Bar Grapg for
> > Death Data", ylab="Number of Death", xlab="Cause of Death") *
> >
> >
> >
> > Thank you very much for your help in advance.
> >
> >
> > with many thanks
> > abou
> > __
> >
> >
> > *AbouEl-Makarim Aboueissa, PhD*
> >
> > *Professor of Statistics*
> > *Graduate Coordinator*
> >
> > *Department of Mathematics and Statistics*
> > *University of Southern Maine*
> >
> > [[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.
>

[[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] [FORGED] Re: getting 21 very different colours

2018-09-11 Thread Paul Murrell



You could also take a look at the 'Polychrome' package

Paul

On 12/09/18 03:36, Barry Rowlingson wrote:

On Tue, Sep 11, 2018 at 11:43 AM, Duncan Murdoch 
wrote:


On 11/09/2018 3:34 AM, Federico Calboli wrote:

Hi All,

I am plotting a scatterplot of 21 populations, and I am using

rainbow(21)[pops.col] to generate 21 colours for the plot (which works).
Maybe it is because I can really process few colours at a time, but the
differences between the colours are not as strong as I’d like.  I can
specify start and end for rainbow(), but if anything that looks worse if I
do not just stick to 0 and 1.


Is there a way of getting a set of 21 colours that maximises the

differences between them?

The LAB and LUV color spaces (in the colorspace package) attempt to map
perceptual differences to equal distances.  You could try using a grid
of points in one of those spaces, but not all triples are valid.

However, 21 colours is probably too many for your purpose.  If you
really want to distinguish 21 groups, you're likely going to have to use
other characteristics as well, such as the symbol.  You could plot 21
different letters in 5 different colours and it might work, but it's not
going to be easy for viewers.



The `alphabet` and `alphabet2` palettes from the `pals` package claim 26
"distinguishable" colours:

Details:

  The ‘alphabet’ palette has 26 distinguishable colors that have
  logical names starting with the English alphabet letters A, B, ...
  Z. This palette is based on the work by Green-Armytage (2010), but
  uses the names 'orange' instead of 'orpiment', and 'magenta'
  instead of 'mallow'.

There are some other palettes in that help page (?alphabet) that might also
work. But 21 colours is pushing it.

Barry







Duncan Murdoch



I could pick them by hand, but that is about 15 colours more than I know

(I have a detailed colourchart, but the visual differences between
’skyblue’ and ’slategrey’ elude me when plotted as dots on a plot).


Cheers

F
--
Federico Calboli
LBEG - Laboratory of Biodiversity and Evolutionary Genomics
Charles Deberiotstraat 32 box 2439
3000 Leuven
+32 16 32 87 67





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



--
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] Bar Graph

2018-09-11 Thread Bert Gunter
Not quite -- he wanted the frequencies not the counts. So something
like this (using the adj argument to center the frequencies above each
bar:

bp <-barplot(Number.of.Death, names.arg=Cause.of.Death, main="Bar
Graph for Death Data", ylab="Number of Deaths", xlab="Cause of Death",
ylim = c(0,500) )

text(bp, y = Number.of.Death + 30, adj = .5,
 lab = round(Number.of.Death/sum(Number.of.Death),2))

Cheers,
Bert

"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 Tue, Sep 11, 2018 at 11:02 AM AbouEl-Makarim Aboueissa
 wrote:
>
> Dear All:
>
>
> I do need your help on how to add frequency to bar plot on the top of each
> bar.
>
>
> here is the R code.
>
>
> *Number.of.Death <- c(432, 217,93, 34, 224)# Number of Death*
>
> *Cause.of.Death <- c("Heart disease", "Cancer", "Stroke", "Accidents",
> "Other")  *
>
> *barplot(Number.of.Death, names.arg=Cause.of.Death, main="Bar Grapg for
> Death Data", ylab="Number of Death", xlab="Cause of Death") *
>
>
>
> Thank you very much for your help in advance.
>
>
> with many thanks
> abou
> __
>
>
> *AbouEl-Makarim Aboueissa, PhD*
>
> *Professor of Statistics*
> *Graduate Coordinator*
>
> *Department of Mathematics and Statistics*
> *University of Southern Maine*
>
> [[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] Bar Graph

2018-09-11 Thread Rui Barradas

Hello,

Use function text() with the return of barplot() as x value and 
Number.of.Death as y.

Note that the limits of the y axis are not the automatic ones.



bp <- barplot(Number.of.Death, names.arg=Cause.of.Death, main="Bar Graph for
Death Data", ylab="Number of Death", xlab="Cause of Death", ylim = c(0, 
500))


text(x = bp, y = Number.of.Death, labels = Number.of.Death, pos = 3)


Hope this helps,

Rui Barradas

On 11-09-2018 19:02, AbouEl-Makarim Aboueissa wrote:

Dear All:


I do need your help on how to add frequency to bar plot on the top of each
bar.


here is the R code.


*Number.of.Death <- c(432, 217,93, 34, 224)# Number of Death*

*Cause.of.Death <- c("Heart disease", "Cancer", "Stroke", "Accidents",
"Other")  *

*barplot(Number.of.Death, names.arg=Cause.of.Death, main="Bar Grapg for
Death Data", ylab="Number of Death", xlab="Cause of Death") *



Thank you very much for your help in advance.


with many thanks
abou
__


*AbouEl-Makarim Aboueissa, PhD*

*Professor of Statistics*
*Graduate Coordinator*

*Department of Mathematics and Statistics*
*University of Southern Maine*

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

2018-09-11 Thread AbouEl-Makarim Aboueissa
Dear All:


I do need your help on how to add frequency to bar plot on the top of each
bar.


here is the R code.


*Number.of.Death <- c(432, 217,93, 34, 224)# Number of Death*

*Cause.of.Death <- c("Heart disease", "Cancer", "Stroke", "Accidents",
"Other")  *

*barplot(Number.of.Death, names.arg=Cause.of.Death, main="Bar Grapg for
Death Data", ylab="Number of Death", xlab="Cause of Death") *



Thank you very much for your help in advance.


with many thanks
abou
__


*AbouEl-Makarim Aboueissa, PhD*

*Professor of Statistics*
*Graduate Coordinator*

*Department of Mathematics and Statistics*
*University of Southern Maine*

[[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] getting 21 very different colours

2018-09-11 Thread Barry Rowlingson
On Tue, Sep 11, 2018 at 11:43 AM, Duncan Murdoch 
wrote:

> On 11/09/2018 3:34 AM, Federico Calboli wrote:
> > Hi All,
> >
> > I am plotting a scatterplot of 21 populations, and I am using
> rainbow(21)[pops.col] to generate 21 colours for the plot (which works).
> Maybe it is because I can really process few colours at a time, but the
> differences between the colours are not as strong as I’d like.  I can
> specify start and end for rainbow(), but if anything that looks worse if I
> do not just stick to 0 and 1.
> >
> > Is there a way of getting a set of 21 colours that maximises the
> differences between them?
>
> The LAB and LUV color spaces (in the colorspace package) attempt to map
> perceptual differences to equal distances.  You could try using a grid
> of points in one of those spaces, but not all triples are valid.
>
> However, 21 colours is probably too many for your purpose.  If you
> really want to distinguish 21 groups, you're likely going to have to use
> other characteristics as well, such as the symbol.  You could plot 21
> different letters in 5 different colours and it might work, but it's not
> going to be easy for viewers.
>
>
The `alphabet` and `alphabet2` palettes from the `pals` package claim 26
"distinguishable" colours:

Details:

 The ‘alphabet’ palette has 26 distinguishable colors that have
 logical names starting with the English alphabet letters A, B, ...
 Z. This palette is based on the work by Green-Armytage (2010), but
 uses the names 'orange' instead of 'orpiment', and 'magenta'
 instead of 'mallow'.

There are some other palettes in that help page (?alphabet) that might also
work. But 21 colours is pushing it.

Barry






> Duncan Murdoch
>
> >
> > I could pick them by hand, but that is about 15 colours more than I know
> (I have a detailed colourchart, but the visual differences between
> ’skyblue’ and ’slategrey’ elude me when plotted as dots on a plot).
> >
> > Cheers
> >
> > F
> > --
> > Federico Calboli
> > LBEG - Laboratory of Biodiversity and Evolutionary Genomics
> > Charles Deberiotstraat 32 box 2439
> > 3000 Leuven
> > +32 16 32 87 67
> >
> >
> >
> >
> >
> > __
> > 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.


Re: [R] For loop with multiple iteration indexes

2018-09-11 Thread David L Carlson
Just for fun, there are ways to do this in R without an explicit loop:

> set.seed(42)
> dat <- matrix(rnorm(10*5), 10, 5)
> x <- sample(1:5)
> y <- sample(1:5)
> diag(cor(dat[, x], dat[, y]))
[1] -0.69156568 -0.06002371 -0.37492894  0.46477742 -0.37972866

You can use as.list() to convert the vector to a list.

> i <- seq_len(length(x))
> sapply(i, function(j) cor(dat[, x[j]], dat[, y[j]]))
[1] -0.69156568 -0.06002371 -0.37492894  0.46477742 -0.37972866
> xy <- cbind(x, y)
> sapply(i, function(j) cor(dat[, xy[j, ]])[1, 2])
[1] -0.69156568 -0.06002371 -0.37492894  0.46477742 -0.37972866

Change sapply() to lapply() to get list output.


David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77843-4352

-Original Message-
From: R-help  On Behalf Of David Disabato
Sent: Monday, September 10, 2018 8:33 PM
To: r-help@r-project.org
Subject: Re: [R] For loop with multiple iteration indexes

Thank you everyone. After thinking about each response, I realized a fairly 
simple solution is available (obviously, other suggested approaches work as
well):

stopifnot(length(x) == length(y); stopifnot(length(x) > 0) r <- list() for (i 
in 1:length(x) ) {
   r[[i]] <- cor(x = dat[, x[i] ], y = dat[, y[i] ]) }
print(r)

On Mon, Sep 10, 2018 at 11:30 AM Berry, Charles  wrote:

> I have a sense of deja vu:
>
> https://www.mail-archive.com/r-help@r-project.org/msg250494.html
>
> There is some good advice there.
>
> > On Sep 9, 2018, at 3:49 PM, David Disabato  wrote:
> >
> > Hi R-help,
> >
> > I am trying to create a for loop with multiple iteration indexes. I 
> > don't want to use two different for loops nested together because I 
> > don't need the full matrix of the two indexes, just the diagonal 
> > elements (e.g.,
> i[1]
> > & j[1] and i[2] & j[2], but not i[1] & j[2]). Is there a way to 
> > specify both i and j in a single for loop? Here is a simplified 
> > example of pseudo-code where x and y are equally sized character 
> > vectors with column names and dat is their dataframe (obviously this 
> > code doesn't run in R,
> but
> > hopefully you perceive my goal):
> >
> > r <- list()
> > n <- 0
> > for (i in x; j in y) {
> >   n <- n + 1
> >   r[[n]] <- cor(x = dat[, i], y = dat[, j]) }
> > print(r)
> >
> > I realize there are other solutions to this particular correlation
> example,
> > but my actual problem is much more complicated, so I am hoping for a 
> > solution that generalizes across any code within the for loop.
>
> A more aRtful way (than a for loop) to approach this is with mapply:
>
>
> i <- head(colnames(mtcars))
> j <- tail(colnames(mtcars))
>
> r <- mapply(function(i, j, dat) cor( x = dat[, i], y = dat[, j]),
>i=i , j=j , MoreArgs = list( dat = mtcars),
>SIMPLIFY = FALSE, USE.NAMES = FALSE)
>
>
> and if you want, maybe USE.NAMES = paste(i, j, sep="_")
>
> Chuck
>
>

--
David J. Disabato, M.A.
Clinical Psychology Doctoral Student
George Mason University
ddisa...@gmu.edu

Email is not a secure form of communication as information and confidentiality 
cannot be guaranteed. Information provided in an email is not intended to be a 
professional service. In the case of a crisis or emergency situation, call 911.

[[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] loop for comparing two or more groups using bootstrapping

2018-09-11 Thread Kristi Glover
Dear Jim,

Thank you very much for the code. I run it but it gave me row names like 
"year224", "year142".

are these the difference between columns? If we want to get bootstrapping means 
of difference between years (year2-year1; year3-year1), its CI and exact p 
value, how can we get it?

thanks

KG



head(daT)

colname.mat<-combn(paste0("year",1:4),2)

samplenames<-apply(colname.mat,2,paste,collapse="")

k<-10

for(column in 1:ncol(colname.mat)) {

 
assign(samplenames[column],replicate(k,sample(unlist(daT[,colname.mat[,column]]),3,TRUE)))

}


> get(samplenames[1])
 [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9] [,10]
year224 0.556 0.667 0.571 0.526 0.629 0.696 0.323 0.526 0.256 0.667
year142 0.324 0.324 0.706 0.638 0.600 0.294 0.612 0.688 0.432 0.387
year237 0.571 0.696 0.629 0.471 0.462 0.471 0.452 0.595 0.333 0.435





From: Jim Lemon 
Sent: September 11, 2018 1:44 AM
To: Kristi Glover
Cc: r-help mailing list
Subject: Re: [R] loop for comparing two or more groups using bootstrapping

Hi Kristy,
Try this:

colname.mat<-combn(paste0("year",1:4),2)
samplenames<-apply(colname.mat,2,paste,collapse="")
k<-1
for(column in 1:ncol(colname.mat)) {
 
assign(samplenames[column],replicate(k,sample(unlist(daT[,colname.mat[,column]]),3,TRUE)))
}

Then use get(samplenames[1]) and so on to access the values.

Jim
On Tue, Sep 11, 2018 at 4:52 PM Kristi Glover  wrote:
>
> Hi R users,
>
> I was trying to test a null hypothesis of difference between two groups was 
> 0. I have many years data, such as year1, year2,, year3, year4 and I was 
> trying to compare between year1 and year2, year1 and year3, year2 and year3 
> and so on and have used following code with an example data.
>
>
> I tried to make a loop but did not work to compare between many years, and 
> also want to obtain the exact p value. Would you mind to help me to make a 
> loop?
>
> Thanks for your help.
>
>
> KG
>
>
> daT<-structure(list(year1 = c(0.417, 0.538, 0.69, 0.688, 0.688, 0.606,
> 0.667, 0.7, 0.545, 0.462, 0.711, 0.642, 0.744, 0.604, 0.612,
> 0.667, 0.533, 0.556, 0.444, 0.526, 0.323, 0.308, 0.195, 0.333,
> 0.323, 0.256, 0.345, 0.205, 0.286, 0.706, 0.7, 0.6, 0.571, 0.364,
> 0.429, 0.326, 0.571, 0.424, 0.341, 0.387, 0.341, 0.324, 0.696,
> 0.696, 0.583, 0.556, 0.645, 0.435, 0.471, 0.556), year2 = c(0.385,
> 0.552, 0.645, 0.516, 0.629, 0.595, 0.72, 0.638, 0.557, 0.588,
> 0.63, 0.744, 0.773, 0.571, 0.723, 0.769, 0.667, 0.667, 0.526,
> 0.476, 0.294, 0.323, 0.222, 0.556, 0.263, 0.37, 0.357, 0.25,
> 0.323, 0.778, 0.667, 0.636, 0.583, 0.432, 0.412, 0.333, 0.571,
> 0.39, 0.4, 0.452, 0.326, 0.471, 0.7, 0.75, 0.615, 0.462, 0.556,
> 0.4, 0.696, 0.465), year3 = c(0.435, 0.759, 0.759, 0.759, 0.714,
> 0.593, 0.651, 0.683, 0.513, 0.643, 0.652, 0.757, 0.791, 0.649,
> 0.78, 0.5, 0.5, 0.5, 0.533, 0.429, 0.333, 0.286, 0.231, 0.533,
> 0.303, 0.417, 0.333, 0.333, 0.357, 0.909, 1, 0.952, 0.8, 0.556,
> 0.529, 0.562, 0.762, 0.513, 0.733, 0.611, 0.733, 0.647, 0.909,
> 0.857, 0.8, 0.556, 0.588, 0.562, 0.857, 0.513), year4 = c(0.333,
> 0.533, 0.6, 0.483, 0.743, 0.5, 0.691, 0.619, 0.583, 0.385, 0.653,
> 0.762, 0.844, 0.64, 0.667, 0.571, 0.571, 0.615, 0.421, 0.5, 0.205,
> 0.308, 0.25, 0.6, 0.242, 0.308, 0.276, 0.235, 0.211, 0.9, 0.632,
> 0.72, 0.727, 0.356, 0.5, 0.368, 0.5, 0.41, 0.562, 0.514, 0.4,
> 0.409, 0.632, 0.72, 0.727, 0.4, 0.5, 0.421, 0.5, 0.462)), .Names = c("year1",
> "year2", "year3", "year4"), row.names = c(NA, -50L), class = "data.frame")
>
> head(daT)
>
> # null hypothesis; difference is equal to zero
>
> dif1.2<-daT$year2-daT$year1
>
> k=1
>
> mysamples1.2=replicate(k, sample(dif1.2, replace=T))
>
> mymeans1.2=apply(mysamples1.2, 2, mean)
>
> quantile(mymeans1.2, c(0.025, 0.975))
>
> hist(mysamples1.2)
>
> mean(mymeans1.2)
>
> #what is p value?
>
>
> #similarly Now I want to compare between year 1 and year3,
>
> dif1.3<-daT$year3-daT$year1
>
> mysamples1.3=replicate(k, sample(dif1.3, replace=T))
>
> mymeans1.3=apply(mysamples1.3, 2, mean)
>
> quantile(mymeans1.3, c(0.025, 0.975))
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help

thz.ch/mailman/listinfo/r-help>
stat.ethz.ch
The main R mailing list, for announcements about the development of R and the 
availability of new code, questions and answers about problems and solutions 
using R, enhancements and patches to the source code and documentation of R, 
comparison and compatibility with S and S-plus, and for the posting of nice 
examples and benchmarks.



> 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

[R] Problem with lm.resid() when weights are provided

2018-09-11 Thread Hamed Ha
Dear R Help Team.

I get some weird results when I use the lm function with weight. The issue
can be reproduced by the example below:


The input data is (weights are intentionally designed to reflect some
structures in the data)


> df
y x weight
 1.51156139  0.55209240 2.117337e-34
-0.63653132 -0.12599316 2.117337e-34
 0.37782776  0.42095384 4.934135e-31
 3.03792318  1.40315446 2.679495e-24
 1.53646523  0.46076858 2.679495e-24
-2.37727874 -0.73963576 6.244160e-21
 0.37183065  0.20407468 1.455107e-17
-1.53917553 -0.95519361 1.455107e-17
 1.10926675  0.03897129 3.390908e-14
-0.37786333 -0.17523593 3.390908e-14
 2.43973603  0.97970095 7.902000e-11
-0.35432394 -0.03742559 7.902000e-11
 2.19296613  1.00355263 4.289362e-04
 0.49845532  0.34816207 4.289362e-04
 1.25005260  0.76306225 5.00e-01
 0.84360691  0.45152356 5.00e-01
 0.29565993  0.53880068 5.00e-01
-0.54081334 -0.28104525 5.00e-01
 0.83612836 -0.12885659 9.995711e-01
-1.42526769 -0.87107631 9.98e-01
 0.10204789 -0.11649899 1.00e+00
 1.14292898  0.37249631 1.00e+00
-3.02942081 -1.28966997 1.00e+00
-1.37549764 -0.74676145 1.00e+00
-2.00118016 -0.55182759 1.00e+00
-4.24441674 -1.94603608 1.00e+00
 1.17168144  1.00868008 1.00e+00
 2.64007761  1.26333069 1.00e+00
 1.98550114  1.18509599 1.00e+00
-0.58941683 -0.61972416 9.98e-01
-4.57559611 -2.30914920 9.995711e-01
-0.82610544 -0.39347576 9.995711e-01
-0.02768220  0.20076910 9.995711e-01
 0.78186399  0.25690215 9.995711e-01
-0.88314153 -0.20200148 5.00e-01
-4.17076452 -2.03547588 5.00e-01
 0.93373070  0.54190626 4.289362e-04
-0.08517734  0.17692491 4.289362e-04
-4.47546619 -2.14876688 4.289362e-04
-1.65509103 -0.76898087 4.289362e-04
-0.39403030 -0.12689705 4.289362e-04
 0.01203300 -0.18689898 1.841442e-07
-4.82762639 -2.31391121 1.841442e-07
-0.72658380 -0.39751171 3.397282e-14
-2.35886866 -1.01082109 0.00e+00
-2.03762707 -0.96439902 0.00e+00
 0.90115123  0.60172286 0.00e+00
 1.55999194  0.83433953 0.00e+00
 3.07994058  1.30942776 0.00e+00
 1.78871462  1.10605530 0.00e+00



Running simple linear model returns:

> lm(y~x,data=df)

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

Coefficients:
(Intercept)x
   -0.04173  2.03790

and
> max(resid(lm(y~x,data=df)))
[1] 1.14046


*HOWEVER if I use the weighted model then:*

lm(formula = y ~ x, data = df, weights = df$weights)

Coefficients:
(Intercept)x
   -0.05786  1.96087

and
> max(resid(lm(y~x,data=df,weights=df$weights)))
[1] 60.91888


as you see, the estimation of the coefficients are nearly the same but the
resid() function returns a giant residual (I have some cases where the
value is much much higher). Further, if I calculate the residuals by
simply predict(lm(y~x,data=df,weights=df$weights))-df$y then I get the true
value for the residuals.


Thanks.

Please do not hesitate to contact me for more details.
Regards,
Hamed.

[[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] getting 21 very different colours

2018-09-11 Thread Duncan Murdoch

On 11/09/2018 3:34 AM, Federico Calboli wrote:

Hi All,

I am plotting a scatterplot of 21 populations, and I am using 
rainbow(21)[pops.col] to generate 21 colours for the plot (which works).  Maybe 
it is because I can really process few colours at a time, but the differences 
between the colours are not as strong as I’d like.  I can specify start and end 
for rainbow(), but if anything that looks worse if I do not just stick to 0 and 
1.

Is there a way of getting a set of 21 colours that maximises the differences 
between them?


The LAB and LUV color spaces (in the colorspace package) attempt to map 
perceptual differences to equal distances.  You could try using a grid 
of points in one of those spaces, but not all triples are valid.


However, 21 colours is probably too many for your purpose.  If you 
really want to distinguish 21 groups, you're likely going to have to use 
other characteristics as well, such as the symbol.  You could plot 21 
different letters in 5 different colours and it might work, but it's not 
going to be easy for viewers.


Duncan Murdoch



I could pick them by hand, but that is about 15 colours more than I know (I 
have a detailed colourchart, but the visual differences between ’skyblue’ and 
’slategrey’ elude me when plotted as dots on a plot).

Cheers

F
--
Federico Calboli
LBEG - Laboratory of Biodiversity and Evolutionary Genomics
Charles Deberiotstraat 32 box 2439
3000 Leuven
+32 16 32 87 67





__
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] getting 21 very different colours

2018-09-11 Thread Ivan Krylov
On Tue, 11 Sep 2018 07:34:51 +
Federico Calboli  wrote:

> Is there a way of getting a set of 21 colours that maximises the
> differences between them?  

In my limited experience, getting even 10 colours to look different
enough is a serious undertaking. Take a look at RColorBrewer:
display.brewer.all(n, "qual") stops offering palettes for n>12.

When I needed a 10-colour categorical/qualitative palette, I opted for
brute force approach of maximising the minimal distance between points
in HCL colourspace, although later my colleague told me that I just
needed an existing algorithm to place the points uniformly. It has to
be HCL and not RGB because HCL signifies the way people perceive
different colours while RGB is only a good representation hardware-wise.

Here is my code; the usual disclaimers about stuff written between 1 and
3 AM apply:

# -8<---

require(nloptr)

h <- c(0,360)
c <- c(0,137) # see the warning about fixup in `?hcl`: not all HCL points are 
representable in RGB

# NOTE: depending on your plot background, you may have to change at least 
luminance range
l <- c(30,90)

npoints <- 24 # I had only 10 here

pts <- matrix(ncol=3, nrow=npoints, dimnames=list(NULL, c("h","c","l")))
pts[,"h"] <- runif(npoints, min=h[1], max=h[2])
pts[,"c"] <- runif(npoints, min=c[1], max=c[2])
pts[,"l"] <- runif(npoints, min=l[1], max=l[2])

lb <- cbind(h=rep(h[1],npoints), c=rep(c[1],npoints), l=rep(l[1],npoints))
ub <- cbind(h=rep(h[2],npoints), c=rep(c[2],npoints), l=rep(l[2],npoints))

obj <- function(x) {
pts[,c("h","c","l")] <- x
# somehow the best results were achieved by calculating Euclidean 
distance from cylindrical coordinates
pts <- cbind(pts[,"c"]*sin(pts[,'h']/360*2*pi), 
pts[,'c']*cos(pts[,'h']/360*2*pi), pts[,'l'])
d <- as.matrix(dist(pts))
diag(d) <- NA
# maximise minimal distance <=> minimize negative of minimal distance
-min(d, na.rm=T)
}

# the stopping criterion is a bit lame, but the objective function here is very 
hard to minimize
# 1e6 iterations take a few minutes on a relatively modern desktop
sol <- nloptr(as.vector(pts), obj, lb=as.vector(lb), ub=as.vector(ub), 
opts=list(algorithm="NLOPT_GN_CRS2_LM", maxeval=1e6))

pts[,c("h","c",'l')] <- sol$solution

plot(pts[,"c"] * sin(pts[,"h"]/360*2*pi), pts[,"c"] * cos(pts[,"h"]/360*2*pi), 
col=hcl(pts[,"h"], pts[,"c"], l), pch=19, cex=2)

# -8<---

I couldn't get my code to produce 24 acceptably different colours, but
maybe you will succeed with a similar approach.

-- 
Best regards,
Ivan

__
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] getting 21 very different colours

2018-09-11 Thread S Ellison
You could look at combning a number of palettes from the RColorBrewer package 
to get the palette length you want.

S Ellison

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Federico
> Calboli
> Sent: 11 September 2018 08:35
> To: r-help@r-project.org
> Subject: [R] getting 21 very different colours
> 
> Hi All,
> 
> I am plotting a scatterplot of 21 populations, and I am using
> rainbow(21)[pops.col] to generate 21 colours for the plot (which works).
> Maybe it is because I can really process few colours at a time, but the
> differences between the colours are not as strong as I’d like.  I can specify
> start and end for rainbow(), but if anything that looks worse if I do not just
> stick to 0 and 1.
> 
> Is there a way of getting a set of 21 colours that maximises the differences
> between them?
> 
> I could pick them by hand, but that is about 15 colours more than I know (I
> have a detailed colourchart, but the visual differences between ’skyblue’ and
> ’slategrey’ elude me when plotted as dots on a plot).
> 
> Cheers
> 
> F
> --
> Federico Calboli
> LBEG - Laboratory of Biodiversity and Evolutionary Genomics
> Charles Deberiotstraat 32 box 2439
> 3000 Leuven
> +32 16 32 87 67
> 
> 
> 
> 
> 
> __
> 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.


***
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
__
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] getting 21 very different colours

2018-09-11 Thread Federico Calboli
Hi All,

I am plotting a scatterplot of 21 populations, and I am using 
rainbow(21)[pops.col] to generate 21 colours for the plot (which works).  Maybe 
it is because I can really process few colours at a time, but the differences 
between the colours are not as strong as I’d like.  I can specify start and end 
for rainbow(), but if anything that looks worse if I do not just stick to 0 and 
1.  

Is there a way of getting a set of 21 colours that maximises the differences 
between them?  

I could pick them by hand, but that is about 15 colours more than I know (I 
have a detailed colourchart, but the visual differences between ’skyblue’ and 
’slategrey’ elude me when plotted as dots on a plot).

Cheers

F
--
Federico Calboli
LBEG - Laboratory of Biodiversity and Evolutionary Genomics
Charles Deberiotstraat 32 box 2439
3000 Leuven
+32 16 32 87 67





__
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] loop for comparing two or more groups using bootstrapping

2018-09-11 Thread Jim Lemon
Hi Kristy,
Try this:

colname.mat<-combn(paste0("year",1:4),2)
samplenames<-apply(colname.mat,2,paste,collapse="")
k<-1
for(column in 1:ncol(colname.mat)) {
 
assign(samplenames[column],replicate(k,sample(unlist(daT[,colname.mat[,column]]),3,TRUE)))
}

Then use get(samplenames[1]) and so on to access the values.

Jim
On Tue, Sep 11, 2018 at 4:52 PM Kristi Glover  wrote:
>
> Hi R users,
>
> I was trying to test a null hypothesis of difference between two groups was 
> 0. I have many years data, such as year1, year2,, year3, year4 and I was 
> trying to compare between year1 and year2, year1 and year3, year2 and year3 
> and so on and have used following code with an example data.
>
>
> I tried to make a loop but did not work to compare between many years, and 
> also want to obtain the exact p value. Would you mind to help me to make a 
> loop?
>
> Thanks for your help.
>
>
> KG
>
>
> daT<-structure(list(year1 = c(0.417, 0.538, 0.69, 0.688, 0.688, 0.606,
>
> 0.667, 0.7, 0.545, 0.462, 0.711, 0.642, 0.744, 0.604, 0.612,
>
> 0.667, 0.533, 0.556, 0.444, 0.526, 0.323, 0.308, 0.195, 0.333,
>
> 0.323, 0.256, 0.345, 0.205, 0.286, 0.706, 0.7, 0.6, 0.571, 0.364,
>
> 0.429, 0.326, 0.571, 0.424, 0.341, 0.387, 0.341, 0.324, 0.696,
>
> 0.696, 0.583, 0.556, 0.645, 0.435, 0.471, 0.556), year2 = c(0.385,
>
> 0.552, 0.645, 0.516, 0.629, 0.595, 0.72, 0.638, 0.557, 0.588,
>
> 0.63, 0.744, 0.773, 0.571, 0.723, 0.769, 0.667, 0.667, 0.526,
>
> 0.476, 0.294, 0.323, 0.222, 0.556, 0.263, 0.37, 0.357, 0.25,
>
> 0.323, 0.778, 0.667, 0.636, 0.583, 0.432, 0.412, 0.333, 0.571,
>
> 0.39, 0.4, 0.452, 0.326, 0.471, 0.7, 0.75, 0.615, 0.462, 0.556,
>
> 0.4, 0.696, 0.465), year3 = c(0.435, 0.759, 0.759, 0.759, 0.714,
>
> 0.593, 0.651, 0.683, 0.513, 0.643, 0.652, 0.757, 0.791, 0.649,
>
> 0.78, 0.5, 0.5, 0.5, 0.533, 0.429, 0.333, 0.286, 0.231, 0.533,
>
> 0.303, 0.417, 0.333, 0.333, 0.357, 0.909, 1, 0.952, 0.8, 0.556,
>
> 0.529, 0.562, 0.762, 0.513, 0.733, 0.611, 0.733, 0.647, 0.909,
>
> 0.857, 0.8, 0.556, 0.588, 0.562, 0.857, 0.513), year4 = c(0.333,
>
> 0.533, 0.6, 0.483, 0.743, 0.5, 0.691, 0.619, 0.583, 0.385, 0.653,
>
> 0.762, 0.844, 0.64, 0.667, 0.571, 0.571, 0.615, 0.421, 0.5, 0.205,
>
> 0.308, 0.25, 0.6, 0.242, 0.308, 0.276, 0.235, 0.211, 0.9, 0.632,
>
> 0.72, 0.727, 0.356, 0.5, 0.368, 0.5, 0.41, 0.562, 0.514, 0.4,
>
> 0.409, 0.632, 0.72, 0.727, 0.4, 0.5, 0.421, 0.5, 0.462)), .Names = c("year1",
>
> "year2", "year3", "year4"), row.names = c(NA, -50L), class = "data.frame")
>
> head(daT)
>
> # null hypothesis; difference is equal to zero
>
> dif1.2<-daT$year2-daT$year1
>
> k=1
>
> mysamples1.2=replicate(k, sample(dif1.2, replace=T))
>
> mymeans1.2=apply(mysamples1.2, 2, mean)
>
> quantile(mymeans1.2, c(0.025, 0.975))
>
> hist(mysamples1.2)
>
> mean(mymeans1.2)
>
> #what is p value?
>
>
> #similarly Now I want to compare between year 1 and year3,
>
> dif1.3<-daT$year3-daT$year1
>
> mysamples1.3=replicate(k, sample(dif1.3, replace=T))
>
> mymeans1.3=apply(mysamples1.3, 2, mean)
>
> quantile(mymeans1.3, c(0.025, 0.975))
>
>
> [[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.