Re: [R] EOF within quoted string

2017-08-10 Thread Adams, Jean
You might want to try some of the suggestions mentioned in this post:
https://stackoverflow.com/q/17414776/2140956

Jean

On Thu, Aug 10, 2017 at 7:59 AM,  wrote:

> Hi,
>
> Reading http://ssc.wisc.edu/~ahanna/20_newsgroups.csv after downloading
> it using
>
> data <- read.csv("20_newsgroups.csv",header=TRUE)
>
> throws this.
>
> Warning message:
> In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
>   EOF within quoted string
>
> So, for example, the first line in the file is this. This column contains
> only such text. Is there a way read it ?
>
> From: cub...@garnet.berkeley.edu () Subject: Re: Cubs behind Marlins?
> How? Article-I.D.: agate.1pt592$f9a Organization: University of California,
> Berkeley Lines: 12 NNTP-Posting-Host: garnet.berkeley.edu
> gajar...@pilot.njin.net writes:  morgan and guzman will have era's 1 run
> higher than last year, and  the cubs will be idiots and not pitch harkey as
> much as hibbard.  castillo won't be good (i think he's a stud pitcher)
>This season so far, Morgan and Guzman helped to lead the Cubsat
> top in ERA, even better than THE rotation at Atlanta.Cubs ERA at
> 0.056 while Braves at 0.059. We know it is earlyin the season, we
> Cubs fans have learned how to enjoy theshort triumph while it is
> still there.
>
> Thanks,
> Mohan
> This e-mail and any files transmitted with it are for the sole use of the
> intended recipient(s) and may contain confidential and privileged
> information. If you are not the intended recipient(s), please reply to the
> sender and destroy all copies of the original message. Any unauthorized
> review, use, disclosure, dissemination, forwarding, printing or copying of
> this email, and/or any action taken in reliance on the contents of this
> e-mail is strictly prohibited and may be unlawful. Where permitted by
> applicable law, this e-mail and other e-mail communications sent to and
> from Cognizant e-mail addresses may be monitored.
>
> [[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] about reading files in order

2017-06-29 Thread Adams, Jean
Thanks for that answer.
I was not aware of gtools::mixedsort

function.

Jean

On Thu, Jun 29, 2017 at 2:47 PM, Henrik Bengtsson <
henrik.bengts...@gmail.com> wrote:

> You can use:
>
> > files <- list.files(path = "folder01")
> > files <- gtools::mixedsort(files)
>
> to order the files in a "human-friendly" order rather than
> lexicographic order (which sort() provides).
>
> FYI 1; it's preferred to use file.path("folder01", list[i]) rather
> than paste('folder01',lists[i],sep='/').
>
> FYI 2; if you use list.files(path = "folder01", full.names = TRUE),
> you get the full paths rather name just the file names, i.e. you don't
> have to use file.path().
>
> /Henrik
>
> On Thu, Jun 29, 2017 at 12:04 PM, lily li  wrote:
> > Hi R users,
> > I have a question about opening the txt files and putting them into a
> > matrix. The txt files are in the folder01, while they have the name
> > file.1.txt, file.2.txt, file.3.txt, etc. There are about 200 such text
> > files. Each txt file contains one value inside. When I tried to use the
> > code below, I found that the txt files are not in order, from 1, 2, 3, to
> > 200. Rather, they are in the order 1, 10, 100, 101, etc. How to change it
> > so that they are in order? Thanks for your help.
> >
> > temp <- list.files('folder01',pattern="*.txt"
> > name.list <-lapply(paste('folder01',temp,sep='/'),read.table,head=F)
> > library(data.table)
> > files.matrix <-rbindlist(name.list)
> >
> > Also, when use the code below, how to complete it so that the values of
> the
> > files are stored in a matrix?
> > lists = list.files('folder01')
> > for (i in 1:length(lists)){
> >   file <- read.table(paste('folder01',lists[i],sep='/'),head=F)
> >   print(file)
> > }
> >
> > [[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.
>
>

[[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] ggplot2 geom_bar arrangement

2017-06-27 Thread Adams, Jean
You just have to change the levels of the factor ...

library(ggplot2)

Lab = c(letters[4:6], letters[1:3])
valuex = c(3.1,2.3,0.4,-0.4,-1.2,-4.4)
df <- data.frame(Lab,valuex)

# set the factor levels to the same order as observed in the data frame
df$Lab <- factor(df$Lab, levels=unique(df$Lab))

px <- ggplot(df,aes(Lab,valuex,label=Lab)) +
  geom_text(aes(y=0)) +
  geom_bar(stat = "identity")
px

Jean

On Tue, Jun 27, 2017 at 1:43 PM, Brian Smith  wrote:

> Hi,
>
> I was trying to draw a geom_bar plot. However, by default, the bars are
> arranged according to the label, which I don't want. I want the bars to
> appear exactly as they appear in the data frame. For example in the code:
>
>  Lab=c(letters[4:6],letters[1:3])
>  valuex = c(3.1,2.3,0.4,-0.4,-1.2,-4.4)
>  df <- data.frame(Lab,valuex)
>  px <- ggplot(df,aes(Lab,valuex,label=Lab)) + geom_text(aes(y=0)) +
> geom_bar(stat = "identity")
>  px
>
>
> The default arranges the bars in order 'a' through 'f', but I want them
> arranged as per df.
>
> How can I do this?
>
> thanks!
>
> [[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.


[R] ASA Conference on Statistical Practice - deadline Thursday

2017-06-16 Thread Adams, Jean
R Users,

Abstracts are now being accepted for the
 ASA Conference on Statistical Practice
 February 15-17, 2017
 Portland, Oregon USA

The deadline for submission is Thursday June 22.  Presentations will be 35
minutes long and fall into four broad themes:
 Communication, Collaboration, and Career Development
 Data Modeling and Analysis
 Data Science and Big Data
 Software, Programming, and Data Visualization

Abstracts may be submitted at
https://www.amstat.org/meetings/csp/2018/submitanabstract.cfm

Thank you.

Jean V. Adams
on behalf of the ASA-CSP 2018 Steering Committee


`·.,,  ><(((º>   `·.,,  ><(((º>   `·.,,  ><(((º>

Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409  USA
715-627-4317, ext. 3125  (Office)
715-216-8014  (Cell)
http://www.glsc.usgs.gov
https://www.usgs.gov/staff-profiles/jean-v-adams

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

2017-06-16 Thread Adams, Jean
You could add size = log10_P to the aes() inside geom_point().
Untested code below.
See also http://ggplot2.tidyverse.org/reference/geom_point.html

ggplot(mydata,  aes(x = X,  y = log10_P)) +
  theme_bw() +
  theme(panel.border=element_blank(), legend.position="top",
 axis.text=element_text(size = 8)) +
  geom_point(aes(color = Traits, size = log10_P))

Jean

On Fri, Jun 16, 2017 at 9:33 AM, greg holly  wrote:

> Hi all;
>
> I am running the following ggplot codes. Runs well. However, I need to
> reflect the numeric values of the log10_P to the point size in the graph.
>
> Your help highly appreciated,
>
> Regards,
> Greg
>
>
> p <- ggplot(mydata,  aes(x = X,  y = log10_P)) +
>   theme_bw() +theme(panel.border=element_blank())
>   + theme(legend.position="top",  axis.text=element_text(size = 8))
>   (p1 <- p + geom_point(aes(color = Traits)
>
> [[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] subletting an array according to dimnames

2017-06-02 Thread Adams, Jean
Have you tried P2["20", "10", "0"] ?

Jean

On Thu, Jun 1, 2017 at 3:10 PM, li li  wrote:

> Hi all,
>   I have a three dimensional array with the corresponding dimension names.
> I would like to subset the array according to the dimension names. For
> example,
> suppose I want to extract the values corresponding to A=20, B=10, C=0.  I
> know I
> can do:
>  P2[dimnames(P2)$A==20, dimnames(P2)$B==10, dimnames(P2)$C==0]
>
> But is there a better way for doing this? Thanks for your help!
>   Hanna
>
> > dimnames(P2)
>
> $A
>
> [1] "20" "25" "30" "35" "40"
>
>
> $B
>
> [1] "5"  "10" "15" "20" "25" "30" "35" "40"
>
>
> $C
>
> [1] "0"  "5" "10" "15" "20" "25" "30" "35"
>
> [[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] Beginner needs help with R

2017-02-06 Thread Adams, Jean
Try this:

seq1 <- paste("DQ0", seq(60054, 60060), sep = "")

Jean

On Sun, Feb 5, 2017 at 7:50 PM, Nabila Arbi 
wrote:

> Dear R-Help Team!
>
> I have some trouble with R. It's probably nothing big, but I can't find a
> solution.
> My problem is the following:
> I am trying to download some sequences from ncbi using the ape package.
>
> seq1 <- paste("DQ", seq(060054, 060060), sep = "")
>
> sequences <- read.GenBank(seq1,
> seq.names = seq1,
> species.names = TRUE,
> gene.names = FALSE,
> as.character = TRUE)
>
> write.dna(sequences, "mysequences.fas", format = "fasta")
>
> My problem is, that R doesn't take the whole sequence number as "060054"
> but it puts it as DQ60054 (missing the zero in the beginning, which is
> essential).
>
> Could please tell me, how I can get R to accepting the zero in the
> beginning of the accession number?
>
> Thank you very much in advance and all the best!
>
> Nabila
>
> [[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] Aggregate data to lower resolution

2017-01-19 Thread Adams, Jean
Milu,

To get the quickest help and keep everyone in the loop, you should cc the
help list.

I don't understand your question.  If you want the mean GDP use the mean
function, if you want the sum of the GDP use the sum function.

Jean

On Fri, Jan 13, 2017 at 5:33 PM, Miluji Sb  wrote:

> Dear Jean,
>
> Greetings of the new year. Hope you are doing well.
>
> I apologise for writing to you off-list but this might be a really silly
> question and I wanted to clarify without bothering everyone. Would kindly
> help me out? Hope this is not too much of a bother.
>
> My original question was regarding aggregating data to 1 degree x 1
> degree. You had kindly provided the following solution:
>
> temp$long1 <- floor(temp$longitude)
> temp$lat1 <- floor(temp$latitude)
> temp1 <- aggregate(GDP ~ long1 + lat1, temp, mean)
>
> Everything works well, my only question (and confusion) is that for
> aggregating from 0.5 degree by 0.5 degree to 1 degree by 1 degree, should
> we use sum instead of mean?
>
> temp1 <- aggregate(GDP ~ long1 + lat1, temp, sum)
>
> I really hope I'm not bothering you too much. Thanks again.
>
> Sincerely,
>
> Milu
>
> On Fri, Jul 22, 2016 at 3:06 PM, Adams, Jean  wrote:
>
>> Milu,
>>
>> Perhaps an approach like this would work.  In the example below, I
>> calculate the mean GDP for each 1 degree by 1 degree.
>>
>> temp$long1 <- floor(temp$longitude)
>> temp$lat1 <- floor(temp$latitude)
>> temp1 <- aggregate(GDP ~ long1 + lat1, temp, mean)
>>
>>   long1 lat1GDP
>> 1   -69  -55 0.90268640
>> 2   -68  -55 0.09831317
>> 3   -72  -54 0.22379000
>> 4   -71  -54 0.14067290
>> 5   -70  -54 0.00300380
>> 6   -69  -54 0.00574220
>>
>> Jean
>>
>> On Thu, Jul 21, 2016 at 3:57 PM, Miluji Sb  wrote:
>>
>>> Dear all,
>>>
>>> I have the following GDP data by latitude and longitude at 0.5 degree by
>>> 0.5 degree.
>>>
>>> temp <- dput(head(ptsDF,10))
>>> structure(list(longitude = c(-68.25, -67.75, -67.25, -68.25,
>>> -67.75, -67.25, -71.25, -70.75, -69.25, -68.75), latitude = c(-54.75,
>>> -54.75, -54.75, -54.25, -54.25, -54.25, -53.75, -53.75, -53.75,
>>> -53.75), GDP = c(1.683046, 0.3212307, 0.0486207, 0.1223268, 0.0171909,
>>> 0.0062104, 0.22379, 0.1406729, 0.0030038, 0.0057422)), .Names =
>>> c("longitude",
>>> "latitude", "GDP"), row.names = c(4L, 17L, 30L, 43L, 56L, 69L,
>>> 82L, 95L, 108L, 121L), class = "data.frame")
>>>
>>> I would like to aggregate the data 1 degree by 1 degree. I understand
>>> that
>>> the first step is to convert to raster. I have tried:
>>>
>>> rasterDF <- rasterFromXYZ(temp)
>>> r <- aggregate(rasterDF,fact=2, fun=sum)
>>>
>>> But this does not seem to work. Could anyone help me out please? Thank
>>> you
>>> in advance.
>>>
>>> Sincerely,
>>>
>>> Milu
>>>
>>> [[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/posti
>>> ng-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] Is it possible to create such graph - Which packages can come handy?

2016-12-20 Thread Adams, Jean
​You might find the code in this blog post helpful.
http://theanalyticalminds.blogspot.com/2015/03/part-3a-plotting-with-ggplot2.html

Scroll down to "Analysing the temperature by month - violin geom with
jittered points overlaid​".

This shows a series of violin plots, which is another way to display the
shape of a distribution.

Jean

On Tue, Dec 20, 2016 at 9:04 AM, Narendra Modi 
wrote:

> Hello Gurus,
> I intend to build attached reference graph in R(r.png). Could you give
> me some ideas on how it can be done, if at all possible?
>
> Basically, I would like to build a Histogram along Y axis for
> different  respective X axis ranges.
> As shown in the input.png file, there is a value of EUR for every Lw,
> a simple X-Y scatter plot.
> Now, what if I build ranges of x axis values, i.e 2000-4000,
> 4000-6000, 6000-8000 etc and analyze the histograms of Y axis values
> for those ranges?
>
> Thanks!
>
> __
> 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] how to show a plot without overlaying the text on top of the another text?

2016-12-14 Thread Adams, Jean
The ggrepel package might help.

http://blog.revolutionanalytics.com/2016/01/avoid-overlapping-labels-in-ggplot2-charts.html

Jean

On Tue, Dec 13, 2016 at 5:37 PM, Marna Wagley 
wrote:

> Hi R user,
> I have created using metaNMDS (Nonmetirc Multidimensional Scaling, MDS) to
> show species composition but some of the species are concentrated at some
> of the sites so that the name of the species are overlaid and it was
> almost impossible to read the species name in the figure. I was wondering
> how
> we can show the plot without overlaying the text on top of another.
> I used the following to create the plot. would you mind to suggest me?
>
> comm.bc.mds <- metaMDS(dat, dist = "bray")
> ordiplot(comm.bc.mds, display = "sites", type = "text")
> ordipointlabel(comm.bc.mds,font = c(1, 1), cex = c(0.5, 0.3))
>
> Thanks
>
> MW
>
> [[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] R for skip to the next row if condition met and then another condition to check

2016-12-06 Thread Adams, Jean
This might help.

# your example data
trboot3 <- structure(c(0L, -1L, -1L, -1L, -1L, -1L, -1L, -1L, 0L, 0L, -1L,
  0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L,
  1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, -1L, -1L, 0L, 1L, 0L, 0L, -1L,
  -1L, -1L, -1L, -1L, -1L, -1L, -1L, -1L, 0L, 0L, 0L, 0L, 0L, 0L,
  -1L, 0L, 0L, 0L), .Dim = c(20L, 3L), .Dimnames = list(NULL, c("V7",
  "V8", "V9")))

# function to identify first occurrence of successive values in a vector
first <- function (x) {
l <- length(x)
y <- c(1, 1 - (x[-1] == x[-l]))
y==1
}

# start with a matrix of zeroes, the same size as the original
trboot4 <- array(0, dim=dim(trboot3), dimnames=dimnames(trboot3))

# identify the first occurrence of successive values in each column
indx <- apply(trboot3, 2, first)

# replace these first occurrence cells with their original values
trboot4[indx] <- trboot3[indx]

trboot4

  V7 V8 V9
 [1,]  0  1  0
 [2,] -1  0 -1
 [3,]  0  0  0
 [4,]  0  0  0
 [5,]  0  0  0
 [6,]  0  0  0
 [7,]  0  0  0
 [8,]  0  1  0
 [9,]  0  0  0
[10,]  0  0  0
[11,] -1  0  0
[12,]  0  0  0
[13,]  0  0  0
[14,]  0  0  0
[15,]  0  0  0
[16,]  0 -1  0
[17,]  0  0 -1
[18,]  0  0  0
[19,]  0  1  0
[20,]  0  0  0

Jean

On Sun, Dec 4, 2016 at 4:08 AM, Ashwini Patil  wrote:

> I have a dataset with many rows and columns. Below is a sample:
>
> V7  V8  V90   1   0-1  1   -1-1  1   -1-1  0   -1-1  0   -1-1  0
> -1-1  0   -1-1  1   -10   1   -10   1   -1-1  0   00   0   00   0   00
>   0   00   0   00   -1  00   -1  -10   0   00   1   00   0   0
>
> This data is saved in a matrix trboot3 What I want to do is create a loop
> whereby two conditions are checked and data is altered.
>
>1. If there is a zero, skip to the next row.
>2. If there is same number one below another in a row, keep the first
>number and change the rest to zero.
>
> Here is my code for the above loop:
>
> trboot4<-trboot3
> valboot<-length(trboot3[,1])for (k in 1:length(trboot3[1,])){
>   for (i in 2:valboot-1){
> if (trboot3[k,i]==0) {i<-i+1}
> else{
>   if(trboot3[k,i] == trboot3[k,i+1]){
> for (j in i+1:valboot){ if(trboot3[k,j] ==
> trboot3[k,i]){trboot4[k,j]<-0}else{break}
>   if(j==valboot){break}
> }
>   }
> }
>   }}
>
> I want to save the new matrix in trboot4
>
> basically the above sample should become:
>
> V7  V8  V90   1   0-1  0   -10   0   00   0   00   0   00   0   00   0
>   00   1   00   0   00   0   0-1  0   00   0   00   0   00   0   00
> 0   00   -1  00   0   -10   0   00   1   00   0   0
>
>
> Thank you!
>
> [[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] barplot beside=TRUE - values differ on scales

2016-10-12 Thread Adams, Jean
Adrian,

Very interesting.

What do you think of using colors to indicate the five possible loss/gain
levels?
For example:

a <- structure(c(112L, 0L, 579L, 1L, 131L, 1L, 2234L, 2L, 2892L, 1L,
  528L, 0L, 582L, 2L), .Dim = c(2L, 7L), .Dimnames = list(c("GN",
  "CN"), c("DC5", "DC8", "DC14", "DC18", "DC19", "DC20", "DC23"
  )))

loss.gain <- c(-2, -1, 0, 1, 2)
colorz <- c("blue", "lightblue", "gray", "orange", "red")
barplot(a["GN", ], col=colorz[match(a["CN", ], loss.gain)])

Jean

On Wed, Oct 12, 2016 at 11:55 AM, Adrian Johnson 
wrote:

> Hi Adams,
> The story I am trying to show visually relationship between GN and CN
> for every column. Each column represents a patient. In each patient, a
> particular chromosome region (CN) is either lost (-2 or -1) or gained
> (1 or 2). Typically if loss (one copy loss - as humans have pair of
> chromosome) or homozygous (two copies loss) theoretically indicate
> decrease in number of copies of gene located in that region of
> chromosome. The number of copies of a gene located in that chromosomal
> regions are indicated by GN.
> through this barplot, I intend to show that in 7 cases (columns) if a
> relationship exist by plotting GN and CN next to each other.  If I log
> values in GN, I am loosing the minor differences between cases in GN.
> hope I could convince/explain.
> thanks
> adrian
>
> On Wed, Oct 12, 2016 at 12:36 PM, Adams, Jean  wrote:
> > Adrian,
> >
> > What story are you trying to tell?  Or what question are you trying to
> > answer by visualizing these data?  How is a bar plot of these numbers
> going
> > to help?  I'm just wondering if perhaps a different visualization might
> make
> > more sense, for example, a scatter plot of GN vs. CN.
> >
> > m <- structure(c(112L, 0L, 579L, 1L, 131L, 1L, 2234L, 2L, 2892L, 1L,
> >   528L, 0L, 582L, 2L), .Dim = c(2L, 7L), .Dimnames = list(c("GN",
> >   "CN"), c("DC5", "DC8", "DC14", "DC18", "DC19", "DC20", "DC23"
> >   )))
> > plot(m["GN", ], m["CN", ])
> >
> > Jean
> >
> >
> > On Wed, Oct 12, 2016 at 11:20 AM, Adrian Johnson <
> oriolebaltim...@gmail.com>
> > wrote:
> >>
> >> Dear group,
> >> I have been struggling to barplot two different measurements from one
> >> subject. These two measures differ in range.  I want to plot row 1
> >> axis on left side and row 2 values on right side.
> >>
> >> For a given column I want to plot GN and CN next to each other.
> >>
> >> my dput code is below
> >> :
> >>
> >> structure(c(112L, 0L, 579L, 1L, 131L, 1L, 2234L, 2L, 2892L, 1L,
> >> 528L, 0L, 582L, 2L), .Dim = c(2L, 7L), .Dimnames = list(c("GN",
> >> "CN"), c("DC5", "DC8", "DC14", "DC18", "DC19", "DC20", "DC23"
> >> )))
> >>
> >>
> >> As you can see:
> >>DC5 DC8 DC14 DC18 DC19 DC20 DC23
> >> GN 112 579  131 2234 2892  528  582
> >> CN   0   112102
> >>
> >> GN values are range from 100 - 3000
> >> while CN are always -2 or -1 or 0 or 1 or 2
> >>
> >> Also I cannot log GN values and plot because a difference in 100 units
> >> also matters in my experiment.
> >>
> >> Any help would be greatly appreciated.
> >>
> >> Thanks
> >> Adrian
> >>
> >> __
> >> 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] barplot beside=TRUE - values differ on scales

2016-10-12 Thread Adams, Jean
Adrian,

What story are you trying to tell?  Or what question are you trying to
answer by visualizing these data?  How is a bar plot of these numbers going
to help?  I'm just wondering if perhaps a different visualization might
make more sense, for example, a scatter plot of GN vs. CN.

m <- structure(c(112L, 0L, 579L, 1L, 131L, 1L, 2234L, 2L, 2892L, 1L,
  528L, 0L, 582L, 2L), .Dim = c(2L, 7L), .Dimnames = list(c("GN",
  "CN"), c("DC5", "DC8", "DC14", "DC18", "DC19", "DC20", "DC23"
  )))
plot(m["GN", ], m["CN", ])

Jean


On Wed, Oct 12, 2016 at 11:20 AM, Adrian Johnson 
wrote:

> Dear group,
> I have been struggling to barplot two different measurements from one
> subject. These two measures differ in range.  I want to plot row 1
> axis on left side and row 2 values on right side.
>
> For a given column I want to plot GN and CN next to each other.
>
> my dput code is below
> :
>
> structure(c(112L, 0L, 579L, 1L, 131L, 1L, 2234L, 2L, 2892L, 1L,
> 528L, 0L, 582L, 2L), .Dim = c(2L, 7L), .Dimnames = list(c("GN",
> "CN"), c("DC5", "DC8", "DC14", "DC18", "DC19", "DC20", "DC23"
> )))
>
>
> As you can see:
>DC5 DC8 DC14 DC18 DC19 DC20 DC23
> GN 112 579  131 2234 2892  528  582
> CN   0   112102
>
> GN values are range from 100 - 3000
> while CN are always -2 or -1 or 0 or 1 or 2
>
> Also I cannot log GN values and plot because a difference in 100 units
> also matters in my experiment.
>
> Any help would be greatly appreciated.
>
> Thanks
> Adrian
>
> __
> 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] Trouble with parameter estimation in nonlinear regression model

2016-10-04 Thread Adams, Jean
Syela,

If you want to constrain parameter "a" to be positive, you can rewrite the
equation replacing "a" with "exp(theta)".  Then when you get the estimate
for "theta", simply convert it back to "a".

Jean

On Mon, Oct 3, 2016 at 12:23 PM, Syela Mohd Noor 
wrote:

> Hi all, I had a problem with the parameter estimation of the Brass Gompertz
> model for my dissertation. I run the code for several times based on
> different years and it was fine until the seventh year onward where I got
> negative values for the parameter (a) which did not make sense since it
> represents the total fertility rate of a country.
> This is my code :
>
> gom.eq=function(a, b, c)
>
> {
>
> age=c(17.5, 22.5, 27.5, 32.5, 37.5, 42.5 , 47.5)
>
> k=(-(age-14)/b)
>
> (a*((c/b)*(exp((k)-(c*(exp(k)))
>
> }
>
>
>
> varlist=list(
> ASFR$Y1960,ASFR$Y1965,ASFR$Y1970,ASFR$Y1975,ASFR$Y1980,ASFR$Y1985,
>
> ASFR$Y1990,ASFR$Y1995,ASFR$Y2000,ASFR$Y2005,ASFR$Y2010,ASFR$Y2013)
>
>
>
> gom.models=lapply(varlist, function(varlist)
>
> {
>
> nlsLM(varlist~gom.eq(a,b,c),data=ASFR,start=list(a=1 , b=1, c=1),trace=T)
>
> })
>
> summary(gom.models)
>
>
>
> gom.models[1:12]
>
>
>
>
> Any idea to solve the problem?
>
>
> Regards,
>
> Syela M.N.
>
> [[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] Run a fixed effect regression and a logit regression on a national survey that need to be "weighted"

2016-09-20 Thread Adams, Jean
If you want your records to be weighted by the survey weights during the
analysis, then use the weights= argument of the glm() function.

Jean

On Tue, Sep 20, 2016 at 5:04 AM, laura roncaglia 
wrote:

> I am a beginner user of R. I am using a national survey to test what
> variables influence the partecipation in complementary pensions (the
> partecipation in complementary pension is voluntary in my country).
>
> Since the dependent variable is a dummy (1 if the person partecipate and 0
> otherwise) I want to run a logit or probit regression; moreover I want to
> run a fixed effect regression since I subset the survey in order to have
> only the individuals interviewed more than one time.
>
> The data frame is composed by several social and economical variables and
> it also contain a variable "weight" which is the survey weight (they are
> weighting coefficients to adjust the results of the sample to the national
> data).
>
>  family pers sex income pension1 101   F  1   12
> 201   F  2   13 202   M  4   04 30
> 1   M  25000   05 302   F  5   06 401   M
> 6   1
>
> pers is the component of the family and pension takes 1 if the person
> partecipate to complementary pension (it is a semplification of the
> original survey, which contains more variables and observation (aroun 22k
> observations)).
>
> I know how to use the plm and glm functions for a fixed effect or logit
> regressoin; in this case I don't know what to do since I need to take
> account of the survey weights.
>
> I used the svydesing function to "weight" the data frame:
>
> df1 <- svydesign(ids=~1, data=df, weights=~dfweight)
>
> I used ids=~1 because there isn't a "cluster" variable in the survey (I
> know that the towns are ramdomly selected and then individuals are ramdomly
> selected, but there isn't a variable that indicate the stratification).
>
> At this point I am lost: I don't know if it is right to use the survey
> package and then what function use to run the regression, or there is a way
> to use the plm or glm functions taking account of the weights.
>
> I tried so hard to search a solution on the website but if you could give
> me an answer I'd be glad.
>
> [[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] Using apply on a three dimensional matrix and passing multiple arguments to user defined function

2016-09-07 Thread Adams, Jean
Justin,

I don't think you can get the apply() function to return an array.  You
could use lapply() instead, and then use simplify2array() to convert the
list of matrices to an array.  Also, in your mask() function you don't need
the which() and you should return the x.  See my example with toy data
below.

# toy data
nlon <- 2
nlat <- 4
ntime <- 3
data <- array(1:(nlon*nlat*ntime), dim=c(nlon, nlat, ntime))
lsmask <- array(sample(0:1, size=nlon*nlat, replace=TRUE), dim=c(nlon,
nlat))

# newly defined function
mask <- function(x, y) {
  x[y==0] <- NA
  x
}

# doit
data2 <- simplify2array(lapply(1:ntime, function(i) mask(data[, , i],
lsmask)))


You may prefer to stick with the for() loop approach (for clarity or
simplicity or ...)  When I ramped up the toy data to much larger
dimensions, the lapply() approach was only slightly faster than the for()
loop approach on my PC.

data3 <- data
data3[ , , i] <- mask(data3[ , , i], lsmask)

Jean




On Tue, Sep 6, 2016 at 11:33 PM, Justin Peter 
wrote:

> Dear R-user,
>
> I have a three-dimensional matrix of atmospheric data. The first two
> dimensions are spatial (lon and lat) and the third is time, such that
>
> dim(data) <- c(nlon,nlat,ntime)
>
> I wish to apply a land sea mask data which is a matrix of "0" and "1" if
> dim(nlon,nlat)
>
> dim(lsmask) <- c(nlon,nlat)
>
> I wish to set all of the elements in the two-dimensional array of
> data[,,ntime] for every 1:length(ntime).
>
> I could do this in a loop:
>
> for (i in 1:ntime){
> data[,,i][which(lsmask == 0)] <- NA
> }
>
> I would like to do this using apply, but I need to pass two variables to
> the function in apply (data and lsmask), where data is a two-dimensional
> array.
>
> I tried:
>
> mask <- function(x,y) {x[which(y==0)] <- NA}
>
> masked_data <- apply(data,c(1,2),mask,y=lsmask)
>
> but I get back a vector of dim(nlon,nlat) populated with NA.
>
> Any clues as to what I am missing?
>
> Thanks in advance for you help.
>
> Kind regards,
> Justin
>
>
>
> --
> Justin Peter
> Research Fellow
> International Centre for Applied Climate Sciences,
> University of Southern Queensland
> West St, Toowoomba, QLD, 4350
> Australia
>
> Email: justin.pe...@usq.edu.au
> Ph: +61 (0) 7 4631 1181
> Fax: +61 (0) 7 4631 5581
> Mob: +61 (0)474 774 107
>
>
>
>
> _
> This email (including any attached files) is confidential and is for the
> intended recipient(s) only. If you received this email by mistake, please,
> as a courtesy, tell the sender, then delete this email.
>
> The views and opinions are the originator's and do not necessarily reflect
> those of the University of Southern Queensland. Although all reasonable
> precautions were taken to ensure that this email contained no viruses at
> the time it was sent we accept no liability for any losses arising from its
> receipt.
>
> The University of Southern Queensland is a registered provider of
> education with the Australian Government.
> (CRICOS Institution Code QLD 00244B / NSW 02225M, TEQSA PRV12081 )
>
>
> [[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] Adding multiple polygons to a Leaflet map

2016-09-01 Thread Adams, Jean
It is hard to troubleshoot without the data.  Can you provide the data, for
example using the dput() function, or can you replicate the issue with some
simplified version of code that we can run?

Jean

On Tue, Aug 30, 2016 at 11:26 AM, Kevin Haynes  wrote:

> Hi everyone - I'd like to add multiple polygons to a leaflet map. I don't
> get any errors when running this code, but it'll only display the second
> choro layer - the citizenship rate one. Here's my code below. Any thoughts?
> Here's the map right now:http://rpubs.com/khaynes17/205217
>   #map
>
>   la_trad_school_perf_map_layers <- leaflet(lac_schools) %>%
> addProviderTiles("CartoDB.Positron") %>%
> setView(-118.4, 34.05, zoom = 9) %>%
> addCircleMarkers(
>   radius = 3,
>   color = ~pal(metandabove_mth),
>   stroke= FALSE, fillOpacity = 0.5,
>   group="14-15 Proficiency Rates - Math"
> ) %>%
> addPolygons(data = income_merged,
>   fillColor = ~pal_income(MedianIncome_2014),
>   color = "#b2aeae",
>   fillOpacity = 0.5,
>   weight = 1,
>   smoothFactor = 0.2,
>   popup = popup_income,
>   group="Median Income - 2014")%>%
> addPolygons(data = cit_merged,
>   fillColor = ~pal_cit(non_citizenship_rate),
>   color = "#b2aeae",
>   fillOpacity = 0.5,
>   weight = 1,
>   smoothFactor = 0.2,
>   popup = popup_cit,
>   group="Non-U.S. Citizen - 2014")%>%
>addLayersControl(
>  baseGroups=c("Median Income - 2014", "Non-U.S. Citizen - 2014"),
>  overlayGroups=c("14-15 Proficiency Rates - Math"),
>  options = layersControlOptions(collapsed = FALSE)
>)
>   la_trad_school_perf_map_layers
>
> [[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] Improving function that estimates regressions for all variables specified

2016-09-01 Thread Adams, Jean
You may be able find someone else's function that already does you want.
For example the dredge() function of the MuMIn package.

http://rpackages.ianhowson.com/cran/MuMIn/man/MuMIn-package.html

Jean

On Fri, Aug 26, 2016 at 1:11 PM, Jorge Cimentada 
wrote:

> Hi, I'd like some feedback on how to make this function more "quicker and
> parsimonious".
>
> I normally run several regressions like this:
> y ~ x1
> y ~ x1 + x2
> y ~ x1 + x2 +xn
>
> Instead, I created a function in which I specify y, x1 and x2 and the
> function automatically generates:
> y ~ x1
> y ~ x1 + x2
> y ~ x1 + x2 +xn
>
> This is the function:
>
> models <- function(dv, covariates, data) {
> dv <- paste(dv, "~ 1")
> combinations <- lapply(1:length(covariates), function(i) seq(1:i))
> formulas <- lapply(combinations, function(p) x <-
> as.formula(paste(c(dv, covariates[p]), collapse=" + ")))
> results <- lapply(formulas, function(o) lm(o, data=data))
> return(results)
> }
>
> And an example:
> models("mpg",c("cyl","disp","hp","am"), mtcars)
>
> I'm concerned about the time that it takes when using other regression
> models, such as those with the survey package(I know these models are heavy
> and take time) but I'm sure that the function has room for improvement.
>
> I'd also like to specify the variables as a formula. I managed to do it but
> I get different results when using things like scale() for predictors.
>
> Formula version of the function:
> models2 <- function(formula, data) {
> dv <- paste(all.vars(formula)[1], " ~ 1")
> covariates <- all.vars(formula)[-1]
> combinations <- lapply(1:length(covariates), function(i) seq(1:i))
> lfo <- lapply(combinations, function(p) x <- as.formula(paste(c(dv,
> covariates[p]), collapse=" + ")))
> results <- lapply(lfo, function(o) lm(o, data=data))
> return(results)
> }
>
> models("mpg",c("cyl","scale(disp)"), mtcars)
>
> models2(mpg ~ cyl + scale(disp), mtcars)
>
> See the difference between the disp variables?
>
> Any feedback is appreciated!
>
>
> *Jorge Cimentada*
> *Ph.D. Candidate*
> Dpt. Ciències Polítiques i Socials
> Ramon Trias Fargas, 25-27 | 08005 Barcelona
>
> Office 24.331
> [Tel.] 697 382 009www.jorgecimentada.com
>
> [[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] loop function

2016-08-18 Thread Adams, Jean
You seemed to have re-written over the "b" object in your code.
This might work for you.

library(MASS)
for (i in 58:1){
  for(j in 58:i){
str.temp <- paste("y1 ~ x", i, "* x", j, sep = "")
univar <- glm.nb(as.formula(str.temp), data=df)
b <- summary(univar)$coeffients[4, 4]
if(b < 0.6){
  cat(i, j, b, "\n")
}
  }
}

By the way, you should post using plain text (not html).

Jean


On Thu, Aug 18, 2016 at 6:48 AM, fatimah soleimany <
fatimah.soleim...@gmail.com> wrote:

> Hi Dear users,
> for an interactive use, i am trying to write a loop that looks for all
> variables in the conditions which i introduced, this is what I'm trying:
>
> library(MASS)> i=1> for (i in 58:1){+ for(j in 58:i){+ + str.temp <-
> paste("y1 ~ x", i, "* x", j, sep = "")+
> univar<-glm.nb(as.formula(str.temp), data=df)+
> b=summary(univar)$coeffients[4,4]+ b<-c(i,j)+ if(b < 0.6){ +
> print(b)+}+   }+   }
>
> i have no error but i didn't get true response too, my result is this:
>
>
> b[1] 1 1
>
>  but i want all the variables that their p-value are less than 0.6, i
> think i couldn't write a true loop,can you help me?
>
> thank you in advance for any help
>
> [[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] Extracting dates to create a new variable

2016-08-10 Thread Adams, Jean
Try this.

dfsub <- df[df$deps %in% c("CC", "DD", "FF"), ]
names(dfsub) <- c("Subject", "newdate", "origdep")
final <- merge(df, dfsub)

Jean

On Wed, Aug 10, 2016 at 10:58 AM, Farnoosh Sheikhi via R-help <
r-help@r-project.org> wrote:

>  blockquote, div.yahoo_quoted { margin-left: 0 !important; border-left:1px
> #715FFA solid !important; padding-left:1ex !important;
> background-color:white !important; }
>
> Hi
> I have a data set like below and wanted to create a new date variable by
> extracting the dates for specific departments.I want to extract the dates
> for departments CC, DD, FF,  put it in a new column and repeat it for other
> unique IDs.
> Subject<- c("2", "2", "2", "3", "3", "3", "4", "4", "5", "5", "5",
> "5")dates<-seq(as.Date('2011-01-01'),as.Date('2011-01-12'),by =
> 1) deps<-c("A", "B", "CC", "C", "CC", "A", "F", "DD", "A", "F", "FF",
> "D")df <- data.frame(Subject, dates, deps)df
> The final data set should look like this:newdate<-c(" 2011-01-03",
>  "2011-01-03",  "2011-01-03", "2011-01-05", "2011-01-05", "2011-01-05" ,
> "2011-01-08", "2011-01-08", "2011-01-08", "2011-01-11", "2011-01-11",
> "2011-01-11")final<-data.frame(Subject, dates, deps, newdate)final
> I really appreciate any help.
>  Best,Farnoosh
>
>
>
>
>
> [[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] Aggregate data to lower resolution

2016-07-22 Thread Adams, Jean
Milu,

Perhaps an approach like this would work.  In the example below, I
calculate the mean GDP for each 1 degree by 1 degree.

temp$long1 <- floor(temp$longitude)
temp$lat1 <- floor(temp$latitude)
temp1 <- aggregate(GDP ~ long1 + lat1, temp, mean)

  long1 lat1GDP
1   -69  -55 0.90268640
2   -68  -55 0.09831317
3   -72  -54 0.22379000
4   -71  -54 0.14067290
5   -70  -54 0.00300380
6   -69  -54 0.00574220

Jean

On Thu, Jul 21, 2016 at 3:57 PM, Miluji Sb  wrote:

> Dear all,
>
> I have the following GDP data by latitude and longitude at 0.5 degree by
> 0.5 degree.
>
> temp <- dput(head(ptsDF,10))
> structure(list(longitude = c(-68.25, -67.75, -67.25, -68.25,
> -67.75, -67.25, -71.25, -70.75, -69.25, -68.75), latitude = c(-54.75,
> -54.75, -54.75, -54.25, -54.25, -54.25, -53.75, -53.75, -53.75,
> -53.75), GDP = c(1.683046, 0.3212307, 0.0486207, 0.1223268, 0.0171909,
> 0.0062104, 0.22379, 0.1406729, 0.0030038, 0.0057422)), .Names =
> c("longitude",
> "latitude", "GDP"), row.names = c(4L, 17L, 30L, 43L, 56L, 69L,
> 82L, 95L, 108L, 121L), class = "data.frame")
>
> I would like to aggregate the data 1 degree by 1 degree. I understand that
> the first step is to convert to raster. I have tried:
>
> rasterDF <- rasterFromXYZ(temp)
> r <- aggregate(rasterDF,fact=2, fun=sum)
>
> But this does not seem to work. Could anyone help me out please? Thank you
> in advance.
>
> Sincerely,
>
> Milu
>
> [[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] multiple-line plot

2016-07-20 Thread Adams, Jean
Use the dput() function to share a subset of your data with the list
(attachments are not supported).

For example, submit this command
 dput(for_jhon[1:20, ])
and post the result to the list along with your question.

Jean

On Tue, Jul 19, 2016 at 1:24 PM, John Wasige  wrote:

> ​Dear all,
>
> This is to kindly request for your help. I would like to plot my data.
>
> The R script below gives some plot that is not clear. How can I get a clear
> multiple-line plot. The data is attached herewith.
>
> ##R Script
> for_jhon = read.csv("C:/LVM_share/for_ jhon.csv", header=TRUE, sep=";")
> matplot(for_jhon$ID, cbind(for_jhon[,2:73]))​
>
> Thanks for your help
>
> John
> __
> 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] Forking and adapting an R package

2016-07-13 Thread Adams, Jean
Timo,

A couple of thoughts ...

First, could you achieve what you want by simply modifying (your own copies
of) a function or two from the hexbin package, without having to modify the
entire package?  This might give you fewer tripping points.

Second, right after you forked the package (so that you have a copy on your
own space on GitHub) and before you modified anything ... were you able to
install and use the package from there successfully?

library("devtools")
devtools::install_github("grssnbchr/hexbin")
library(hexbin)


Jean

On Tue, Jul 12, 2016 at 6:28 AM,  wrote:

> Hello.
>
> I'm trying to adapt the package “hexbin” to suit my needs. This is the
> first
> time I do this. I've read a bit through Hadley's “R packages”, but now I'm
> pretty lost (from a workflow point of view). I am using RStudio and
> Hadley's
> devtools.
>
> So I forked the repo I want to adapt: https://github.com/grssnbchr/hexbin
> and
> cloned it using RStudio (I created a new project). What I basically want
> to do
> is adapt the package slightly and use the adapted source on my use case
> (an Rmd
> file in another location) - ideally, I would call the respective function
> (hexbin::grid.hexagons) in the Rmd and the source code of “hexbin” would be
> called and debugged (just for understanding what the package “hexbin”
> actually
> does in that case, I do not have to build it yet, or even publish it).
> What is
> the workflow for this?
>
> Also, I tried running devtools::check() and it already fails there:
> R version 3.2.5 (2016-04-14) -- "Very, Very Secure Dishes"
>
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> > devtools::check()
> Updating hexbin documentation
> Loading hexbin
> Creating a generic function for ‘plot’ from package ‘graphics’ in package
> ‘hexbin’
> Creating a generic function for ‘summary’ from package ‘base’ in package
> ‘hexbin’
> Setting env vars
>
> ---
> CFLAGS : -Wall -pedantic
> CXXFLAGS: -Wall -pedantic
> Building hexbin
>
> 
> '/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore
> --quiet
> CMD build '/home/tgrossen/R/hexbin' --no-resave-data --no-manual
>
> * checking for file ‘/home/tgrossen/R/hexbin/DESCRIPTION’ ... OK
> * preparing ‘hexbin’:
> * checking DESCRIPTION meta-information ... OK
> * cleaning src
> * installing the package to build vignettes
> * creating vignettes ... ERROR
>
> Error: processing vignette 'hexagon_binning.Rnw' failed with diagnostics:
>  chunk 1 (label = comphexsq)
> Error in eval(expr, envir, enclos) : could not find function “hexbin”
> Execution halted
> Error: Command failed (1)
>
> As you can see, I am very much lost. I googled for "adapt R package and
> debug"
> and so forth but couldn't find any tutorial or anything.
>
> Thanks,
>
> Timo
>
> __
> 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] ASA Conference on Statistical Practice - deadline Thursday

2016-06-20 Thread Adams, Jean
R users,

Abstracts are now being accepted for the
 ASA Conference on Statistical Practice
 February 23-25, 2017
 Jacksonville FL, USA

Past conference attendees have shown particular interest in R,
reproducibility, and data visualization.

The deadline for submission is June 23.  Presentations will be 35 minutes
long and fall into four broad themes:
 Communication, Collaboration, and Career Development
 Data Modeling and Analysis
 Big Data and Data Science
 Software, Programming, and Graphics

Abstracts may be submitted at
 http://www.amstat.org/meetings/csp/2017/submitabstract.cfm

Thank you.

Jean V. Adams
on behalf of the ASA-CSP 2017 Steering Committee



`·.,,  ><(((º>   `·.,,  ><(((º>   `·.,,  ><(((º>

Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409  USA
http://www.glsc.usgs.gov
http://profile.usgs.gov/jvadams

[[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] Filtering String Variables

2016-05-23 Thread Adams, Jean
George,

You are very close.  Try this ...

# make Debitor a character variable in the data frame
ds_example$Debitor <- as.character(ds_example$Debitor)

duplicates <- duplicated(ds_example$Debitor)
duplicated_debitors <- unique(ds_example$Debitor[duplicates])
ds_duplicates <- ds_example[ds_example$Debitor %in% duplicated_debitors, ]

Jean

On Mon, May 23, 2016 at 8:28 AM,  wrote:

> # Hi All,
> #
> # I have the following data frame (example):
>
> Debitor <- c("968691", "968691", "968691",
>  "A04046", "A04046",
>  "L0006", "L0006", "L0006",
>  "L0023", "L0023",
>  "L0056", "L0056",
>  "L0094", "L0094", "L0094",
>  "L0124", "L0124",
>  "L0143",
>  "L0170",
>  "13459",
>  "473908",
>  "394704",
>  "4711",
>  "4712",
>  "4713")
> Debitor <- as.character(Debitor)
> var1 <- c(11, 12, 13,
>   14, 14,
>   12, 13, 14,
>   10, 11,
>   12, 12,
>   12, 12, 12,
>   15, 17,
>   11,
>   14,
>   12,
>   17,
>   13,
>   15,
>   16,
>   11)
> ds_example <- data.frame(Debitor, var1)
> ds_example$case_id <- 1:nrow(ds_example)
> ds_example <- ds_example[, sort(colnames(ds_example))]
> ds_example
>
> # I would like to generate a data frame that contains the duplicates AND
> the
> # corresponding non-duplicates to the duplicates.
> # For example, finding the duplicates with deliver case 2 and 3 but the
> list
> # should also contain case 1 because case 1 is the corresponding case to
> the
> # duplicate cases 2 and 3.
> # For the whole example dataset that would be:
> needed <- c(1, 1, 1,
> 1, 1,
> 1, 1, 1,
> 1, 1,
> 1, 1,
> 1, 1, 1,
> 1, 1,
> 0, 0, 0, 0, 0, 0, 0, 0)
> needed <- as.logical(needed)
> ds_example <- data.frame(ds_example, needed)
> ds_example
>
> # To find the duplicates and the corresponding non-duplicates
> duplicates <- duplicated(ds_example$Debitor)
>
> list_of_duplicated_debitors <- as.character(ds_example[duplicates,
> "Debitor"])
>
> filter_variable <- unique(list_of_duplicated_debitors)
>
> ds_duplicates <- ds_example["Debitor" == filter_variable]  # Result:
> dataset with 0 columns
>
> ds_duplicates <- ds_example["Debitor"] %in% filter_variable  # Result:
> FALSE
>
> # How can I create a dataset like this
>
> ds_example <- ds_example[needed, ]
> ds_example
>
> # using the Debitor IDs?
>
> Kind regards
>
> Georg Maubach
>
> __
> 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] subset by multiple letters condition

2016-04-23 Thread Adams, Jean
This is quite a different question.  I suggest you start a new post with a
new subject line for this.  And I suggest you include code for an example
plot that you want to use.

Otherwise, you might look here for some ideas on how to control colors in a
scatter plot using base r, http://stackoverflow.com/a/8475315

Jean

On Sat, Apr 23, 2016 at 11:09 AM,  wrote:

> Thanks Jean, Does anyone know how to set these [hast1] and [hast2] as the
> colors of a plot?
>
>
> On Friday, April 22, 2016 7:39 AM, "Adams, Jean"  wrote:
>
>
>
> You can use the grepl() function to give you logicals for each criterion,
> then combine them as needed.  For example:
>
> # example version of Command
> Command <- paste0("_localize_", c("PD","t2","t1_seq", "abc", "xyz",
> "PD_t1"))
>
> hasPD <- grepl("PD", Command, fixed=TRUE)
> hast1 <- grepl("t1", Command, fixed=TRUE)
> hast2 <- grepl("t2", Command, fixed=TRUE)
>
> > Command[hast1]
> [1] "_localize_t1_seq" "_localize_PD_t1"
>
> > Command[hasPD]
> [1] "_localize_PD""_localize_PD_t1"
>
> > Command[hast1 & hasPD]
> [1] "_localize_PD_t1"
>
> Jean
>
>
> On Fri, Apr 22, 2016 at 8:42 AM, ch.elahe via R-help 
> wrote:
>
>
> >Hi all,
> >
> >I have a data frame df and I want to do subset based on several
> conditions of letters of the names in Command.1)if the names contain PD
> 2)if the names contain t1 3)if the names contain t2 4)if the names contain
> t1 and PD 5)if the names contain t2 and PD 6)otherwise the names would be
> unknown. I don't know how to use grep for all these conditions.
> >
> >   'data.frame': 36919 obs. of 162 variables
> >   $TE:int 38,41,11,52,48,75,.
> >   $Command   :factor W/2229 levels
> "_localize_PD","_localize_tre_t2","_localize_t1_seq",...
> >
> >
> >Thanks for any help
> >
> >__
> >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] subset by multiple letters condition

2016-04-22 Thread Adams, Jean
You can use the grepl() function to give you logicals for each criterion,
then combine them as needed.  For example:

# example version of Command
Command <- paste0("_localize_", c("PD","t2","t1_seq", "abc", "xyz",
"PD_t1"))

hasPD <- grepl("PD", Command, fixed=TRUE)
hast1 <- grepl("t1", Command, fixed=TRUE)
hast2 <- grepl("t2", Command, fixed=TRUE)

> Command[hast1]
[1] "_localize_t1_seq" "_localize_PD_t1"

> Command[hasPD]
[1] "_localize_PD""_localize_PD_t1"

> Command[hast1 & hasPD]
[1] "_localize_PD_t1"

Jean

On Fri, Apr 22, 2016 at 8:42 AM, ch.elahe via R-help 
wrote:

>
> Hi all,
>
> I have a data frame df and I want to do subset based on several conditions
> of letters of the names in Command.1)if the names contain PD 2)if the names
> contain t1 3)if the names contain t2 4)if the names contain t1 and PD 5)if
> the names contain t2 and PD 6)otherwise the names would be unknown. I don't
> know how to use grep for all these conditions.
>
>'data.frame': 36919 obs. of 162 variables
>$TE:int 38,41,11,52,48,75,.
>$Command   :factor W/2229 levels
> "_localize_PD","_localize_tre_t2","_localize_t1_seq",...
>
>
> Thanks for any help
>
> __
> 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] New member

2016-04-14 Thread Adams, Jean
This is a good place to start ...
https://cran.r-project.org/doc/manuals/R-intro.pdf

Jean

On Thu, Apr 14, 2016 at 5:39 AM, kipkorirfrankli...@gmail.com <
kipkorirfrankli...@gmail.com> wrote:

>
> Hello. I am Franklin from University of Eldoret. I really want to study
> the R package. What should I first of all do?
> [[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] Storing output of loop into list()

2016-04-07 Thread Adams, Jean
You don't need a for loop for the first part.  You can do it like this:

Notice that I used unchanging data for the temps vector so that you could
tell us what output you expect to see, in case what I provide is not
adequate.

temps <- c(13.988, 13.932, 14.039, 14.082, 13.998, 13.93, 14.028, 14.015,
  14.06, 14.092, 14.089, 13.971, 14.062, 14.001, 13.959, 14.046,
  14.034, 14.089, 13.991, 13.982, 14.038, 14.001, 13.973, 13.966,
  13.995, 13.934, 14.101, 14.087, 14.064, 14.06, 14.027, 13.996,
  14.037, 14.024, 14.032, 14.052, 13.986, 14.021, 13.988, 13.98,
  13.968, 13.959, 14.055, 13.978, 14.105, 14.005, 13.996, 14.027,
  13.99, 13.966, 14.047, 13.903, 13.953, 14.02, 13.969, 14.051,
  14.027, 14.03, 14.078, 13.988, 14.007, 13.899, 14.023, 13.991,
  13.993, 13.973, 14.035, 14.091, 14.033, 13.943, 14.08, 14, 14.015,
  14.042, 13.993, 14.064, 14.039, 13.939, 13.95, 14.017, 13.984,
  14.075, 14.006, 14.029, 14.004, 13.974, 14.003, 14.073, 13.991,
  13.973, 14.029, 14.02, 14.032, 14.036, 14.021, 13.983, 13.981,
  13.977, 13.94, 14.014)

tempdif9 <- -diff(temps, lag=9)
L <- length(tempdif9)
sel <- tempdif9[-L] >= 0.1 & tempdif9[-1] > -0.05
ttind <- cbind(tempdif9, index=1:L)[sel, ]
ttind

 tempdif9 index
[1,]0.10110
[2,]0.10017
[3,]0.10128
[4,]0.15243

I'm not sure what you are trying to achieve with the second part.  I
suspect that what you really wanted is to see the temperatures that
contributed to the output in ttind.  If that's the case, then perhaps this
will help.

contrib <- t(sapply(ttind[, "index"], function(i) temps[i + 0:8]))
contrib

   [,1]   [,2]   [,3]   [,4]   [,5]   [,6]   [,7]   [,8]   [,9]
[1,] 14.092 14.089 13.971 14.062 14.001 13.959 14.046 14.034 14.089
[2,] 14.034 14.089 13.991 13.982 14.038 14.001 13.973 13.966 13.995
[3,] 14.087 14.064 14.060 14.027 13.996 14.037 14.024 14.032 14.052
[4,] 14.055 13.978 14.105 14.005 13.996 14.027 13.990 13.966 14.047

Jean


On Thu, Apr 7, 2016 at 11:09 AM,  wrote:

> Hello. I am trying to store the output from a loop into a matrix. Failed
> so far, thanks for the help.
>
> What I want to store into a new matrix: (just run the code once):
>
> temps<-rnorm(400,14,0.05)
> ttind<-NULL
> for(ti in 1:(length(temps)-9)) {
>   if(temps[ti]-temps[ti+9] >= 0.1 && max(temps[ti]-temps[ti+1:9]) > -0.05)
> ttind<-c(ttind,ti)
> }
> for(ti in 1:length(ttind)) {
>
>  print(round(temps[ttind[ti]:(ttind[ti]+9)],3))
>
>   }
>
>
>
>
>
>
>
> My (failed) soultion attempt:
>
> temps<-rnorm(400,14,0.05)
> ttind<-NULL
> for(ti in 1:(length(temps)-9)) {
>   if(temps[ti]-temps[ti+9] >= 0.1 && max(temps[ti]-temps[ti+1:9]) > -0.05)
> ttind<-c(ttind,ti)
> }
>
> outputList = list()
> counter = 1
>
> for(ti in 1:length(ttind)) {
>
>   outputList[i] <-  print(round(temps[ttind[ti]:(ttind[ti]+9)],3))
> counter= counter+1
>   }
>
> print(outputList)
>
>
> [[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] before-after control-impact analysis with R

2016-04-04 Thread Adams, Jean
I searched for
 analyze BACI data in R
and found a couple things that you might find helpful.

http://people.stat.sfu.ca/~cschwarz/Stat-650/Notes/MyPrograms/BACI/BACITalk-2012-10-15-UBC/baci.pdf
http://people.stat.sfu.ca/~cschwarz/Stat-650/Notes/PDFbigbook-R/R-part013.pdf

Jean

On Sun, Apr 3, 2016 at 1:24 AM, MAHFUZATUL IZYAN 
wrote:

> Hi! I’m Zatul from Malaysia. I’m currently doing simple task on BACI
> approach in ecology study. I’m a newbie in ecology study. Perhaps, I can
> get link and some idea regarding how to analyse BACI data. Tq.
>
>
>
>
>
> Regards.
>
>
> Sent from Windows Mail
> [[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] How to form groups for this specific problem?

2016-03-29 Thread Adams, Jean
You're welcome, Satish.

Yes, questions that are seeking solutions in R code are appropriate for
this group.  It's helpful if you provide sample data (for example, using
dput()) and sample R code that folks can use.  And it's helpful if you show
the results that you are hoping to achieve (as you did).

Jean

On Mon, Mar 28, 2016 at 1:15 PM, Satish Vadlamani <
satish.vadlam...@gmail.com> wrote:

> Jean:
> Wow. Thank you so much for this. I will read up igraph and then see if
> this is going to work for me for the larger dataset.
>
> Thanks for the wonderful snippet code you wrote. Basically, the
> requirement is this:
> TLA1 (Top Level Assembly) and its components should belong to the same
> group. If a component belongs to a different TLA (say TLA2), then that TLA1
> and all of its components should belong to the same as that of TLA1.
>
> Are these types of questions appropriate for this group?
>
> Thanks,
> Satish
>
>
> On Mar 28, 2016 9:10 AM, "Adams, Jean"  wrote:
>
>> Satish,
>>
>> If you rearrange your data into a network of nodes and edges, you can use
>> the igraph package to identify disconnected (mutually exclusive) groups.
>>
>> # example data
>> df <- data.frame(
>>   Component = c("C1", "C2", "C1", "C3", "C4", "C5"),
>>   TLA = c("TLA1", "TLA1", "TLA2", "TLA2", "TLA3", "TLA3")
>> )
>>
>> # characterize data as a network of nodes and edges
>> nodes <- levels(unlist(df))
>> edges <- apply(df, 2, match, nodes)
>>
>> # use the igraph package to identify disconnected groups
>> library(igraph)
>> g <- graph(edges)
>> ngroup <- clusters(g)$membership
>> df$Group <- ngroup[match(df$Component, nodes)]
>> df
>>
>>   Component  TLA Group
>> 1C1 TLA1 1
>> 2C2 TLA1 1
>> 3C1 TLA2 1
>> 4C3 TLA2 1
>> 5C4 TLA3 2
>> 6C5 TLA3 2
>>
>> Jean
>>
>> On Sun, Mar 27, 2016 at 7:56 PM, Satish Vadlamani <
>> satish.vadlam...@gmail.com> wrote:
>>
>>> Hello All:
>>> I would like to get some help with the following problem and understand
>>> how
>>> this can be done in R efficiently. The header is given in the data frame.
>>>
>>> *Component, TLA*
>>> C1, TLA1
>>> C2, TLA1
>>> C1, TLA2
>>> C3, TLA2
>>> C4, TLA3
>>> C5, TLA3
>>>
>>> Notice that C1 is a component of TLA1 and TLA2.
>>>
>>> I would like to form groups of mutually exclusive subsets and create a
>>> new
>>> column called group for this subset. For the above data, the subsets and
>>> the new group column value will be like so:
>>>
>>> *Component, TLA, Group*
>>> C1, TLA1, 1
>>> C2, TLA1, 1
>>> C1, TLA2, 1
>>> C3, TLA2, 1
>>> C4, TLA3, 2
>>> C5, TLA3, 2
>>>
>>> Appreciate any help on this. I could have looped through the observations
>>> and tried some logic but I did not try that yet.
>>>
>>> --
>>>
>>> Satish Vadlamani
>>>
>>> [[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] How to form groups for this specific problem?

2016-03-28 Thread Adams, Jean
Satish,

If you rearrange your data into a network of nodes and edges, you can use
the igraph package to identify disconnected (mutually exclusive) groups.

# example data
df <- data.frame(
  Component = c("C1", "C2", "C1", "C3", "C4", "C5"),
  TLA = c("TLA1", "TLA1", "TLA2", "TLA2", "TLA3", "TLA3")
)

# characterize data as a network of nodes and edges
nodes <- levels(unlist(df))
edges <- apply(df, 2, match, nodes)

# use the igraph package to identify disconnected groups
library(igraph)
g <- graph(edges)
ngroup <- clusters(g)$membership
df$Group <- ngroup[match(df$Component, nodes)]
df

  Component  TLA Group
1C1 TLA1 1
2C2 TLA1 1
3C1 TLA2 1
4C3 TLA2 1
5C4 TLA3 2
6C5 TLA3 2

Jean

On Sun, Mar 27, 2016 at 7:56 PM, Satish Vadlamani <
satish.vadlam...@gmail.com> wrote:

> Hello All:
> I would like to get some help with the following problem and understand how
> this can be done in R efficiently. The header is given in the data frame.
>
> *Component, TLA*
> C1, TLA1
> C2, TLA1
> C1, TLA2
> C3, TLA2
> C4, TLA3
> C5, TLA3
>
> Notice that C1 is a component of TLA1 and TLA2.
>
> I would like to form groups of mutually exclusive subsets and create a new
> column called group for this subset. For the above data, the subsets and
> the new group column value will be like so:
>
> *Component, TLA, Group*
> C1, TLA1, 1
> C2, TLA1, 1
> C1, TLA2, 1
> C3, TLA2, 1
> C4, TLA3, 2
> C5, TLA3, 2
>
> Appreciate any help on this. I could have looped through the observations
> and tried some logic but I did not try that yet.
>
> --
>
> Satish Vadlamani
>
> [[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] treating integer(0) and NULL in conditions and loops

2016-03-11 Thread Adams, Jean
To reframe the problem ... the issue is not with the function nchar() (or
whatever), it's with the input value rz being null.  I suggest you build
into the loop whatever actions/outputs you want when rz is NULL.

for (i in 1:10){
  if (is.null(rz)) {
# do something here
  } else {
if (nchar(rz)>6) {
  # ...
}
if (nchar(a[i])+nchar(rz))<6) {
  # ...
}
if (nchar(rz)+nchar(a[i+1]>6) {
  # ...
}
  }
}

Jean


On Fri, Mar 11, 2016 at 8:55 AM, Jan Kacaba  wrote:

> Hello, I have following problem in loops. It occurred to me multiple times
> bellow is an example.  Inside if() I have sometimes function f(x) which may
> return integer(0).  If I test f(x)>1 and f(x)=integer(0) I get error. Maybe
> it can be solved more eloquently without loop or swithces. I don't know.
>
> Example:
>
> a=c("ab","abc","abcd","abcde","abcdefghjk") # vector from which new strings
> will be constructed
> svec=NULL # vector of string
> rz=NULL # string
>
> for (i in 1:10){
> if (nchar(rz)>6){
>   svec[i]=rz
>   rz=NULL
> }
>
> if (nchar(a[i])+nchar(rz))<6){
>   rz=paste(rz,a[i])
> }
>
> if (nchar(rz)+nchar(a[i+1]>6){
>   svec[i]=rz
>   rz=NULL
> }
> }
>
> I'm not interested how to treat nchar() function in particular but general
> function. One solution which comes to mind is to redefine function for
> example nchar() function like this:
>
> new.nchar=function(x){
> if (length(nchar(rz))==0){z=0}
> if (length(nchar(rz))>0){z=nchar(rz)}
> return(z)
> }
>
> Is it correct way of doing this or is there a better way without the need
> of redefining new function?
> 
>
> [[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] bootstrap glm

2016-02-29 Thread Adams, Jean
​It's helpful if you post example data with your question, so R-help
readers can easily test your code​.  I created a fake data set with two x
variables for testing.  It's also helpful if you list the necessary
packages.  I assume that used the boot package.

You are dealing with two kinds of indices here, and I think you are
confusing them a bit in your code.  One index tells the program which x
columns to fit, another index tells the boot strapping part of the program
which rows to use.  I modified your code to do what I think you are trying
to do.  The results seem reasonable in this example.

Jean

# fake data
n <- 200
datasim <- data.frame(Y=sample(0:1, n, replace=TRUE), X1=rnorm(n),
X2=rnorm(n))

library(boot)

set.seed(111)

yfunction <- function(data, indices) {
  glm.snp1 <- glm(Y ~ ., family="binomial", data=data[indices, ])
  null <- glm.snp1$null.deviance
  residual <- glm.snp1$deviance
  return(null-residual)
}

resulty <- lapply(2:(ncol(datasim)), function(xcol) {
  boot(datasim[, c(1, xcol)], yfunction, R=100)
})

obsresult <- sapply(resulty, "[[", "t0")
bootresult <- sapply(resulty, "[[", "t")

# observed result
obsresult

# naive 95% bootstrap CI
apply(bootresult, 2, quantile, c(0.025, 0.975))


On Thu, Feb 25, 2016 at 9:59 AM, Hassan, Nazatulshima <
nazatulshima.has...@liverpool.ac.uk> wrote:

> Hi
>
> I have a data with an outcome,Y and 10 predictors (X1-X10).
> My aim is to fit a logistic model to each of the predictors and calculate
> the deviance difference (dDeviance).
> And later on bootstrapping the dDeviance for 100 times (R=100).
> I tried the following function. It is calculating the original dDeviance
> correctly. But, when I checked the mean bootstrap values, it differs
> greatly from the original.
> I suspect I made a mistake with the bootstrapping function, which I need
> help with.
> I attached the script if you need to look at it.
>
> Thank you in advance.
>
>
> set.seed(111)
>
> yfunction <- function(data,indices)
> {
> glm.snp1 <- glm(Y~data[indices], family="binomial", data=datasim)
> null <- glm.snp1$null.deviance
> residual <- glm.snp1$deviance
> dDeviance <-(null-residual)
> return(dDeviance)
> }
>
> mybootstrap <- function(data)
> {
> boot(data,yfunction, R=100)
> }
>
> resulty <- lapply(datasim[,-1],function(x)mybootstrap(x))
> bootresult <- sapply(datasim[,-1],function(x)mybootstrap(x)$t)
> colMeans(bootresult)
>
>
>
> -shima-
>
> __
> 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] Static to interactive map (leaflet spplot)

2016-02-17 Thread Adams, Jean
Deb,

I assume you have already seen the great introduction to leaflet here ...
http://rstudio.github.io/leaflet/

You may find these two answers on stackoverflow helpful ...

http://stackoverflow.com/a/28240058/2140956
http://stackoverflow.com/a/29118680/2140956


Jean

On Tue, Feb 2, 2016 at 5:28 PM, Debasish Pai Mazumder 
wrote:

> Hi ALL,
>
> I have a script to plot hexagonal polygon on a map. Its a static map. I
> used spplot. I would like to convert this plot to interactive plot using "
> *leaflet*". How do I make it interactive plot?
>
> Here is spplot lines:
>
> cl = map("world", xlim = c(-120, 20), ylim = c(-10, 70), plot = TRUE)
> cl = map("world",plot = TRUE)
> clp = map2SpatialLines(cl, proj4string = CRS(ll))
> clp = spTransform(clp, CRS(lcc))
> l2 = list("sp.lines", clp, col = "black", lty = 1, lwd = 3)
>
> cr = colorRampPalette(brewer.pal(9,"YlOrRd"))(100)
>
> require(grid)
> spplot(hspdf, "CDP", col = "white", col.regions = cr,
> sp.layout = list(l2),
> at = seq(0,100,10),
> sub = list("CDP", cex = 1.5, font = 2))
>
> where
> > hspdf
> class   : SpatialPolygonsDataFrame
> features: 95
> extent  : -4141330, 3748528, 1530846, 6914278  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=lcc +lat_1=60 +lat_2=30 +lon_0=-60 +ellps=WGS84
> variables   : 4
> names   : hexid, count, hct,   CDP
> min values  :37, 1,   1, 0.136612021857923
> max values  :   448, 7,   3,  39.4391854927413
>
> CDP values of each hexagonal polygon.
>
> -Deb
>
> [[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] log log regression model

2016-01-01 Thread Adams, Jean
This is more of a statistics question than an R programming question.  I
suggest you look at Cross Validated for an answer.  I found this in a quick
search,

http://stats.stackexchange.com/questions/115571/back-transforming-regression-results-when-modeling-logy

Jean

On Thu, Dec 31, 2015 at 7:35 PM, Andras Farkas <
fark...@optimum-dosing-strategies.org> wrote:

>
>
> Dear All,
>
> wonder if you have a thought on the followimg: if I have a simple model
> like model <- lm(log(y)~log(x)+log(z),data=data), where both, the dependent
> and independent variables are log transformed, is it ok just to use ypred
> <- predict(model,type=response) to get the predictions , then transform
> ypred with exp(ypred)  to y's original scale to compare observed or known
> data (y) with model predicted (ypred) on the original scale?
>
> appreciate your thoughts...
>
> Andras
>
> __
> 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] (no subject)

2015-12-24 Thread Adams, Jean
Excellent job providing example data and a desired result.

This code works on the example you provided.  Hope it helps.

Jean

# reshape the info data frame
library(tidyr)
info2 <- gather(myinfo, set, val, -game)
info2$set <- as.numeric(gsub("[[:alpha:]]", "", info2$set))

# add a new column to the x data frame
y <- t(x[,grep("char", names(x))])
newx <- x
newx$char <- row(y)[y==1]

# merge and define winner
res <- merge(newx, info2)
res$winner <- with(res, ifelse(char==val, 1, 0))
res


On Wed, Dec 23, 2015 at 3:35 PM, Dimitri Liakhovitski <
dimitri.liakhovit...@gmail.com> wrote:

> Merry upcoming Christmas - for those of us who celebrate it!
>
> # I have data frame x.
> x <- data.frame(game = c(rep(1, 4), rep(2, 4)), set = rep(c(1,1,2,2),
> 2), player = rep(1:2, 4),
> char1 = c(1,0,0,0,0,0,0,1), char2 =
> c(0,0,1,0,0,1,0,0), char3 = c(0,1,0,1,0,0,0,0),
> char4 = c(0,0,0,0,1,0,1,0))
> x
> # There are several games (2 here). Each game has several sets (2
> here. In each set participate
> # several players (2 here).
> # Each player possesses 1 or 4 possible characteristics.
> # For example, in game 1, set 1, player 1 has characteristic 1 and player
> 2 -
> # characteristic 3
>
> # I also have data frame myinfo:
> (myinfo <- data.frame(game = 1:2, set1 = c(3, 4), set2 = c(2, 1)))
> # It tells me:
> # in game 1, set 1 the winner was the player with characteristic 3
> # in game 1, set 2 the winner was the player with characteristic 2, etc.
>
> # I need to merge the 2 to produce the result below.
> # I just need an additional column that - for each game and each set -
> # has a 1 in the row of the player who had the winning characteristic
> # (as per myinfo) and has a 0 otherwise.
>
> result <- x
> result$winner <- c(0, 1, 1, 0, 1, 0, 0, 1)
> result
>
> # I have written a long loop that loops through each set of each game,
> identifies
> # which characteristic wins in myinfo, and puts a 1 against the winning
> row.
> # But it's taking forever. Could it be done faster? Thanks a lot!
>
> # Important: In my real game the number of players could be more than
> 2 and so can
> # the number of games and the number of sets per game.
> # However, we can assume that the number of sets per game is always the
> same,
> # and the number of players per set is always the same.
>
>
> --
> Dimitri Liakhovitski
>
> __
> 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] [R-pkgs] LW1949 – new package for evaluating dose-effect experiments

2015-12-07 Thread Adams, Jean
LW1949 1.0.0 is now available on CRAN.



LW1949 automates the steps taken in Litchfield and Wilcoxon’s (1949) manual
approach to evaluating dose-effect experiments. Letting the computer do the
work saves time and yields the best fit possible using the Litchfield
Wilcoxon approach (by minimizing the chi-squared statistic).



A brief demonstration of LW1949 is given in this web app,

 https://jvadams.shinyapps.io/LW1949demo



An example of how to use the functions in LW1949 is given in this vignette,

 https://rawgit.com/JVAdams/LW1949/master/vignettes/Intro.html



Litchfield, JT Jr. and F Wilcoxon. 1949. A simplified method of evaluating
dose-effect experiments. Journal of Pharmacology and Experimental
Therapeutics 96(2):99-113.

 http://jpet.aspetjournals.org/content/96/2/99.abstract


Jean​​


`·.,,  ><(((º>   `·.,,  ><(((º>   `·.,,  ><(((º>

Jean V. Adams​​
Statistician
U.S. Geological​​ Survey ​​
Great Lakes Science Center
223 East Steinfest Road ​​
Antigo, WI 54409  USA ​​
http://www.glsc.usgs.gov
http://profile.usgs.gov/jvadams

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages
__
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] Looping through multiple sub elements of a list to compare to multiple components of a vector

2015-12-02 Thread Adams, Jean
First, a couple posting tips.  It's helpful to provide some example data
people can work with.  Also, please post in plain text (not html).

If you have a single standard for comparison, you might find an approach
like this helpful.

# example data
mylist <- c("AAEBCC", "AABDCC", "AABBCD")
list.2 <- strsplit(mylist, split=NULL)

# setting a standard for comparison
std.string <- "AABBCC"
standard <- unlist(strsplit(std.string, split=NULL))

sapply(list.2, function(x) x==standard)

This gives you a matrix of logicals with the number of rows the same length
as your original strings (the 99 amino acids) and the number of columns the
same length as the number of strings you're comparing (the 15 sequences).

  [,1]  [,2]  [,3]
[1,]  TRUE  TRUE  TRUE
[2,]  TRUE  TRUE  TRUE
[3,] FALSE  TRUE  TRUE
[4,]  TRUE FALSE  TRUE
[5,]  TRUE  TRUE  TRUE
[6,]  TRUE  TRUE FALSE

Jean

On Wed, Dec 2, 2015 at 9:39 AM, debra ragland via R-help <
r-help@r-project.org> wrote:

> I think I am making this problem harder than it has to be and so I keep
> getting stuck on what might be a trivial problem.
> I have used the seqinr package to load a protein sequence alignment
> containing 15 protein sequences;
> > library(seqinr)> x =
> read.alignment("proteins.fasta",format="fasta",forceToLower=FALSE)This
> automatically loads in a list of 4 elements including the sequences and
> other information.
> I store the sequences to a new list;
>> mylist = x$seqwhich returns a character vector of 15 strings.
> I have found that if I split the long character strings into individual
> characters it is easy to use lapply to loop over this list. So I use
> strsplit;
> >list.2 = strsplit(mylist, split = NULL)
> >From this list I can determine which proteins have changes at certain
> positions by using;
> >lapply(list.2, "[", 10) == "L"This returns a logical T/F vector for
> those elements of the list that do/do not the letter L at position 10.
> Because each of the protein sequences contains 99amino acids, I want to
> automate this process so that I do not have to compare/contrast positions 1
> x 1. Most of the changes occur between positions/letters 10-95. I have a
> standard character vector that I wish to use for comparison when looping
> through the list.
> Should I perhaps combine all --  the standard "letter"/aa vector, the list
> of protein sequences -- into one list? Or is it better to leave them
> separate for this comparison? I'm not sure what the output should be as I
> need to use it for another statistical test. Would a list of logical
> vectors be the most sufficient output to return?
> [[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] Subsetting dataframe by the nearest values of a vector elements

2015-11-09 Thread Adams, Jean
Harun,

Can you give a simple example?

If your cross_section looked like this
c(144, 179, 214, 39, 284, 109, 74, 4, 249)
and your other vector looked like this
c(0, 50, 100, 150, 200, 250, 300, 350)
what would you want your subset to look like?

Jean

On Mon, Nov 9, 2015 at 7:26 AM, Harun Rashid via R-help <
r-help@r-project.org> wrote:

> Hello,
> I have a dataset with two columns 1. cross_section (range: 0~635), and
> 2. elevation. The dataset has more than 100 rows. Now I want to make a
> subset on the condition that the 'cross_section' column will pick up the
> nearest cell from another vector (say 0, 50,100,150,200,.,650).
> How can I do this? I would really appreciate a solution.
> Regards,
> Harun
> --
>
> 
> 
>
> [[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] find max. value for a equation by optimize

2015-10-29 Thread Adams, Jean
If you read the help file for optimize, you will see that you need to set
the argument maximum to TRUE.

?optimize

optimize(sm, c(0, 50), maximum=TRUE)

Jean

On Thu, Oct 29, 2015 at 4:19 PM, Jianling Fan  wrote:

> Hello, everyone,
>
> I have a specific equation, When I draw it out, I found there is a
> max. value for it at about x=5. but I couldn't point it out by
> optimize(). Does anyone know why? Thanks!
>
> my code is:
>
> d50<-18.04
> c<-  -1.276
> dm<-147
>
> sm <- function (x) {
>
> 1/(1+(x/d50)^c)+(1-1/(1+(dm/d50)^c))*x/dm-(1/(1+((x-1)/d50)^c)+(1-1/(1+(dm/d50)^c))*(x-1)/dm)
> }
> curve(sm, 0,50)
> optimize(sm,c(0,50))
>
> The optimize() only give min. value but not max.
>
> __
> 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] mapping between list and vector

2015-10-29 Thread Adams, Jean
Maxim,

I'm not sure how much faster this would be ... but you could test it out
and see.  I defined lngL and result as vectors instead of lists.  And I
calculated j outside of the "loop".

myList <- list(a="key1", b=c("key2","key3"), c="key4")
myVec <- c("val1","val2","val3","val4")

lngL <- sapply(myList, length)
L <- length(lngL)
j <- cumsum(c(1, lngL))[1:L]
result <- sapply(1:L, function(i) paste(myVec[j[i]:(j[i] - 1 + lngL[i])],
collapse="//"))

Jean

On Thu, Oct 29, 2015 at 2:34 PM, Maxim via R-help 
wrote:

> Hi,
>
> for some reason I have to map elements of a list "myList" (of vectors of
> different length) to a vector "myVec" as such:
>
> myList <- list(a="key1", b=c("key2","key3"), c="key4")
> myVec <- c("val1","val2","val3","val4")
>
>
> result <- list()
> lapply(myList,length) -> lngL
>
> j <- 1
> for (i in 1:(length(lngL))) {
> result[[i]] <- paste(myVec[j:(j-1+lngL[[i]])],collapse="//")
> j <- j+lngL[[i]]
> }
>
> that the result looks like this:
>
> > result
>
> [[1]]
> [1] "val1"
>
> [[2]]
> [1] "val2//val3"
>
> [[3]]
> [1] "val3"
>
> Above code is the fastest version I was able to come up with (the list
> contains about 1 million elements). I guess the for loop can be substituted
> by a lapply command making it less complicated and probably faster, but I
> can't figure out how to do this in a more elegant and especially faster
> fashion.
>
> Best
> Maxim
>
> [[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] Distribution hist

2015-10-28 Thread Adams, Jean
Something like this might help you get started.

Simulation <-
  c(10403, NA, NA, NA, NA, 11178, NA, NA, NA, NA, 11521, NA, NA,
  NA, NA, 11385, NA, NA, NA, NA, 10102, NA, NA, NA, NA, 10544.013,
  10339.925, 9912.695, 9928.198, 9932.112, 9008.05, 9437.174, 10406.784,
  10832.123, 11095.868, 10955.094, 10804.075, 9002.848, 11276.038,
  10503.487, 11899.525, 10085.509, 9109.918, 8953.339, 10135.833,
  11047.832, 14353.462, 8804.653, 11942.829, 7722.255, 9732.114,
  8413.027, 10213.796, 10091.471, 12317.169)

yl <- c(0, 2)
par(mfrow=c(1, 2), oma=c(0, 0, 2, 0))
matplot(Simulation, type="l", ylim=yl)
fhist <- hist(Simulation, plot=FALSE)
with(fhist, plot(counts, mids, ylim=yl, type="o"))
mtext("Dim Mo Simulation 2 years", outer=TRUE, side=3)


Jean

On Tue, Oct 27, 2015 at 3:17 PM, bgnumis bgnum  wrote:

> Hi all,
>
> I have this data on "sim" variable
>
>  10403.000NANANANA
>  11178.000NANANANA
>  11521.000NANANANA
>  11385.000NANANANA
> 10102.000NANANANA
>  10544.013 10339.925  9912.695  9928.198  9932.112
>   9008.050  9437.174 10406.784 10832.123 11095.868
>  10955.094 10804.075  9002.848 11276.038 10503.487
>  11899.525 10085.509  9109.918  8953.339 10135.833
>  11047.832 14353.462  8804.653 11942.829  7722.255
>   9732.114  8413.027 10213.796 10091.471 12317.169
>
> I want to use matplot on a left plot and a "distribution line" on a right
> plot.
>
> My idea is the same size from the ylim (max and min) on the left plot will
> be the same on the right plot (but I cannot get the same size so thar the
> right plot show the distribution of the matplot on the left.
>
> I tried this but canot (some suggest me using rect() for the boundaries of
> the second plot but I cannot achive what I want.
>
> I dont care if is it a hist or line plot but something similar a
> distribution shape (or like a bell)
>
>
> Can anyone try to help me?
>
> par(mar=c(10,6,6,6))
> matplot(Simulation,type="l",ylim=c(0,2))
>
>
> title(" Dim Mo Simulation 2 years",font=4)
> fhist<-hist(Simulation,plot=FALSE)
>
> par(mar=c(6,0,6,6))
> barplot(fhist$counts,axes=FALSE, space=0,horiz=TRUE,col="lightgray")
>
> [[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] Formating time in R

2015-10-26 Thread Adams, Jean
Raoni,

You could write your own function to do this.  For example, using the
period class from the R package lubridate, you could do something like this:

days2 <- function(x) {
  h1 <- 24*x
  h <- floor(h1)
  m1 <- 60*(h1 - h)
  m <- floor(m1)
  s <- round(60*(m1 - m))
  new_period(second=s, minute=m, hour=h)
}

library(lubridate)
test <- c(1.424708, 0.028674)
days2(test)

[1] "34H 11M 35S" "41M 17S"

Jean

On Mon, Oct 26, 2015 at 1:48 PM, Cacique Samurai 
wrote:

> Hello R-Helpers!
>
> I have a vector of times of events that time is fraction of 1, because
> it was calculated in excel. Are there some way to format a period
> greater than 24h in a format like excel [h]:mm:ss?
>
> Exemple:
>
> test = c(1.424708, 0.028674)
>
> > chron (times. = test [2], format = "h:m:S")
> [1] 00:41:17
>
> > chron (times. = test, format = "h:m:S")
> Time in days:
> [1] 1.424708 0.028674
>
> I need an output like:
>
> 34:11:35 0:41:17
>
> Thanks in advanced,
>
> Raoni
>
> --
> Raoni Rosa Rodrigues
> Research Associate of Fish Transposition Center CTPeixes
> Universidade Federal de Minas Gerais - UFMG
> Brasil
> rodrigues.ra...@gmail.com
>
> __
> 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] Variable names conflict

2015-10-15 Thread Adams, Jean
Axel,

The solution you propose looks fine to me, if an error is the outcome that
you want in such a situation.  Were you hoping for a different outcome?
Would you, for example, prefer that the "x" in the data frame be given a
different name, rather than the "x" in the function?

Jean

On Thu, Oct 15, 2015 at 11:42 AM, Axel Urbiz  wrote:

> Hello,
>
> I have a variable named 'x' defined inside a function, which   may conflict
> with a variable name supplied in the argument to the function. What is the
> best practice to avoid this conflict?
>
> foo <- function(df) {
>   x <- df[, 1, drop = FALSE]
>   dfOut <- data.frame(df, x)
>   dfOut
>
> }
> Data <- data.frame(x = c(1, 2), y = c(3, 4))
> foo(Data)
>
>   x y x.1
> 1 1 3   1
> 2 2 4   2
>
> The following solution doesn't look nice to me…
>
> foo <- function(df) {
>   if (any(names(df) == 'x'))
> stop("x cannot be a variable name in the data frame")
>   x <- df[, 1, drop = FALSE]
>   dfOut <- data.frame(df, x)
>   dfOut
>
> }
>
> Thanks!
> Axel.
>
> [[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] k-nearest neighbour classification

2015-10-13 Thread Adams, Jean
Ah, I see what you're after.  I don't know of a built in function to search
for the best number of nearest neighbors.  You may have to run the code for
each k separately, then compare the resulting errors.

Jean

On Tue, Oct 13, 2015 at 9:13 AM, Neverstop  wrote:

> I know that knn.cv(train=predictors.training, cl=classes.training, k=3,
> prob=TRUE) works but by doing so I fix the tuning paramer k to be 3. Isn't
> cross validation a technique to choose the optimal tuning parameter trying
> a
> range of different values for the tuning parameter?
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/k-nearest-neighbour-classification-tp4713523p4713531.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> 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] k-nearest neighbour classification

2015-10-13 Thread Adams, Jean
The argument k should be a scalar, not a vector.  So, for example, this
works:

knn.cv(train=predictors.training, cl=classes.training, k=3, prob=TRUE)

Jean


On Tue, Oct 13, 2015 at 3:59 AM, Neverstop  wrote:

> Hi, I'm trying to perform a cross validation to choose the optimal k in the
> k-nearest-neighbors algorithm for classification. I'm using the  knn
> 
> function of the package class. Reading the R documentation, I've found out
> that there's already a function to perform cross validation:  knn.cv
>   .
> The
> problem is that I don't understand how I should use it.
>
> data(iris)
> head(iris)
>
> predictors.training=iris[c(1:25,51:75,101:125),c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width")]
>
> predictors.test=iris[c(26:50,76:100,126:150),c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width")]
> classes.training=iris[c(1:25,51:75,101:125),"Species"]
> library(class)
> knn.cv(train=predictors.training, cl=classes.training, k=c(1,3,5,7),
> prob=TRUE)
>
> Warning messages:
> 1: In if (ntr - 1 < k) { :
>   the condition has length > 1 and only the first element will be used
> 2: In if (k < 1) stop(gettextf("k = %d must be at least 1", k), domain =
> NA)
> :
>   the condition has length > 1 and only the first element will be used
>
> Thank you.
>
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/k-nearest-neighbour-classification-tp4713523.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> 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] R lappy, sapply or mapply question

2015-10-09 Thread Adams, Jean
You were very close.  Try this.

df <- data.frame(x5=dailyrecord$a, x6 = dailyrecord$e, x7 = dailyrecord$f)
apply(df, 1, function(row) fun3(list1, list2, as.list(row)))

Jean

On Fri, Oct 9, 2015 at 3:15 PM, liqunhan--- via R-help  wrote:

>
>
> Hello, R-experts,
> In R-program, I have a question about the apply-family.
> I want to use apply-family to replace a for-loop in my R-code,But, lapply
> returns a list of 3 (each component is the same), sapply returns a matrix,
> and mapply with error message.
> how to use apply-family function so that it returns a vector, as it does
> when using for-loop in my R-codes below?
> Hope to hear back soon!
> Thank you very much!
>
>
>
> #-
> # Below is my R-codes:
> #---  begin of  R code --
> # suppose list1 returned by fun1()
> # fun1() is a R-script with about 200 lines
> list1 <- list(u=3.8, v=53.42)# suppose list2 returned by fun2()
> # fun2() is a R-script with about 5000 lines
> list2 <- list(x=3.8, y=-9,3)# demo fun3(), the actual function is much
> more complicated
> fun3 <- function(xlist1, xlist2, xlist3) {
>
>   x1 <- xlist1$u
>   x2 <- xlist1$v
>
>   x3 <- xlist2$x
>   x4 <- xlist2$y
>
>   x5 <- xlist3$x5
>   x6 <- xlist3$x6
>   x7 <- xlist3$x7
>
>   w <- x1^2 + sqrt(x2+x3) - 0.75*x4 + exp(x5)
>   z <- sin(x2)/x7 + x6/(x3+x4)
>   return(w+z)
> }dailyrecord <- data.frame(a = rnorm(5), b = rnorm(5), c =
> rnorm(5),
>   d = rnorm(5), e = rnorm(5), f =
> rnorm(5),
>   g = rnorm(5))
> result_forloop <- rep(0, 5)
> # use for - loop ## how to avoid the for-loop ??for (k in 1 : 5) {
>   xlist <- list(x5 = dailyrecord$a[k], x6 = dailyrecord$e[k], x7 =
> dailyrecord$f[k])
>   result_forloop[k] <- fun3(list1, list2, xlist)
> }# use lapply  #--- return a list of 3 
> xlst <- list(x5=dailyrecord$a, x6 = dailyrecord$e, x7 = dailyrecord$f)
> result_lapply <- lapply(xlst, function(s) fun3(list1, list2, xlst))
>
> # use sapply  #--- return a matrix  ---
> result_sapply <- sapply(xlst, function(s) fun3(list1, list2, xlst))
>
> # use mapply  #--- error  ---
> result_mapply <- mapply(fun3, xlist1 = list1, xlist2 = list2, xlist3 =
> xlst)
>
> #---  end of R 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.

[[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] Result error using the function

2015-10-06 Thread Adams, Jean
I have simplified your function.  And I have transposed your results such
that resulting metrics are in columns rather than rows.  So, it's not
exactly what you were after, but perhaps you will find it useful.

monthly_summary <- function(dt, r, tol=1E-6) {
  # number of days with above tol by year and month
  mt1 <- tapply(dt[, "Amount"] > tol, dt[, c("Month", "Year")], sum)
  # mean number of days with above tol by month
  mn <- apply(mt1, 1, mean)
  # proportion of days with above tol by year and month
  pd1 <- tapply(dt[, "Amount"] > tol, dt[, c("Month", "Year")], mean)
  # mean proportion of days with above tol by month
  mnp <- apply(mt1, 1, mean)
  # inverse of this proportion
  lambda <- 1/mnp
  cbind(mt1, mn, lambda)
}

m_sum <- monthly_summary(J1, 2)
m_sum

Jean


On Tue, Oct 6, 2015 at 1:33 AM, smart hendsome 
wrote:

> Hi R-users,
>
>
> I am new to R.  I try to code using the function in R as below:
>  monthly_summary <- function(dt,r)
> {  tol <- 1E-6
>mn  <- vector(length=12, mode="numeric")
>lambda  <- vector(length=12, mode="numeric")
>ag  <- aggregate(dt[,4] > tol, list (dt[,2], dt[,1]), sum)
>names(ag) <- c("Year", "Month","Amount")
>mt1 <- matrix(ag[,3],nrow=r,ncol=12,byrow=T)
>rownames(mt1) <- 1950:1951
>colnames(mt1) <- c("Jan","Feb","Mar","Apr","May","June","July",
>  "Aug","Sept","Oct","Nov","Dec")
>
>   for (i in 1:ncol(mt1))
>   {
>   {  xi <- mt1[,i]
>  mn[i]  <- mean(xi)## calc mean
>   }
>
>   if  (mt1[,c(1,3,5,7,8,10,12)])
>   {
>lambda[i]  <- (31/mn[i])   ## calc lambda
> for month with 31 days
>   }
>   else if  (mt1[,2])
>{
>lambda[i]  <- (28/mn[i])## calc lambda
> for month with 28 days
>}
>else
>{
>   lambda[i]  <- (30/mn[i])  ## calc lambda
> for month with 30 days
>}
>
>   ## result
>   mt1 <- round(mt1, 0)
>   mn <-   round(mn, 3)
>   lambda <- round(lambda, 3)
>
> }
>   comb <- rbind(mt1, mn = mn, lambda = lambda)
> }
>
> ## call function
> m_sum <- monthly_summary(J1,2); m_sum
>
> The problems are:
> 1)the value of count rain in decimals
> 2) the value lambda is wrong3)i dont know how to account the leap years in
> february
> Anyone can help me?
> I also provide my data using dput(). Thanks so much.
> structure(list(Year = c(1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L,
> 1950L, 1

Re: [R] vector graphics

2015-10-06 Thread Adams, Jean
Perhaps the discussion at this link will be helpful ...
http://stackoverflow.com/questions/9555889/producing-a-vector-graphics-image-i-e-metafile-in-r-suitable-for-printing-in

Jean

On Tue, Oct 6, 2015 at 9:42 AM, Ivan Calandra 
wrote:

> Dear useRs,
>
> A colleague of mine is having a problem with graphic devices. The goal is
> to save into a vector graphic format that can be edited with Illustrator
> CS4.
>
> On my Mac (Snow Leopard), I use RSvgDevice::devSVG() and it works fine.
> But on her Windows Vista computer, I cannot find an alternative.>
> sessionInfo()
> R version 3.2.2 (2015-08-14)
> Platform: i386-w64-mingw32/i386 (32-bit)
> Running under: Windows Vista (build 6002) Service Pack 2
>
> I have tried:
> - pdf(): I cannot dissociate the graphical elements (no problem with text)
> - cairo_pdf(): the text is replaced by symbols
> - cairo_ps(): fine except that the text is not text but object (it is then
> a bit troublesome, as any text modification requires the text to be
> completely rewritten)
> - svg(): the graphic is completely screwed up (it seems to be a scaling
> problem, with symbols and letters all very large and superposed)
> - RSvgDevice cannot be installed on the Windows machine, neither as binary
> nor from source.
>
> Is there any other device that could work? If not, is it a matter of
> settings? So, basically, what can I do?
>
> Thank you in advance,
> Ivan
>
> --
> Ivan Calandra, PhD
> University of Reims Champagne-Ardenne
> GEGENAA - EA 3795
> CREA - 2 esplanade Roland Garros
> 51100 Reims, France
> +33(0)3 26 77 36 89
> ivan.calan...@univ-reims.fr
> https://www.researchgate.net/profile/Ivan_Calandra
>
> __
> 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] Line in hist count

2015-09-28 Thread Adams, Jean
I'm not sure what you want when you refer to the "last value of f", but
perhaps this will help you out.  I simplified your example since the other
parts of the code you submitted (par, grid, title, etc.) do not have
anything to do with your question.

# some fake data for f
f <- rnorm(20)

# save the counts using default breaks
fhist <- hist(f, plot=FALSE)

# calculate the proportion
x <- fhist$counts/sum(fhist$counts)

# plot the results, and save the y values
b <- barplot(x, horiz=TRUE)

# add text to the bars
text(x, b, b, pos=2)

Jean


On Sun, Sep 27, 2015 at 4:51 PM, bgnumis bgnum  wrote:

> Hi, all
>
> I have discovered that with abline(h=dataf,col="red") can add a line as I
> want in this plot
>
> fhist<-hist(f,plot=FALSE)
> par(mar=c(6,0,6,6))
> barplot(fhist$counts/ sum(fhist$counts),axes=FALSE,
> space=0,horiz=TRUE,col="lightgray")
> grid()
> title("Marginal Distribution CDS vs. Ibex",font=4)
> abline(h=dataf,col="red")
>
> The thing is:
>
> ¿How can I display the associated fhist$counts/ sum(fhist$counts on the
> last value of f?
>
> 2015-09-26 23:31 GMT+02:00 bgnumis bgnum :
>
> > Hi all,
> >
> > Several time ago I used to work with R, now I´m returning to study and
> > work and searching old file I see that I used this code:
> >
> >
> > gfhist<-hist(gf,plot=FALSE)
> >
> > par(mar=c(6,0,6,6))
> >
> > barplot(gfhist$counts,axes=FALSE, space=0,horiz=TRUE,col="lightgray")
> >
> > grid()
> >
> > title("Marginal Distribution Lagged",font=4)
> >
> > The thing is I would line to plot a bar (horizontal and thing bar that
> > will be placed on the last gf data but on the barplot
> >
> > ¿Do you think is it possible? gf is a matrix.
> >
> >
> >
>
> [[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] How to find out if two cells in a dataframe belong to the same pre-specified factor-level

2015-09-28 Thread Adams, Jean
Here's one approach that works.  I made some changes to the code you
provided.  Full working example code given below.

library(reshape)
library(ggplot2)
library(dplyr)

dist1 <- matrix(runif(16), 4, 4)
dist2 <- matrix(runif(16), 4, 4)
rownames(dist1) <- colnames(dist1) <- paste0("A", 1:4)
rownames(dist2) <- colnames(dist2) <- paste0("A", 1:4)
m1 <- melt(dist1)
m2 <- melt(dist2)
# I changed the by= argument here
final <- full_join(m1, m2, by=c("X1", "X2"))

# I made some changes to keep spcs character and grps factor
species <- data.frame(spcs=paste0("A", 1:4),
  grps=as.factor(c(rep("cat", 2), (rep("dog", 2, stringsAsFactors=FALSE)

# define new variables for final indicating group membership
final$g1 <- species$grps[match(final$X1, species$spcs)]
final$g2 <- species$grps[match(final$X2, species$spcs)]
final$group <- as.factor(with(final, ifelse(g1==g2, as.character(g1),
"dif")))

# plot just the rows with matching groups
ggplot(final[final$group!="dif", ], aes(value.x, value.y, col=group)) +
  geom_point()
# plot all the rows
ggplot(final, aes(value.x, value.y, col=group)) + geom_point()

Jean


On Sun, Sep 27, 2015 at 4:22 PM,  wrote:

> Dear list,
> I really couldnt find a better way to describe my question, so please bear
> with me.
>
> To illustrate my problem, i have a matrix with ecological distances (m1)
> and one with genetic distances (m2) for a number of biological species. I
> have merged both matrices and want to plot both distances versus each
> other, as illustrated in this example:
>
> library(reshape)
> library(ggplot2)
> library(dplyr)
>
> dist1 <- matrix(runif(16),4,4)
> dist2 <- matrix(runif(16),4,4)
> rownames(dist1) <- colnames(dist1) <- paste0("A",1:4)
> rownames(dist2) <- colnames(dist2) <- paste0("A",1:4)
>
> m1 <- melt(dist1)
> m2 <- melt(dist2)
>
> final <- full_join(m1,m2, by=c("Var1","Var2"))
> ggplot(final, aes(value.x,value.y)) + geom_point()
>
> Here is the twist:
> The biological species belong to certain groups, which are given in the
> dataframe `species`, for example:
>
> species <- data.frame(spcs=as.character(paste0("A",1:4)),
>   grps=as.factor(c(rep("cat",2),(rep("dog",2)
>
> I want to check if a x,y pair in final (as in `final$Var1`, `final$Var2`)
> belongs to the same group of species (here "cat" or "dog"), and then want
> to color all groups specifically in the x,y-scatterplot.
> Thus, i need an R translation for:
>
> final$group <- If (final$Var1 and final$Var2) belong to the same group as
> specified
>   in species, then assign the species group here, else do nothing or
> assign NA
>
> so i can proceed with
>
> ggplot(final, aes(value.x,value.y, col=group)) + geom_point()
>
> So, in the example, the pairs A1-A1, A1-A2, A2-A1, A2-A2 should be
> identified as "both cats", hence should get the factor "cat".
>
> Thank you very much!
>
>
> Tim
>
> __
> 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] Error from lme4: "Error: (p <- ncol(X)) == ncol(Y) is not TRUE"

2015-09-22 Thread Adams, Jean
Rory,

When I searched online, I found an issue with lme4 on GitHub that suggests
this error is "due to NA values in non-factor variables".
https://github.com/lme4/lme4/issues/246

Hope this helps.

Jean

On Tue, Sep 22, 2015 at 8:18 AM, Rory Wilson  wrote:

> Hello all, I am trying to run a random intercept model using lme4. The
> random effect is a factor of 29 possibilities, making a model with one
> random effect (one level). It is just a linear model. There are 713
> observations. However, when trying to run the model I receive the
> error "Error: (p <- ncol(X)) == ncol(Y) is not TRUE",
> a search for which reveals somewhat surprisingly little. Has anyone seen
> this before? Note that if I simply change the random effect into a fixed
> effect and use lm, the model works perfectly.Thank you!Rory
>
> [[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] R code help!

2015-09-19 Thread Adams, Jean
Here's one way to save your results, using a list of lists and a for() loop.

nsim <- 100
outputs <- vector("list", nsim)
for(i in 1:nsim) {
  outputs[[i]] <- sim.f(p.s=.05, N=1000, sample.size=69, n.sim=500)
}

Jean

On Fri, Sep 18, 2015 at 2:27 PM, SH  wrote:

> Dear R users,
>
> I am trying to simulate surveys and the survey result will be used to
> determine the population to be "accepted" or "rejected".  With the results,
> I would like to calculate cumulative means and plot them to see if a
> converged value is as expected.  Below is R-code I generated.  I need a
> help to repeat this simulation code as many times (e.g., 100) and keep the
> results as list format if possible.  Could you give me any insight?
>
> Thanks  a lot in advance,
>
> Steve
>
> sim.f <- function(p.s, N, sample.size, n.sim) {
> pop = sampled.pop = decision = decisionB = cum.mn = as.list(NULL)
> for(i in 1:n.sim) {
>p <- c(rep(1, p.s*N), pop2 <- rep(0, N*(1-p.s))) # Generate sample space
>pop[[i]] <- sample(p) # Randomization sample space
>sampled.pop[[i]] <- sample(pop[[i]], sample.size)# Random sampling
>decision[i] <- ifelse(sum(sampled.pop[[i]])>=1, 'Reject','Pass') #
> Decision for each group of n.sim
>decisionB <- ifelse(decision == 'Reject', 1, 0) # Convert to binary
>cum.mn <- cumsum(decisionB) / seq_along(decisionB) # Cummulative mean
> of
> n.sim group decisions
>}
> result = list(population=pop,
>   pop_sub = sampled.pop,
>   decision = decision,
>   decisionB = decisionB,
>   cum.mn = cum.mn)
> }
> sim.out <- sim.f(p.s=.05, N=1000, sample.size=69, n.sim=500)
> # I want to repeat this simulation function for example 100 times or and
> also #keep the data so that I can explore later.  If it is not possible to
> keep all #outputs, at least I would like to have cum.mn outputs.
>
> summary(sim.out)
> sim.out$population
> sim.out$pop_sub
> sim.out$decision
> sim.out$decisionB
> y1 <- sim.out$cum.mn
> #plot(y1, type='l')
> lines(y2, type='l')
> ...
> lines(y100, type='l')
> abline(h=.95, col='red')
>
> [[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] finding those elements of listA that are found in listB

2015-09-17 Thread Adams, Jean
John,

The intersect() function may help you.  For example:

listA <- sort(sample(10, 5))
listB <- sort(sample(10, 5))
both <- intersect(listA, listB)

> listA
[1] 2 4 7 8 9
> listB
[1]  1  2  3  8 10
> both
[1] 2 8

Jean

On Wed, Sep 16, 2015 at 9:43 PM, John Sorkin 
wrote:

> I have two structures. I think they are lists, but I am not sure. Both
> structures contain integers. I am trying to find those members of list b
> that are found in list a. I have tried to perform the search using grep,
> but I get an error. Please see code below. I would appreciate knowing how
> to search listB for any element in listA
> Thanks
> John
>
>
> > str(listA)
>  int [1:42] 13083 13705 14123 14168 14382 14652 14654 14678 14817 14822 ...
> > str(listB)
>  int [1:633] 13083 13083 13083 13083 13083 13083 13705 13705 13705 13705
> ...
> > grep(listA,listB)
> [1] 1 2 3 4 5 6
> Warning message:
> In grep(listA, listB) :
>   argument 'pattern' has length > 1 and only the first element will be used
>
>
>
>
>
>
>
>
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:16}}

__
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] mtext in the top left of margin

2015-09-16 Thread Adams, Jean
You can use the coordinates of the plot region as fractions of the figure
region, par("plt"), to define the adj= argument of mtext().  And you can
use the number of lines of the plot margin to define the line= argument of
mtext().  For example:

plot.figure <- function() {
  par(mfrow=c(3, 1), mar=c(3, 5, 3, 2), oma=c(1, 1, 1, 1))
  # use the coords of the plot region as fractions of the figure region
  # to define the adj= argument of mtext()
  pplt <- par("plt")
  adjx <- (0 - pplt[1]) / (pplt[2] - pplt[1])
  # use the number of lines of margin to define the line= argument of
mtext()
  liney <- par("mar")[3] - 1.5
  plot(dnorm, from=-4, to=4, main="Test")
box("plot", col="grey")
box("figure", col="red")
mtext("A", side=3, adj=adjx, line=liney)
  plot(dnorm, from=-4, to=4)
box("plot", col="grey")
box("figure", col="red")
mtext("B", side=3, adj=adjx, line=liney)
  plot(dnorm, from=-4, to=4)
box("plot", col="grey")
box("figure", col="red")
mtext("C", side=3, adj=adjx, line=liney)
  box("outer", col="blue")
}
plot.figure()

Jean

On Wed, Sep 16, 2015 at 5:00 AM, Hermann Norpois  wrote:

> Hello,
>
> for a multiple figures plot I am looking for the syntax to put text in the
> top left of the margin (of the plot). I want my testfunction plot.figure to
> place mtext in the top left of the red margin (created by box("figure",
> col="red")).
>
> Can anybody help?
>
> Thanks
> Hermann
>
> plot.figure <- function ()
> {
>
>
> par (mfrow=c(3,1))
> par (mar=c(3,3,1,0.5))
> par (oma=c(1,1,1,1))
> par (mar=c(3,5,3,2))
>
> plot (dnorm, from=-4, to=4, main="Test")
> box ("plot", col="grey")
> box ("figure", col="red")
> box ("outer", col="blue")
> mtext ("A", side=3, adj=0, line=1.5)
>
> plot (dnorm, from=-4, to=4)
> box ("plot", col="grey")
> box ("figure", col="red")
> box ("outer", col="blue")
>  mtext ("B", side=3, adj=0, line=1)
> plot (dnorm, from=-4, to=4)
> box ("plot", col="grey")
> box ("figure", col="red")
> box ("outer", col="blue")
> mtext ("C", side=3, adj=0)
> }
>
> [[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] Visualization of people's interactions by participation to parties

2015-09-04 Thread Adams, Jean
Hendrik,

It's not clear to me what kind of R help you are looking for.  I suggest
you provide more information on the data that you have and the questions
that you want answered.  Is it in an external file?  Is it an R object?
What code have you written or tried?  Including example data, for example
the output from dput(), is very helpful.

Jean

On Wed, Sep 2, 2015 at 1:46 AM, Voxcoelestis via R-help <
r-help@r-project.org> wrote:

> Dear all,
>
> I have a long list of parties and participants over many years and want to
> extract network relations between people to identify groups of friends. My
> list looks like this:
>
> Party 1; date party 1; first name 1 last name 1; first name 2 last name 2;
> first name 3 last name 3;
> Party 2; date party 2; first name 1 last name 1; first name 3 last name 3;
> first name 4 last name 4;
> Party 3; date party 3; first name 3 last name 3; first name 5 last name 5;
> Party 4; date party 4; first name 2 last name 2; first name 6 last name 6;
> first name 3 last name 3; first name 1 last name 1;
> Party 5; date party 5; first name 5 last name 5; first name 4 last name 4;
> 
>
> Obviously the amount and the order of names is not regular. The list is
> far too long to count co-appearances for each person-person combination by
> hand.
>
> What I would like to do is first of all create a network with individual
> persons as nodes and the co-appearances as edges and the number of
> co-appearances as strenght of interactions clustering closesly related
> people.
>
> In a second step it would be beneficial to extract information on the
> durability of these interactions by including the time difference between
> first and last interaction.
>
> Do you have any ideas or hints how to approach this problem?
>
> Thank you so much,
>
> Hendrik
>
> __
> 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] accessing confidence interval values from the 'predict' function

2015-08-10 Thread Adams, Jean
Avril,

The more direct way to access these columns from the matrix is:

ci[, "lwr"]
ci[, "upr"]

Jean

On Mon, Aug 10, 2015 at 3:20 AM, alc  wrote:

>
>
> Dear all,
>
> I'm wondering how can I access the confidence interval values ('upr' and
> 'lwr' values) produced by the 'predict' function. For example, I fitted
> a linear regression line using:
>
>  fit <- lm(y ~ x)
>
> I then wanted to calculate a 95% confidence interval for the line, and
> did this using:
>
>  ci <- predict(fit, data.frame(x), interval="confidence")
>
> I see that the 'ci' object has 'upr' and 'lwr' variables stored in it,
> but am not sure how to access them properly.
>
> I find I can do it using:
>
>  upper <- as.data.frame(ci)$upr
>  lower <- as.data.frame(ci)$lwr
>
> However, I'm wondering is there a more 'proper' way to do it in R? I
> find that things like ci$upr don't seem to work, but am not sure what's
> the right way?
>
> Kind Regards,
>
> Avril
>
>
>
>
> --
>  The Wellcome Trust Sanger Institute is operated by Genome Research
>  Limited, a charity registered in England with number 1021457 and a
>  company registered in England with number 2742969, whose registered
>  office is 215 Euston Road, London, NW1 2BE.
> [[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] Piecewise (segmented) linear regression with center section slope constraint

2015-08-07 Thread Adams, Jean
This posting on StackOverflow might be useful to you.
http://stackoverflow.com/questions/13810607/in-r-package-segmented-how-could-i-set-the-slope-of-one-of-lines-in-the-model

Jean

On Thu, Aug 6, 2015 at 3:01 PM, Drew Morrison 
wrote:

> Hi,
>
> I'm working on a way to predict the electricity consumption of electrically
> heated buildings as a function of outdoor air temperature. I've identified
> a
> three-segment linear model as a candidate for a good fit, with the slope of
> the center section constrained to zero. I'm working with the segmented
> package. I've searched some of the other posts on this forum and they've
> been very helpful, but they don't address my big sticking point: how do I
> constrain the slope of the center section of the model to 0, rather than
> the
> left or right section?
>
> Below is a script with simulated data and my first attempt at fitting the
> model. You should be able to copy, paste, and run it. Thanks in advance.
> Drew
>
> # three-piece segmented regression
> # center section constrained to slope of 0.
>
>
> # simulate and plot data
> T<- 1:100
> energy<- 100+75*pmax(55-T,0)+25*pmax(T-70,0)+150*rnorm(50)
> plot(T, energy)
>
> # create a linear model
> model <- lm(energy~T)
> #print(summary(model))
>
> # start segmented regression
> library(segmented)
> seg_model <- segmented(model, seg.Z = ~ T, psi = list(T = c(52, 71)))
> print(summary(seg_model))
> print(seg_model$psi)
> print(slope(seg_model))
>
> # plot regression lines
> fitted_energy <- fitted(seg_model)
> regression_model <- data.frame(Temperature = T, kWh = fitted_energy)
> lines(x = T, y = fitted_energy, col = 1)
>
> # try constrained regression
> TT<- -T   # change signs of independent variable
> model <- lm(energy~1)  # constrain slope
> seg_model <- segmented(model, seg.Z = ~ TT, psi = list(TT = c(-71, -52)))
> print(summary(seg_model))
> print(seg_model$psi)
> print(slope(seg_model))
>
> # plot constrained regression
> fitted_energy <- fitted(seg_model)
> regression_model <- data.frame(Temperature = T, kWh = fitted_energy)
> lines(x = T, y = fitted_energy, col = 2)
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Piecewise-segmented-linear-regression-with-center-section-slope-constraint-tp4710839.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> 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] (no subject)

2015-08-06 Thread Adams, Jean
A quick internet search for
 R version history
yielded this page
 https://cran.r-project.org/bin/windows/base/old/

Jean

On Wed, Aug 5, 2015 at 4:55 AM, Djossè Parfait 
wrote:

> Good morning,
>
> I would like to know how often per year is a new full version release of R.
>
>
>
> Thanks
>
> --
> Djossè Parfait BODJRENOU
> Chef de la Division Centralisation et Analyse des Données
> Statistiques /DPP/MESFTPRIJ
>
> [[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] Function returning multiple objects but printing only one

2015-07-14 Thread Adams, Jean
Daniel,

I'm not sure if this is what you're after, but you could include a print()
call in your function.  For example:

myfun <- function(x) {
  m1 <- min(x)
  m2 <- mean(x)
  m3 <- max(x)
  out <- list(m1, m2, m3)
  print(out[[2]])
  return(out)
}

result <- myfun(1:10)

​Jean
​

On Mon, Jul 13, 2015 at 4:06 PM, Daniel Caro  wrote:

> Hello,
>
> Sorry if this has already been addressed before but I could not find any
> helpful references.
>
> I would like to create a function that outputs a single element of a list
> but stores all elements, similar to  'lm' and many other functions. There
> are several answers on how to return multiple objects with lists, for
> example:
>
>
> http://r.789695.n4.nabble.com/How-to-return-multiple-values-in-a-function-td858528.html
>
>
> http://stackoverflow.com/questions/8936099/returning-multiple-objects-in-an-r-function
>
> But the examples show how to print multiple outputs, such as
>
> functionReturningTwoValues <- function() {return(list(first=1, second=2))}
> functionReturningTwoValues()
>
> And I only want the function to print a single element from the list but
> still store the other elements such that they can be retrieved with
> functionReturningTwoValues$first, for example. My function produces
> bootstrap coefficients so clearly I don't want to print the bootstrap
> output but I do want users to be able to access it.
>
> Many thanks,
> Daniel
>
> [[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] A simple question

2015-07-14 Thread Adams, Jean
R-help readers,

For your information ...

The package stringi is required to run Alex's code.

Alex's message was cross posted to StackOverflow, and seems to have been
answered there,
http://stackoverflow.com/questions/31398466/r-stri-locate-all-creating-a-start-and-end-matrix

Jean

On Tue, Jul 14, 2015 at 12:33 AM, Alex Kim via R-help 
wrote:

> Hello,
>
> I am trying to create a matrix that looks like this, using the
> stri_locate_all function.
>
> > x <- "ABCDJAKSLABCDAKJSABCD"
> > m <- stri_locate_all_regex(x, 'ABCD')
> > m
> [[1]]
>  start end
> [1,] 1   4
> [2,]10  13
> [3,]18  21
>
> I tried converting m into a matrix, however it always seems to wrap around
> the wrong way:
>
> > output <- matrix(unlist(m), ncol = 2, byrow = TRUE)
> > output
>  [,1] [,2]
> [1,]1   10
> [2,]   184
> [3,]   13   21
>
> I want to output the start locations in the first column and the end
> locations in the second column into a matrix to look like this.
>
>  [,1] [,2]
> [1,] 1   4
> [2,]10  13
> [3,]18  21
>
> Thank you for your help,
> Alex
>
> [[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] Collecting output of regressions in an intelligent way

2015-06-25 Thread Adams, Jean
Francesca,

You don't provide any example data, so the code that I am provided is
untested, but here is one way to put your commands into a loop.


# define range of p values you want to use
ps <- 6:10
# create an empty list to collect the results
waldchi <- vector("list", length(ps))

# loop through the p values
for(i in seq(ps)) {
  v.p <- VAR(cbind(index1, ma_fin), p=ps[i], type="both")
  print(summary(v.p)
  wald_finp.1 <- wald.test(
b=coef(V.p$varresult[[1]]),
Sigma=vcov(V.p$varresult[[1]]),
Terms=seq(from=2, by=2, length=ps[i]-1))
  waldchi[[i]] <- wald_finp.1$result$chi2
}

# combine the results
wald_fin <- do.call(rbind, waldchi)

Jean


On Thu, Jun 25, 2015 at 4:26 AM, Francesca 
wrote:

> Dear R Contributors
> I am asking for some suggestions on how to organize output of a series of
> regressions and tests in an intelligent way.
> I estimate a series of Var models with increasing numbers of lags and the
> perform a Wald test to control Granger Causality: I would like to learn a
> way to do it that allows me not to produce copy and past code.
>
> This is what I do:
> Estimate var models with increasing number of lags,
>
> V.6<-VAR(cbind(index1,ma_fin),p=6,type="both")
> V.7<-VAR(cbind(index1,ma_fin),p=7,type="both")
> V.8<-VAR(cbind(index1,ma_fin),p=8,type="both")
> V.9<-VAR(cbind(index1,ma_fin),p=9,type="both")
>
> then observe results and control significance of regressors:
>
> summary(V.6)
> summary(V.7)
> summary(V.8)
> summary(V.9)
> summary(V.10)
>
> then use the estimated var to perform the test:
>
> wald_fin7.1<-wald.test(b=coef(V.7$varresult[[1]]),
> Sigma=vcov(V.7$varresult[[1]]), Terms=c(2,4,6,8,10,12))
> wald_fin8.1<-wald.test(b=coef(V.8$varresult[[1]]),
> Sigma=vcov(V.8$varresult[[1]]), Terms=c(2,4,6,8,10,12,14))
> wald_fin9.1<-wald.test(b=coef(V.9$varresult[[1]]),
> Sigma=vcov(V.9$varresult[[1]]), Terms=c(2,4,6,8,10,12,14,16))
> wald_fin10.1<-wald.test(b=coef(V.10$varresult[[1]]),
> Sigma=vcov(V.10$varresult[[1]]), Terms=c(2,4,6,8,10,12,14,16,18))
>
> #then collect tests result in a table:
>
> wald_fin<-rbind(wald_fin7.1$result$chi2,
> wald_fin12.1$result$chi2,wald_fin21.1$result$chi2,
> wald_fin7.2$result$chi2,
> wald_fin12.2$result$chi2,wald_fin21.2$result$chi2)
>
>
> My idea is that it is possible to create all this variable with a loop
> across the objects names but it is a level of coding much higher than my
> personal knowledge and ability.
>
> I hope anyone can help
>
> Thanks in advance
>
>
> --
>
> Francesca
>
> --
> Francesca Pancotto, PhD
> Università di Modena e Reggio Emilia
> Viale A. Allegri, 9
> 40121 Reggio Emilia
> Office: +39 0522 523264
> Web: https://sites.google.com/site/francescapancotto/
> --
>
> [[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] sampling rows with values never sampled before

2015-06-22 Thread Adams, Jean
Mike,

There may be a more efficient way to do this, but this works on your
example.

# mix up the order of the rows
mix <- dat[order(runif(dim(dat)[1])), ]

# get rid of duplicate x1s and x2s
sub <- mix[!duplicated(mix[, "x1"]) & !duplicated(mix[, "x2"]), ]
sub

Jean

On Mon, Jun 22, 2015 at 11:42 AM, C W  wrote:

> Hello R list,
>
> I am have question about sampling unique coordinate values.
>
> Here's how my data looks like
>
> > dat <- cbind(x1 = rep(1:5, 3), x2 = rep(c(3.7, 2.9, 5.2), each=5))
> > dat
>   x1  x2
>  [1,]  1 3.7
>  [2,]  2 3.7
>  [3,]  3 3.7
>  [4,]  4 3.7
>  [5,]  5 3.7
>  [6,]  1 2.9
>  [7,]  2 2.9
>  [8,]  3 2.9
>  [9,]  4 2.9
> [10,]  5 2.9
> [11,]  1 5.2
> [12,]  2 5.2
> [13,]  3 5.2
> [14,]  4 5.2
> [15,]  5 5.2
>
>
> If I sampled (1, 3.7), then, I don't want (1, 2.9) or (2, 3.7).
>
> I want to avoid either the first or second coordinate repeated.  It leads
> to undefined matrix inversion.
>
> I thought of using sampling(), but not sure about applying it to a data
> frame.
>
> Thanks in advance,
>
> Mike
>
> [[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.


[R] ASA Conference on Statistical Practice - deadline Thursday

2015-06-22 Thread Adams, Jean
R users,

Abstracts are now being accepted for the
 2016 ASA Conference on Statistical Practice,
 February 18-20,
 San Diego, CA, USA.

Past conference attendees have shown particular interest in R,
reproducibility, and data visualization.

The deadline for submission is June 25.  Presentations will be 35 minutes
long and fall into four broad themes:
 Communication, Impact, and Career Development
 Data Modeling and Analysis
 Big Data Prediction and Analytics
 Software, Programming, and Graphics

Abstracts may be submitted at
http://www.amstat.org/meetings/csp/2016/abstracts.cfm

Thank you.

Jean V. Adams
on behalf of the ASA-CSP 2016 Steering Committee



`·.,,  ><(((º>   `·.,,  ><(((º>   `·.,,  ><(((º>

Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409  USA
http://www.glsc.usgs.gov
http://profile.usgs.gov/jvadams

[[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] Heatmap.2 error

2015-06-19 Thread Adams, Jean
Pijush,

The error is a result of you having repeated color values.  The warnings
can be addressed by changing the arguments that you use.  Attachments are
removed from posts to R Help, so I used different data to show you an
example.

Jean


library(gplots)

data(mtcars)
x  <- as.matrix(mtcars[1:6, 3:4])
x[1:3, ] <- -x[1:3, ]

colors1 <- c(seq(-170, 0, 10), seq(0, 370, 10))
my_palette1 <- colorRampPalette(c("green", "black",
"red"))(n=length(colors1)-1)
heatmap.2(x, col=my_palette1, breaks=colors1, symkey=FALSE, density.info
="none",
  trace="none", dendrogram="none")

colors2 <- unique(colors1)
my_palette2 <- colorRampPalette(c("green", "black",
"red"))(n=length(colors2)-1)
heatmap.2(x, col=my_palette2, breaks=colors2, symkey=FALSE, density.info
="none",
  trace="none", dendrogram="none")


On Fri, Jun 19, 2015 at 9:02 AM, Pijush Das  wrote:

> Dear Sir,
>
> Please help me solving the error occurring during the execution of the code
> given below.
>
>
> library("openxlsx")
> library(gplots)
> library("RColorBrewer")
>
> rix <- read.xlsx(file.choose(), sheet = 1, colNames = TRUE,rowNames = TRUE)
> rawdata <- data.matrix(rix)
>
>
> colors =
> c(seq(-2,-0.5,length=100),seq(-0.5,1,length=100),seq(1,2,length=100))
> my_palette <- colorRampPalette(c("green", "black", "red"))(n = 299)
>
>  heatmap.2(rawdata, col=my_palette, scale="row",  key=TRUE, symkey=FALSE,
> density.info="none", trace="none", cexRow=0.5, Rowv = FALSE, Colv=FALSE,
> breaks=colors)
>
>
> Error in seq.default(min.raw, max.raw, by = min(diff(breaks)/4)) :  invalid
> (to - from)/by in seq(.)
> In addition: Warning messages:
> 1: In heatmap.2(rawdata, col = my_palette, scale = "row", key = TRUE,  :
>   Using scale="row" or scale="column" when breaks arespecified can produce
> unpredictable results.Please consider using only one or the other.
> 2: In heatmap.2(rawdata, col = my_palette, scale = "row", key = TRUE,  :
>   Discrepancy: Rowv is FALSE, while dendrogram is `none'. Omitting row
> dendogram.
> >
>
> Please find the data set attached with the email.
>
>
> Thanking you.
>
> Regards
> Pijush
> __
> 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] Change Julian function in SPlus to R date code

2015-06-10 Thread Adams, Jean
Try looking at the julian() function in base ...

?julian

Jean

On Wed, Jun 10, 2015 at 2:46 AM, roslinazairimah zakaria <
roslina...@gmail.com> wrote:

> Dear r-users,
>
> I have a code in SPlus which use julian function.  What is the similar code
> used in R?
>
> define.date1<-function(dt1,mt1,mt2,nn,da)
> { mt2<-mt2+1
> start<-julian(mt1, 1, nn, origin=c(month=1, day=1, year=1971))+1
> end<-julian(mt2, 1, nn, origin=c(month=1, day=1, year=1971))+da
> a<-dt1[start:end,]
> am<-as.matrix(a[,5])
> }
>
> I have check the Date package in R but not so sure how to adjust it.
>
> Thank you for any help given.
>
> [[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] Combining multiple probability weights for the sample() function.

2015-06-02 Thread Adams, Jean
Ben,

Perhaps I am missing something, but couldn't you simply reduce your
possibilities to:

possibilities[c(1, 5, 2, 4), ]
 Var1 Var2 Var3
[1,] "A"  "A"  "C"
[2,] "A"  "A"  "T"
[3,] "C"  "A"  "C"
[4,] "C"  "G"  "C"

If you sample from these four rows you will have a 50% chance that Var1 and
Var2 are equal and a 50% chance that Var1 and Var3 are equal.

Jean


On Tue, Jun 2, 2015 at 7:26 AM, Benjamin Ward (ENV) 
wrote:

> Dear R-List,
>
> I have a set of possibilities I want to sample from:
>
> bases <- list(c('A', 'C'), c('A', 'G'), c('C', 'T'))
> possibilities <- as.matrix(expand.grid(bases))
>
> >possibilities
> Var1 Var2 Var3
> [1,] "A"  "A"  "C"
> [2,] "C"  "A"  "C"
> [3,] "A"  "G"  "C"
> [4,] "C"  "G"  "C"
> [5,] "A"  "A"  "T"
> [6,] "C"  "A"  "T"
> [7,] "A"  "G"  "T"
> [8,] "C"  "G"  "T"
>
> If I want to randomly sample one of these rows. If I do this, I find that
> it is 25% likely that my choice will have an identical first and last
> letter (e.g. [1,] "A"  "A"  "C"). It is also 25% likely that my choice will
> have an identical first and third letter (e.g. [4,] "C"  "G"  "C"). It is
> not likely at all that the second and third letter of my choice could be
> identical.
>
> What I would like to do, is sample one of the rows, but given the
> constraint that the probability of drawing identical letters 1 and 2 should
> be 50% or 0.5, and at the same time the probability of drawing identical
> letters 1 and 3 should be 50%. I am unsure on how to do this, but I know it
> involves coming up with a modified set of weights for the sample()
> function. My progress is below, any advice is much appreciated.
>
> Best Wishes,
>
> Ben Ward, UEA.
>
>
> So I have used the following code to come up with a matrix, which contains
> weighting according to each criteria:
>
> possibilities <- as.matrix(expand.grid(bases))
>   identities <- apply(possibilities, 1, function(x) c(x[1] == x[2], x[1]
> == x[3], x[2] == x[3]))
>   prob <- matrix(rep(0, length(identities)), ncol = ncol(identities))
>   consProb <- apply(identities, 1, function(x){0.5 / length(which(x))})
>   polProb <- apply(identities, 1, function(x){0.5 / length(which(!x))})
>   for(i in 1:nrow(identities)){
> prob[i, which(identities[i,])] <- consProb[i]
> prob[i, which(!identities[i,])] <- polProb[i]
>   }
>   rownames(prob) <- c("1==2", "1==3", "2==3")
>   colnames(prob) <- apply(possibilities, 1, function(x)paste(x, collapse =
> ", "))
>
> This code gives the following matrix:
>
> A, A, CC, A, C  A, G, CC, G, C
>  A, A, T C, A, T   A, G, T   C, G, T
> 1==2 0.2500 0.0833 0.0833 0.0833 0.2500 0.0833
> 0.0833 0.0833
> 1==3 0.0833 0.2500 0.0833 0.2500 0.0833 0.0833
> 0.0833 0.0833
> 2==3 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625
> 0.0625 0.0625
>
> Each column is one of the choices from 'possibilities', and each row gives
> a series of weights based on three different criteria:
>
> Row 1, that if it possible from the choices for letter 1 == letter 2, that
> combined chance be 50%.
> Row 2, that if it possible from the choices for letter 1 == letter 3, that
> combined chance be 50%.
> Row 3, that if it possible from the choices for letter 2 == letter 3, that
> combined chance be 50%.
>
> So:
>
>  If I used sample(x = 1:now(possibilities), size = 1, prob = prob[1,])
> repeatedly, I expect about half the choices to contain identical letters 1
> and 2.
>
>  If I used sample(x = 1:now(possibilities), size = 1, prob = prob[2,])
> repeatedly, I expect about half the choices to contain identical letters 1
> and 3.
>
> If I used sample(x = 1:now(possibilities), size = 1, prob = prob[3,])
> repeatedly, I expect about half the choices to contain identical letters 2
> and 3. Except that in this case, since it is not possible.
>
> Note each row sums to 1.
>
> What I would like to do - if it is possible - is combine these three sets
> of weights into one set, that when used with
> sample(x = 1:nrow(possibilities, size = 1, prob = MAGICPROB) will give me
> a list of choices, where ~50% of them contain identical letters 1 and 2,
> AND ~50% of them contain identical letters 1 and 3, AND ~50% again contain
> identical letters 2 and 3 (except in this example as it is not possible
> from the choices).
>
> Can multiple probability weightings be combined in such a manner?
>
>
>
>
> [[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/mailm

Re: [R] Scatterplot : smoothing colors according to density of points

2015-06-02 Thread Adams, Jean
Try this.

Jean

D <- structure(list(
  id = structure(1:6, .Label = c("O13297", "O13329", "O13525",
"O13539", "O13541", "O13547"), class = "factor"),
  X = c(44.44, 31.272085, 6.865672, 14.176245, 73.275862,
28.991597),
  Y = c(21.6122, 4.0159, 2.43884, 7.81217, 3.59012, 258.999)),
  .Names = c("id", "X", "Y"), class = "data.frame",
  row.names = c("1", "2", "3", "4", "5", "6"))

# define the number of colors
ncol <- 100
# define the radius of the neighborhood
distcut <- 30
pal <- colorRampPalette(c("blue", "yellow", "red"))(ncol)

# calculate the euclidean distance between all pairs of points, based on X,
Y coordinates
Ddist <- with(D, as.matrix(dist(cbind(X, Y), diag=TRUE, upper=TRUE)))
# count up the number of neighbors within distcut distance of each point
D$C <- apply(Ddist wrote:

> Hello everyone,
>
> I have a data frame D with 4 columns id,X,Y,C.
> I want to plot a simple scatter plot of D$X vs. D$Y and using D$C values
> as a color. (id is just a text string not used for the plot)
>
> But actually, I don't want to use the raw values of D$C, I would prefer to
> calculate the average values of D$C according to the density of points in a
> fixed neighborhood.
> In other words, I would like to smooth the colors according to the density
> of points.
>
> I am looking for any function,package that could solve this.
> So far, I've been looking at library MASS and the function kde2d which can
> calculate the density of points in 2 directions, but I don't see how I
> could then use this information to recalculate my D$C values.
>
> Here is a piece of the matrix :
>  > head(D)
>   id X YC
> 1 O13297 44.44  21.61220 -0.136651639
> 2 O13329 31.272085   4.01590 -0.117016949
> 3 O13525  6.865672   2.43884 -0.161173913
> 4 O13539 14.176245   7.81217 -0.075756757
> 5 O13541 73.275862   3.59012 -0.006988235
> 6 O13547 28.991597 258.99900 -0.013985507
>
> > dim(D)
> [1] 36164
>
> > apply(D[,-1],2,range)
>X  Y  C
> [1,]   0.3378378 0.0003 -0.738
> [2,] 100.000 24556.4000  0.5582500
> (Y is not linear, so I use log='y' in the plot function)
>
> I used a palette of 100 colors ranging from Blue to Yellow to red.
> >pal =  colorRampPalette(c("blue","yellow","red"))(100)
>
> To make D$C values correspond to a color, I used a cut with the following
> breaks (101 breaks from -1.2 to 1.2):
> > BREAKS
>   [1] -1.2000 -0.8000 -0.4000 -0.3600 -0.3200 -0.2800 -0.2400 -0.2000
> -0.1925
>  [10] -0.1850 -0.1775 -0.1700 -0.1625 -0.1550 -0.1475 -0.1400 -0.1368
> -0.1336
>  [19] -0.1304 -0.1272 -0.1240 -0.1208 -0.1176 -0.1144 -0.1112 -0.1080
> -0.1048
>  [28] -0.1016 -0.0984 -0.0952 -0.0920 -0.0888 -0.0856 -0.0824 -0.0792
> -0.0760
>  [37] -0.0728 -0.0696 -0.0664 -0.0632 -0.0600 -0.0568 -0.0536 -0.0504
> -0.0472
>  [46] -0.0440 -0.0408 -0.0376 -0.0344 -0.0312 -0.0280 -0.0248 -0.0216
> -0.0184
>  [55] -0.0152 -0.0120 -0.0088 -0.0056 -0.0024  0.0008  0.0040  0.0072
> 0.0104
>  [64]  0.0136  0.0168  0.0200  0.0232  0.0264  0.0296  0.0328  0.0360
> 0.0392
>  [73]  0.0424  0.0456  0.0488  0.0520  0.0552  0.0584  0.0616  0.0648
> 0.0680
>  [82]  0.0712  0.0744  0.0776  0.0808  0.0840  0.0872  0.0904  0.0936
> 0.0968
>  [91]  0.1000  0.1250  0.1500  0.1750  0.2000  0.2250  0.2500  0.4875
> 0.7250
> [100]  0.9625  1.2000
> > C.levels = as.numeric(cut(D$C,breaks=BREAKS))
> >length(C.levels)
> [1] 3616
>
> C.levels ranges from 2 to 98 and then to plot the colors I used
> pal[C.levels].
> > plot( x=D$x, y=D$Y, col=pal[ C.levels ],log='y')
>
>
>
> [[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] Really stuck with the nls function!! It's Urgent !!

2015-05-28 Thread Adams, Jean
I can't answer your question, but I can help you get help by re-writing
your code so it's easy for others to see what you're talking about ...

Jean


library(expm)
apinene_modele_prediction <- function(t, theta) {
  x0 = c(100, 0, 0, 0, 0)
  A = matrix(c(
-(theta[1]+theta[2]), theta[1], theta[2], 0, 0,
0, 0, 0, 0, 0,
0, 0, -(theta[3]+theta[4]), theta[3], theta[4],
0, 0, 0, 0, 0,
0, 0, theta[5], 0, -theta[5]
), 5, 5)
  X = x0
  for (i in t[2:length(t)]) {
X = c(X, x0 %*% expm(A*i))
  }
  return(X)
}

t = seq(0, 100, by = 2)
theta = c(0.2, 0.2, 0.2, 0.2, 0.2)
nls(y ~ apinene_modele_prediction(t, theta),
  start = list(theta = c(0.2, 0.2, 0.2, 0.2, 0.2)))
nls(y ~ apinene_modele_prediction(t, c(theta, theta, theta, theta, theta)),
  start = list(theta = 0.2))


On Wed, May 27, 2015 at 6:18 PM, oussama belmejdoub 
wrote:

> Greetings,
>
> I'm trying to use the nls function in my statistics project but I'm really
> finding lot of difficulties.
>
> I have a function called apinene_modele_prediction that calculates the
> estimations:
> library(expm); #exp of a matrixapinene_modele_prediction <-
> function(t,theta)
> {x0=c(100,0,0,0,0);A=matrix(c(-(theta[1]+theta[2]),theta[1],theta[2],0,0,0,0,0,0,0,0,0,-(theta[3]+theta[4]),theta[3],theta[4],0,0,0,0,0,0,0,theta[5],0,-theta[5]),5,5);X=x0;for
> (i in t[2:length(t)]){X=c(X,x0%*%expm(A*i));}return(X);}
>
> My "t" vector is given by:
> t=seq(0,100,by=2)
> And the real observations "y" ara given to us  in a txt file called
> "data.txt" that I have joined to this message.
>
> So when I try to fit the "theta" in my model starting with:
> theta=c(0.2,0.2,0.2,0.2,0.2)
> And doing:
> theta_appr
> <-nls(y~apinene_modele_prediction(t,theta),start=list(theta=c(0.2,0.2,0.2,0.2,0.2)))
> I always get the ERROR : singular gradient matrix at initial parameter
> estimates
>
> And, when I try:
> nls(y~apinene_modele_prediction(t,c(theta,theta,theta,theta,theta)),start=list(theta=0.2))
> I get the result:Nonlinear regression model  model: y ~
> apinene_modele_prediction(t, c(theta,theta,theta,theta,theta))data:
> parent.frame()theta 0.04403residual sum-of-squares: 219002
>
>
> But I need to have the elements of the theta to be different and not equal.
> Thanks in advance for your help.
> __
> 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] ASA Conference on Statistical Practice

2015-05-20 Thread Adams, Jean
R users,

Abstracts are now being accepted for the
 2016 ASA Conference on Statistical Practice,
 February 18-20,
 San Diego, CA, USA.

Past conference attendees have shown particular interest in R,
reproducibility, and data visualization.

The deadline for submission is June 25.  Presentations will be 35 minutes
long and fall into four broad themes:
 Communication, Impact, and Career Development
 Data Modeling and Analysis
 Big Data Prediction and Analytics
 Software, Programming, and Graphics

Abstracts may be submitted at
http://www.amstat.org/meetings/csp/2016/abstracts.cfm

Thank you.

Jean V. Adams
on behalf of the ASA-CSP 2016 Steering Committee



`·.,,  ><(((º>   `·.,,  ><(((º>   `·.,,  ><(((º>

Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409  USA
http://www.glsc.usgs.gov
http://profile.usgs.gov/jvadams

[[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] help with "by" function

2015-05-12 Thread Adams, Jean
Nilesh,

I found a couple errors in your code.  First, in your by() statement you
have a function to operate on the selected subset of data, which you refer
to as
 x
but then, in your aov statement you refer to
 data_set
not
 x

Second, your funC() statement is a function of
 trait_names
but to make sure that the name of the variable is included in the formula,
I changed this to a character variable.

Give the code below a try and see if it works for you.

Jean


library(agricolae)
library(dplyr)

funC <- function(trait_names){
  by(data_set, data_set$Isopair, function(x) {
  mod <- aov(formula(paste(trait_names, "~ STGgroup*Field +
Rep%in%Field")),
data=x)
  out <- HSD.test(mod, "STGgroup", group=TRUE, console=TRUE)
  dfout <- arrange(data.frame(out$groups), desc(trt))
  })
}

funC("Trait1")


On Tue, May 12, 2015 at 1:03 PM, DIGHE, NILESH [AG/2362] <
nilesh.di...@monsanto.com> wrote:

> Hi,
> I have an anonymous function called function(x) that will run anova, run
> HSD.test on the model, and then sort the results.  I am passing this
> anonymous function to the "by" function to get results by "Isopair" factor
> which is my index variable.  Since I want to run the anova on multiple
> dependent variables including "Trait1" & "Trait2", I am calling the
> dependent variable, "trait_names" in the model and then passing the "by"
> function to another function called "funC" which takes the "trait_names" as
> an argument to execute.
>
> After I execute the funC(data_set$trait1), I am getting the results by
> Isopair but the results for the two Isopairs (Isopair-A &Isopair-B) are the
> same which I know is not correct.  It looks like the data is not getting
> split by Isopairs and so ALL data is used in anova for both Isopairs.  Any
> help in modifying function, funC or any other ways to achieve the desired
> outcome will be highly appreciated.
>
> Thanks.  Nilesh
>
> R code, data set, and session info is pasted below.
> R code:
> library(agricolae)
> funC<- function(trait_names){
>   by(data_set, data_set$Isopair,function(x){
>   mod<- aov(trait_names~ STGgroup*Field + Rep%in%Field, data=data_set)
>   out<-HSD.test(mod,"STGgroup",group=TRUE,console=TRUE)
>   dfout<- arrange(data.frame(out$groups),desc(trt))
>   })
> }
> Results:
> ##execute funC function for Trait1 & Trait2
> funC(data_set$Trait1)
>
>
> data_set$Isopair: Isopair-A
>
>   trtmeans M
>
> 1 STG 776.9167 a
>
> 2 Non-STG 779.0833 a
>
> ---
>
> data_set$Isopair: Isopair-B
>
>   trtmeans M
>
> 1 STG 776.9167 a
>
> 2 Non-STG 779.0833 a
>
> Data:
> data_set<- structure(list(Field = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> 2L), .Label = c("LML6", "TZL2"), class = "factor"), Isopair =
> structure(c(1L,
> 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
> 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Isopair-A", "Isopair-B"
> ), class = "factor"), STGgroup = structure(c(1L, 1L, 1L, 2L,
> 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L,
> 1L, 2L, 2L, 2L), .Label = c("Non-STG", "STG"), class = "factor"),
> Rep = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
> 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label =
> c("Rep1",
> "Rep2", "Rep3"), class = "factor"), Trait1 = c(686L, 641L,
> 642L, 727L, 619L, 562L, 808L, 739L, 744L, 873L, 797L, 868L,
> 782L, 783L, 675L, 713L, 762L, 641L, 1009L, 995L, 845L, 1186L,
> 912L, 663L), Trait2 = c(45L, 65L, 70L, 35L, 20L, 80L, 70L,
> 65L, 70L, 20L, 30L, 35L, 40L, 55L, 35L, 40L, 35L, 40L, 40L,
> 35L, 25L, 40L, 35L, 25L)), .Names = c("Field", "Isopair",
> "STGgroup", "Rep", "Trait1", "Trait2"), class = "data.frame", row.names =
> c(NA,
> -24L))
>
> Session info:
>
> R version 3.1.3 (2015-03-09)
>
> Platform: i386-w64-mingw32/i386 (32-bit)
>
> Running under: Windows 7 x64 (build 7601) Service Pack 1
>
>
>
> locale:
>
> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
> States.1252
>
> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
>
> [5] LC_TIME=English_United States.1252
>
>
>
> attached base packages:
>
> [1] grid  stats graphics  grDevices utils datasets  methods
>  base
>
>
>
> other attached packages:
>
>  [1] gridExtra_0.9.1 Hmisc_3.16-0Formula_1.2-1   survival_2.38-1
> caret_6.0-41ggplot2_1.0.1
>
>  [7] lattice_0.20-30 MASS_7.3-39 dplyr_0.4.1 agricolae_1.2-1
>
>
>
> loaded via a namespace (and not attached):
>
>  [1] acepack_1.3-3.3 assertthat_0.1  boot_1.3-15
>  BradleyTerry2_1.0-6
>
>  [5] brglm_0.5-9 car_2.0-25  cluster_2.0.1
>  coda_0.17-1
>
>  [9] codetools_0.2-10colorspace_1.2-6combinat_0.0-8  DBI_0.3.1
>
> [13] deldir_0.1-9digest_0.6.8foreach_1.4.2
>  foreign_0.8-63
>
> [17] gtable_0.1.2gtools_3.4.1iterators_1.0.7
>  klaR_0.6-12
>
> [21] l

Re: [R] How to finding a given length of runs in a series of data?

2015-05-07 Thread Adams, Jean
Two libraries are needed to run the code you submitted ...

library(dplyr)
library(sqldf)

Your IsHigh() function and its use can be replaced by a single line of code

isHighFlow <- as.numeric(Flow>=1600)

You are getting the additional hour by using cumsum().  One date element
which you seem to characterize as zero hours returns a one in cumsum, two
returns two, etc.
cumsum(c(1, 0, 1, 1, 0, 1, 1, 1, 0))

If everything is off by one hour, just subtract a 1.  Problem solved.

Jean


On Wed, May 6, 2015 at 5:55 PM, jcrosbie  wrote:

> I'm trying to study times in which flow was operating at a given level or
> greater. To do so I have created a way to see how long the series has
> operated at a high level. But for some reason the data is calculating the
> runs one hour to long. Any ideas on why?
>
>
>
>
>
> Code:
> Date<-format(seq(as.POSIXct("2014-01-01 01:00"), as.POSIXct("2015-01-01
> 00:00"), by="hour"), "%Y-%m-%d %H:%M", usetz = FALSE)
> Flow<-runif(8760, 0, 2300)
>
> IsHigh<- function(x ){
> if (x < 1600) return(0)
> if (1600 <= x) return(1)
> }
>
> isHighFlow = unlist(lapply(Flow, IsHigh))
>
> df = data.frame(Date, Flow, isHighFlow )
>
>
> temp <- df %>%
>   mutate(highFlowInterval = cumsum(isHighFlow==0)) %>%
>   group_by(highFlowInterval) %>%
>   summarise(hoursHighFlow = n(), minDate = min(as.character(Date)), maxDate
> = max(as.character(Date)))
>
> #Then join the two tables together.
> temp2<-sqldf("SELECT *
>   FROM temp LEFT JOIN df
>   ON df.Date BETWEEN temp.minDate AND temp.maxDate")
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/How-to-finding-a-given-length-of-runs-in-a-series-of-data-tp4706915.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> 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] Run Rscript and ignore errors?

2015-04-26 Thread Adams, Jean
Nick,

I don't know of a way to do what you want ... tell R to ignore all errors
... but, I do have a suggestion.

Since you regard these errors as "non-essential", why not edit your code to
reflect that?  For example, instead of writing
 plot(df$x1, df$y1)
write
 if ("x1" %in% names(df) & "y1" %in% names(df)) plot(df$x1, df$y1)

... or something like that.

Jean

On Thu, Apr 23, 2015 at 12:28 PM, Nick Matzke  wrote:

> Hi R-help,
>
> I've looked at google, the Rscript documentation and the Rscript --help
> output and haven't found much on this.  So, here's my question:
>
> I have a rather long script that runs on various input datasets.  It is
> quite convenient to run the script from the Terminal command line with
> "Rscript scriptname.R"
>
> However, some datasets will cause errors. These are non-essential errors --
> just some datasets don't have certain columns so certain parts of the
> overall analysis don't produce figures etc.  Yes, I could go through the
> whole script and insert try() statements, etc.  But I'm lazy.
>
> So, is there a way to run Rscript or something similar, and just have it
> ignore all errors (i.e., keep running through the script)?  I.e., just like
> what happens if you just copy-paste the whole script into the R window --
> errors happen and are noted but the rest of the script keeps running.
>
> Thanks very much for any help!!
>
> Cheers!
> Nick
>
> [[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] Script to workflow conversion

2015-04-22 Thread Adams, Jean
Santosh,

I know nothing about this personally, but I found this site with an
internet search.
http://www.ef-prime.com/products/ranalyticflow_en/features.html

Jean

On Wed, Apr 22, 2015 at 5:20 PM, Santosh  wrote:

> Dear Rxperts..
>
> Sorry.. i don't have data for my query..
>
> Is there a way that an R script can be converted to a workflow? or if not a
> workflow, converted into a flowchart or anything close to that effect.
>
>
> Regards,
> Santosh
>
> [[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] help assigning values to matrix

2015-04-14 Thread Adams, Jean
I think it would be easier to keep track of what you're doing, if you save
the assignment to the very end of your for() loop.  For example ...

# create an empty matrix to be used as a template
Mtemplate <- matrix(data=NA, nrow=13, ncol=3,
dimnames=list(c(10,20,30,35,40,50,60,70,80,90,100,120,999),
  c("col1", "col2", "col3")))

# create as many 13x3 matrices as vectors I have.
for (j in 1:length(mynames)){

  # do all your work with the matrix Mnew
  Mnew <- Mtemplate
  # The rowname of the last row will be the length of the vector
  dimnames(Mnew)[[1]][dim(Mnew)[1]] <- length(get(mynames[j]))

  # Example: assign three values in the last row of the created matrices
  Mnew[13, ] <- c(3, 4, 5)

  # then, when you're all done, assign Mnew to the name you want to keep
  Mname <- paste("results", mynames[j], 1, sep="_")
  assign(Mname, Mnew)

}

Jean

On Tue, Apr 14, 2015 at 5:48 AM, David  wrote:

>
>
> Hi group,
>
> I am automatically creating several matrices to store results from
> different analyses on vectors of different lengths. The matrices are named
> according  to each vector, so I can trace back results. I am using the
> following commands, which give me an error. My idea is to populate the for
> loop to include several steps and keep adding results to the matrices. But
> to start with:
>
> > ls()
> [1] "PS013_1" "PS056_1" "PS058_1" "PS080_1" "PS117_1" "PS193_1" "PS194_1"
>
> > mynames<- c("PS013","PS056","PS058","PS080","PS117","PS193","PS194")
>
> > for (j in 1:length(mynames)){
>
> #create as many 13x3 matrices as vectors I have. The rowname of the last
> row will be the length of the vector
> >
> assign(paste("results",mynames[j],"1",sep="_"),matrix(data=NA,nrow=13,ncol=3,dimnames
> =
> list(c(10,20,30,35,40,50,60,70,80,90,100,120,print(length(get(paste(mynames[j],1,sep="_"),c("col1","col2","col3"
>
> # Example: assign three values in the last row of the created matrices
> >assign(paste("results",mynames[j],"1",sep="_")[13,],c(3,4,5))
>
> }
>
> Error in paste("results", mynames[j], "1", sep = "_")[13, ] :
>   incorrect number of dimensions
>
>
> I have noticed that to access the positions of a matrix I cannot use
> [row,column] coordinates, but actual "count" positions like:
>
> #let's write something  in one of the matrices, since they are all NAs
> > results_PS013_1[1,]<-c(1,14,27)
> > get(paste("results",mynames[1],"1",sep="_"))
> col1 col2 col3
> 10  1 14 27
> 20  NA NA  NA
> 30  NA NA  NA
> 35  NA NA  NA
> 40  NA NA  NA
> 50  NA NA  NA
> 60  NA NA  NA
> 70  NA NA  NA
> 80  NA NA  NA
> 90  NA NA  NA
> 100 NA NA  NA
> 120 NA NA  NA
> 295 NA NA  NA
>
> > get(paste("results",mynames[1],"1",sep="_"))[1]
> [1] 1
> > get(paste("results",mynames[1],"1",sep="_"))[2]
> [1] NA
> > get(paste("results",mynames[1],"1",sep="_"))[14]
> [1] 14
> > get(paste("results",mynames[1],"1",sep="_"))[c(1,14,27)]
> [1] 114   27
>
> So if I try to write three other values to the first row of the first
> matrix, I now try the following
>
> > assign(get(paste("results",mynames[1],"1",sep="_"))[c(1,14,27)],c(3,4,5))
> Error in assign(get(paste("results", mynames[1], "1", sep = "_"))[c(1,  :
>   invalid first argument
>
>
> Can anyone explain to me why I cannot assign the values in this way and
> how is it that I cannot use [row,column] coordinates?
>
> Thanks in advance for your help
>
> Dave
>
>
> [[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] Sum of some months totals

2015-04-14 Thread Adams, Jean
If you want to calculate the number of days having greater than a certain
threshold of rain within a range of months, a function like this might
serve your needs.

raindays <- function(data, monStart=1, monEnd=3, threshold=0.85) {
  with(data, {
selRows <- Month >= monStart & Month <= monEnd & Rain > threshold
days <- tapply(selRows, Year, sum)
return(days)
  })
}

raindays(kitale)

Jean

On Tue, Apr 14, 2015 at 2:46 AM, Frederic Ntirenganya 
wrote:

> I want to compute monthly summaries from daily data. I want to choose which
> month to start and how many months to total over.  Default could be to
> start in January and total over 3 months.  For the number of rain days the
> default threshold is 0.85mm.
>
> I tried to make a function which sum all months not some of months. I will
> appreciate any help from you guys. Thanks.
> Here is the data and the code I used.
>
> > dput(head(kitale))structure(list(Year = c(1979L, 1979L, 1979L, 1979L,
> 1979L, 1979L
> ), Month = c(1L, 1L, 1L, 1L, 1L, 1L), Day = 1:6, Rain = c(0,
> 0, 0, 0, 0, 0)), .Names = c("Year", "Month", "Day", "Rain"), row.names =
> c(NA,
> 6L), class = "data.frame")
>
> here is the function:
>
> total = function(data, threshold = 0.85){
>   month_tot=matrix(NA,31,12)
>   rownames(month_tot)=as.character(1979:2009)
>
> colnames(month_tot)=c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
>   raindays=month_tot
>   # loop over months and years to get summary statistics
>   for (mon in 1:12) {
> rain=data[data[2]==mon,c(1,4)]   # rain just for a specific month
> for (yr in 1979:2009) {
>   month_tot[yr-1978,mon]=sum(rain[rain[,1]==yr,2])
>   raindays[yr-1978,mon]=sum(rain[rain[,1]==yr,2]>threshold)
> }
>   }
>   month_tot
> }
>
> Regards,
>
> Frederic.
>
>
>
> Frederic Ntirenganya
> Maseno University,
> African Maths Initiative,
> Kenya.
> Mobile:(+254)718492836
> Email: fr...@aims.ac.za
> https://sites.google.com/a/aims.ac.za/fredo/
>
> [[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] mutiple data sets

2015-04-13 Thread Adams, Jean
You should cc r-help in your reply to keep everyone in the loop.

Jean

On Mon, Apr 13, 2015 at 8:02 AM, rsm  wrote:

>  Hi Jean
> Truly appreciate your guidance.
> honestly, finding it bit challenging to plot.
> before plotting.
> i have some basic q.
> have multiple data sets spanning over 15 years of One Y , the Independent,
> X about 30 dependent variables.
> am trying to build a forecasting program for Y , given changes in X.
> any thoughts, or documents that can help me do this step by step.
> am going thru the videows and documents, but not getting hang of managing
> the panel data concept.
>
> Thank you very much
>
> Regards
>
> Ravishankar Mantha
>
>
> On 4/13/2015 6:24 PM, Adams, Jean wrote:
>
>  There are some examples of how to plot correlation matrices at this
> link.
>
>
> http://stackoverflow.com/questions/5453336/plot-correlation-matrix-into-a-graph/26637268#26637268
>
> Perhaps that will help get you started.
>
>  Jean
>
> On Mon, Apr 13, 2015 at 5:11 AM, ravimantha  wrote:
>
>> Hi just started in R, this is the first time.
>>
>> I have one Y & Multiple X variables.
>> was trying to do Correlation, managed it using cov( Y,X)
>> unable to plot the above.
>>
>> further since the data sets is very large of about 20 years * 30
>> variables,
>> end objective is to build a forecasting model Y.
>> have managed to do this , using excel, but its maddness, so thought will
>> use
>> R.
>>
>> Your help will be much appreciated please.
>>
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/mutiple-data-sets-tp4705763.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> 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] mutiple data sets

2015-04-13 Thread Adams, Jean
There are some examples of how to plot correlation matrices at this link.

http://stackoverflow.com/questions/5453336/plot-correlation-matrix-into-a-graph/26637268#26637268

Perhaps that will help get you started.

Jean

On Mon, Apr 13, 2015 at 5:11 AM, ravimantha  wrote:

> Hi just started in R, this is the first time.
>
> I have one Y & Multiple X variables.
> was trying to do Correlation, managed it using cov( Y,X)
> unable to plot the above.
>
> further since the data sets is very large of about 20 years * 30 variables,
> end objective is to build a forecasting model Y.
> have managed to do this , using excel, but its maddness, so thought will
> use
> R.
>
> Your help will be much appreciated please.
>
>
>
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/mutiple-data-sets-tp4705763.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> 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] operations on columns when data frames are in a list

2015-04-13 Thread Adams, Jean
If you write a function that takes a data frame as an argument and returns
a data frame, you can use lapply to carry out the tasks that you want.  For
example, if your list of data frames is called mydat ...

mon2date <- function(df) {
  if ("Month" %in% names(df)) {
df$Month<- as.POSIXct(df$Month, format="%Y/%m/%d")
  }
  return(df)
}

mydat2 <- lapply(mydat, mon2date)

Jean

On Sun, Apr 12, 2015 at 5:30 PM, Steve E.  wrote:

> Hello R folks,
>
> I have recently discovered the power of working with multiple data frames
> in
> lists. However, I am having trouble understanding how to perform operations
> on individual columns of data frames in the list. For example, I have a
> water quality data set (sample data included below) that consists of
> roughly
> a dozen data frames. Some of the data frames have a chr column called
> 'Month' that I need to to convert to a date with the proper format. I would
> like to iterate through all of the data frames in the list and format all
> of
> those that have the 'Month' column. I can accomplish this with a for-loop
> (e.g., below) but I cannot figure out how to do this with the plyr or apply
> families. This is just one example of the formatting that I have to perform
> so I would really like to avoid loops, and I would love to learn how to
> better work with lists as well.
>
> I would appreciate greatly any guidance.
>
>
> Thank you and regards,
> Stevan
>
>
> a for-loop like this works, but is not an ideal solution:
>
> for (i in 1:length(data)) {if ("Month" %in% names(data[[i]]))
> data[[i]]$Month<- as.POSIXct(data[[i]]$Month, format="%Y/%m/%d")}
>
>
>
> sample data (head of two data frames from the list of all data frames):
>
> structure(list(`3D_Fluorescence.csv` = structure(list(ID = 1:6,
> Site_Number = c("R5", "R6a", "R8", "R9a", "R14", "R15"),
> Month = c("2001/10/01", "2001/10/01", "2001/10/01", "2001/10/01",
> "2001/10/01", "2001/10/01"), Exc_A = c(215L, 215L, NA, NA,
> 215L, 215L), Em_A = c(422.5, 410.5, NA, NA, 408.5, 408),
> Fl_A = c(303, 296.86, NA, NA, 297.62, 174.75), Exc_B = c(325L,
> 325L, NA, NA, 325L, 325L), Em_B = c(416, 413, NA, NA, 418.5,
> 417.5), Fl_B = c(137.32, 116.1, NA, NA, 132.48, 77.44)), .Names =
> c("ID",
> "Site_Number", "Month", "Exc_A", "Em_A", "Fl_A", "Exc_B", "Em_B",
> "Fl_B"), row.names = c(NA, 6L), class = "data.frame"), algae.csv =
> structure(list(
> ID = 1:6, SiteNumber = c("R1", "R2A", "R2B", "R3", "R4",
> "R5"), SiteLocation = c("CAP canal above Waddell Canal",
> "Lake Pleasant integrated sample", "Lake Pleasant integrated sample",
> "Waddell Canal", "Cap Canal at 7th St.", "Verde River btwn Horseshoe
> and
> Bartlett"
> ), ClusterName = c("cap", "cap", "cap", "cap", "cap", "verde"
> ), SiteAcronym = c("cap-siphon", "pleasant-epi", "pleasant-hypo",
> "waddell canal", "cap @ 7th st", "verde abv bartlett"), Date =
> c("1999/08/18",
> "1999/08/18", "1999/08/18", "1999/08/18", "1999/08/18", "1999/08/16"
> ), Month = c("1999/08/01", "1999/08/01", "1999/08/01", "1999/08/01",
> "1999/08/01", "1999/08/01"), SampleType = c("", "", "", "",
> "", ""), Conductance = c(800, 890, 850, 870, 830, 500), ChlA = c(0.3,
> 0.3, 0.6, 0.8, 1.1, 7.6), Phaeophytin = c(0, 0, 0, 0, 0.7,
> 4.7), PhaeophytinChlA = c(0.7, 0.7, 1.3, 5.3, 0.7, 4.7),
> Chlorophyta = c(0L, 0L, 18L, 0L, 0L, 21L), Cyanophyta = c(8L,
> 0L, 0L, 0L, 7L, 79L), Bacillariophyta = c(135L, 76L, 0L,
> 18L, 54L, 195L), Total = c(147L, 76L, 18L, 18L, 61L, 302L
> ), AlgaeComments = c("", "", "", "", "", "")), .Names = c("ID",
> "SiteNumber", "SiteLocation", "ClusterName", "SiteAcronym", "Date",
> "Month", "SampleType", "Conductance", "ChlA", "Phaeophytin",
> "PhaeophytinChlA", "Chlorophyta", "Cyanophyta", "Bacillariophyta",
> "Total", "AlgaeComments"), row.names = c(NA, 6L), class = "data.frame")),
> .Names = c("3D_Fluorescence.csv",
> "algae.csv"))
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/operations-on-columns-when-data-frames-are-in-a-list-tp4705757.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> 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] problem in replication

2015-04-13 Thread Adams, Jean
Why did you submit this post?
Are you asking for help with something?
Reporting an update on an earlier post?

Jean

On Mon, Apr 13, 2015 at 5:43 AM, thanoon younis 
wrote:

> Hi
> I have a small problem with my code in R. The problem is the replication of
> simulation didn't work as a sequence from r=1 to 100 but the results stop
> at 1 and when i close the first results with r=1 the second results run and
> so on. i want to leave my computer to run until finish 100 replication In
> chronological order.
>
> Many thanks
>
> --
> Thanoon Y. Thanoon
> PhD Candidate
> Department of Mathematical Sciences
> Faculty of Science
> University Technology Malaysia, UTM
> E.Mail: thanoon.youni...@gmail.com
> E.Mail: dawn_praye...@yahoo.com
> Facebook:Thanoon Younis AL-Shakerchy
> Twitter: Thanoon Alshakerchy
> H.P:00601127550205
>
> [[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] How to complete this code

2015-04-13 Thread Adams, Jean
You will likely get more help answering your question if you provide
reproducible code of a simple example of your situation.

Jean

On Fri, Apr 10, 2015 at 3:42 PM, Mahdiyeh Erfaniyan <
mahdiyeh.erfani...@gmail.com> wrote:

> Hi,
>
>
> Consider the line below:
>
>
>
> for(r in a)for (s in a) x=rbind(x,apply(replicate(1000,V(r,s)),1,mean))
>
>
>
> V is a vector of (n-1) variables calculated by some rule and is a functions
> of (r,s).  So the line above produces 1000 replicates of V for each (r,s),
> puts them in a matrix, calculates the mean of them, and finally puts the
> means for all (r,s) in a matrix. So the produced matrix, x, is the mean of
> (n-1) V 's for each possible value of (r,s) in each row. Now for simplicity
> fix (r,s) in just one point and let n=5. So in each replicate we have only
> one V which is a vector consisted of 4 variables. Name the elements of V as
> U1, U2, U3 and U4. Then we can let
>
> V(i) = [U1i , U2i , U3i , U4i]
>
>
>
> which shows each row of V produced per replicate (i=1,2,...,1000).
> Therefore we can say
>
>
>
> x=[x1 , x2 , x3 , x4]
>
>
>
> which is the vector of means calculated at the end. Now what I need is to
> first calculate the vector below per replicate (i=1,...,1000):
>
>
>
> Er(i) = [ |Ui1-x1| , |Ui2-x2| , |Ui3-x3| , |Ui4-x4| ]
>
>
>
> where |A| shows the absolute value of A. Then I should calculate mean of
> Er(i) 's and put the result in a vector. I just don't know how I can
> calculate Er(i) 's in the given line above. On the other words, I don't
> know where I should add the required code in the given line. Thanks for any
> help in advance!
>
> [[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] BIG difficulties in Using boot.ci (bot package)

2015-04-13 Thread Adams, Jean
S,

There is no mention of a type="bca" argument on the ?confint help file.

You can look here for an example of using the boot.ci() function in the
boot package:

http://www.statmethods.net/advstats/bootstrapping.html

​Jean​


On Fri, Apr 10, 2015 at 11:01 AM, varin sacha  wrote:

> Dear R-Experts,
>
> I am trying to compute the BCa nonparametric bootstrap on regression
> coefficients.
>
> Here is the reproducible example :
>
> GDP.LOG <-c(14,12,13,15.5,16,17,16.5,13.5,12.5,12)
> Quality.score <-c(12,11,13,14,15,16,12,10,9,9)
> Competitivness.score=c(8,6,7,5,6.5,7,8,4.5,6,7)
> fit <- lm(formula = GDP.LOG ~ Quality.score + Competitivness.score)
> confint(fit, level=.95)
> confint.default(fit, level=.95)
> confint(fit,level=.95,type="bca")
>
> I am not sure but I think that I can not get the nonparametric BCa
> bootstrap with the confint function. As you can see, I have tried the
> argument type="bca", I don’t get any error message, but the results don’t
> change, the results are exactly the same as confint(fit,level=.95).
> As I have understood, the default argument uses normal quantiles and the
> method for linear models uses T-quantiles instead.
> So, I have checked the boot package and the boot.ci function to calculate
> the BCa bootstrap on the regression coefficients, but I don’t really
> understand how to compute the code.
> So, any help from you would be highly appreciated.
>
> Best,
> S
>
> __
> 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] Color US counties on US map using a numeric variable for color intensity

2015-04-03 Thread Adams, Jean
Dimitri,

To answer your questions:
The colorRamp() function creates a new function, newpal().
The value returned by newpal() is a numeric matrix of RGB color values.
The rgb() function is then used to convert this numeric matrix to colors,
with the argument maxColorValue
giving the maximum of the color values range.  Typically either 255 or 1.
See the help files for more information

?colorRamp
?rgb


I think Jim Lemon's suggestion to use color.scale() function is a handier
solution.

Jean

On Thu, Apr 2, 2015 at 6:05 PM, Dimitri Liakhovitski <
dimitri.liakhovit...@gmail.com> wrote:

> This is really cool, Jim - thanks a lot!
>
> On Thu, Apr 2, 2015 at 6:18 PM, Jim Lemon  wrote:
> > Hi Dimitri,
> > You can also try the color.scale function in plotrix, which allows you to
> > specify the NA color in the call.
> >
> >
> newcol<-color.scale(mydata.final$Mean.Wait,extremes=c("yellow","red"),na.color="white")
> >
> > Jim
> >
> >
> > On Fri, Apr 3, 2015 at 8:08 AM, Dimitri Liakhovitski
> >  wrote:
> >>
> >> Jean, I think I fixed it:
> >>
> >> newpal <- colorRamp(c("yellow", "red"))
> >> missing <- is.na(mydata.final$Mean.Wait)
> >> newcol <- ifelse(missing, "white",
> >>
> >> rgb(newpal(mydata.final$Mean.Wait[!is.na(mydata.final$Mean.Wait)]/
> >>   max(mydata.final$Mean.Wait,
> >> na.rm=T)), maxColorValue=255))
> >> map('county', fill=TRUE, col=newcol,
> >> resolution=0, lty=0, bg="transparent")
> >> map('state', lwd=1, add=TRUE)
> >>
> >> One understanding question: what exactly does this rgb line do and why
> >> do we have to say "maxColorValue=255"?
> >> Thank you!
> >>
> >> On Thu, Apr 2, 2015 at 5:02 PM, Dimitri Liakhovitski
> >>  wrote:
> >> > Thank you, Jean, but I think this newcol line is not working. I am
> >> > running:
> >> >
> >> > newcol <- ifelse(missing, "white",
> >> >
> >> > rgb(newpal(mydata.final$Mean.Wait/max(mydata.final$Mean.Wait,
> >> > na.rm=T)),
> >> >  maxColorValue=255))
> >> >
> >> > # And I am getting:
> >> > Error in rgb(newpal(mydata.final$Mean.Wait/max(mydata.final$Mean.Wait,
> >> > :
> >> >   color intensity NA, not in 0:255
> >> >
> >> > I think it's not liking the NAs - despite the ifelse...
> >> >
> >> > On Thu, Apr 2, 2015 at 4:26 PM, Adams, Jean  wrote:
> >> >> Dimitri,
> >> >>
> >> >> You could use colorRamp() and rgb() to get more continuous colors.
> >> >> For example
> >> >>
> >> >> newpal <- colorRamp(c("yellow", "red"))
> >> >> missing <- is.na(mydata.final$Mean.Wait)
> >> >> newcol <- ifelse(missing, "white",
> >> >>   rgb(newpal(mydat$Mean.Wait/max(mydat$Mean.Wait)),
> maxColorValue=255))
> >> >> map('county', fill=TRUE, col=newcol,
> >> >> resolution=0, lty=0, bg="transparent")
> >> >> map('state', lwd=1, add=TRUE)
> >> >>
> >> >> Jean
> >> >>
> >> >>
> >> >> On Thu, Apr 2, 2015 at 12:03 PM, Dimitri Liakhovitski
> >> >>  wrote:
> >> >>>
> >> >>> I have a data frame 'mydata.final' (see below) that contains US
> >> >>> counties and a continuous numeric variable 'Mean.Wait' that ranges
> >> >>> from zero to 10 or so. I also created variable 'wait' that is based
> on
> >> >>> the 'Mean.Wait' and takes on discrete values from 1 (lowest values
> on
> >> >>> 'Mean.Wait') to 5 (highest values on 'Mean.Wait').
> >> >>>
> >> >>> I can create a map of the US with the counties colored based on the
> >> >>> values of 'wait' using R package 'maps':
> >> >>>
> >> >>> #
> >> >>> ### Generating an artificial data file:
> >> >>> #
> >> >>> library(maps)
> >> >>> mydata.final <- data.frame(county = (map('

Re: [R] Color US counties on US map using a numeric variable for color intensity

2015-04-02 Thread Adams, Jean
Dimitri,

You could use colorRamp() and rgb() to get more continuous colors.
For example

newpal <- colorRamp(c("yellow", "red"))
missing <- is.na(mydata.final$Mean.Wait)
newcol <- ifelse(missing, "white",
  rgb(newpal(mydat$Mean.Wait/max(mydat$Mean.Wait)), maxColorValue=255))
map('county', fill=TRUE, col=newcol,
resolution=0, lty=0, bg="transparent")
map('state', lwd=1, add=TRUE)

Jean


On Thu, Apr 2, 2015 at 12:03 PM, Dimitri Liakhovitski <
dimitri.liakhovit...@gmail.com> wrote:

> I have a data frame 'mydata.final' (see below) that contains US
> counties and a continuous numeric variable 'Mean.Wait' that ranges
> from zero to 10 or so. I also created variable 'wait' that is based on
> the 'Mean.Wait' and takes on discrete values from 1 (lowest values on
> 'Mean.Wait') to 5 (highest values on 'Mean.Wait').
>
> I can create a map of the US with the counties colored based on the
> values of 'wait' using R package 'maps':
>
> #
> ### Generating an artificial data file:
> #
> library(maps)
> mydata.final <- data.frame(county = (map('county', plot = FALSE)$names),
>  stringsAsFactors = F)
>
> ### My numeric variable:
> set.seed(123)
> mydata.final$Mean.Wait <- runif(nrow(mydata.final)) * 10
>
> ### Introducing NAs to mimic my real data set:
> set.seed(1234)
> mydata.final$Mean.Wait[sample(1:nrow(mydata.final), 1500)] <- NA
>
> ### Cutting the original numeric variable into categories
> ### because I don't know how to color based on 'Mean.Wait':
> mydata.final$wait <- cut(mydata.final$Mean.Wait, breaks = 5)
> levels(mydata.final$wait) <- 1:5
> mydata.final$wait <- as.numeric(as.character(mydata.final$wait))
>
> 
> Building a US map based on 'wait' (5 categories)
> #
>
> ### Creating my 5 colors:
> pal <- colorRampPalette(c("yellow", "red"))
> allcolors <- pal(5)
>
> ### Looking at my 5 colors:
> barplot(1:5, rep(1,5), col = allcolors, horiz = T)
>
> ### Builiding the US map using 5 categories in 'wait':
> map('county', fill = TRUE, col = allcolors[mydata.final$wait],
> resolution = 0, lty = 0, bg = "transparent")
> map('state', lwd=1, add=TRUE)
>
> My goal is: instead of splitting 'Mean.Wait' into 5 ordered categories
> ('wait'), I'd like to color the counties on the map based on the
> intensity of my (continuous) 'Mean.Wait'. What would be the way to do
> it and maybe even to add a legend?
> Thanks a lot!
>
> --
> Dimitri Liakhovitski
>
> __
> 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] Calculating different PCAs in R

2015-04-01 Thread Adams, Jean
PCA 1, 2, and 3 refer to the scores not the loadings.
Check out the help for princomp.

?princomp

pc.cr <- princomp(USArrests, cor = TRUE)
pc.cr$scores[1:3, ]

Jean


On Tue, Mar 31, 2015 at 4:26 PM, im db  wrote:

> Dear All, I want to use princomp() function in R in order to calculate
> Principle Component Analysis.In different papers, I have seen "PCA 1", "PCA
> 2", "PCA 11" , etc. Would you please tell me how can i calculate different
> PCAs in R?At the moment i just use this line "eigenVectors <-
> pca$loadings"But I don’t know if it is correct to use loadings.Thank you in
> advance.  Best regards,
> Iman Dabbaghi
>
> [[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] how to deal with changing weighting functions

2015-03-31 Thread Adams, Jean
Can you give a concrete simple example of inputs with expected results?  Is
phi a function?  Of omega 1 and 2?  Is the summation over everything
through V_d-k?

On Mon, Mar 30, 2015 at 2:58 PM, T.Riedle  wrote:

> Hi everybody,
> Does anybody have an idea how I can generate tau according to the attached
> formula? The point is that phi changes with k and I thought I could make it
> by using a for-function in R but I am not sure how to do that.
>
> Could anyone help me?
> Thanks in advance.
>
>
> __
> 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] automatic coercicion

2015-03-21 Thread Adams, Jean
>From one Jean to another ... A[i, , drop=FALSE]

On Sat, Mar 21, 2015 at 6:04 AM,  wrote:

> My question must be a trivial one.
>
> There is automatic coercicion to vector when extracting only one line of a
> matrix.
> # example
> A = matrix(1:12,3,4)
> rownames(A) = c('a1','a2','a3')
>
> i = 1:2
> A[i,]
> #[,1] [,2] [,3] [,4]
> # a1147   10matrix
> # a2258   11
>
> i = 1
> A[i,]
> # [1]  1  4  7 10   vector !!!
>
> # to get the rowname, it is necessary to do
> rownames(A)[i]
> # [1] "a1"
>
> Is it possible to get a (1,4)-matrix (without testing length(i) ) ? I see
> nothing in options()...
>
> Jean Coursol
>
> __
> 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] Plotting straight line

2015-03-16 Thread Adams, Jean
Something like this might help you get started.

x <- seq(-5, 5, 1)
m <- seq(0.5, 5, 0.5)
plot(0, 0, type="n", xlab="", ylab="", xlim=range(x), ylim=range(outer(m,
x)+1))
invisible(lapply(m, function(slope) abline(1, slope)))

Jean

On Sun, Mar 15, 2015 at 11:03 PM, Partha Sinha  wrote:

> I want to plot a straight line where y=m*x+1 (where x varying from -5
> to +5) and and m will change from 0.5 to 5. All the straight lines
> needs to be overlaid.
> Thanks
> Parth
>
> __
> 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] automate "press enter"

2015-03-12 Thread Adams, Jean
Harold,

This did the trick for my application,

options(httr_oauth_cache=TRUE)


See
http://stackoverflow.com/questions/28221405/automated-httr-authentication-with-twitter-provide-response-to-interactive-pro
for details.

Jean

On Thu, Mar 12, 2015 at 10:25 AM, Doran, Harold  wrote:

> I’m dealing with an issue that is seemingly simple, and I’m sure there is
> an obvious solution. I’m writing a wrapper function that calls functions
> from another package (twitteR).
>
> However, the function I happen to be using in that package prompts the
> user the user to enter a “1” or a “2” in the workspace before the user can
> proceed. The actual process looks like this:
>
> > setup_twitter_oauth(APIkey,APIsecret, Accesstoken, Accesssecret)
>
> Use a local file to cache OAuth access credentials between R sessions?
> 1: Yes
> 2: No
>
> I know I want the value  “2” to be entered, but I cannot figure out how to
> automate it without a human actually entering “2” and hitting enter when
> prompted.
>
> Is it possible to automate this so the user doesn’t have to manually hit
> enter?
>
> Harold
>
>
>
> [[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] Panel Data--filling in missing dates in a span only

2015-03-11 Thread Adams, Jean
Steve,

Here is one approach that works.  I am calling your first data frame "df".

# list all years from min to max observed in each ID
years <- tapply(df$Date, df$ID, function(x) min(x):max(x))

# create a data frame based on the observed range of years
fulldf <- data.frame(ID=rep(names(years), sapply(years, length)),
  Date=unlist(years))

# merge the data frame of observations with the data frame with all years
merge(fulldf, df, all=TRUE)

Jean

On Tue, Mar 10, 2015 at 5:53 PM, Steven Archambault 
wrote:

> Hi folks,
>
> I have this panel data (below), with observations missing in each of the
> panels. I want to fill in years for the missing data, but only those years
> within the span of the existing data. For instance, BC-0002 needs on year,
> 1995. I do not want any years after the last observation.
>
> structure(list(ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
> 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label =
> c("BC-0002",
> "BC-0003", "BC-0004"), class = "factor"), Date = c(1989L, 1990L,
> 1991L, 1992L, 1993L, 1994L, 1996L, 1989L, 1990L, 1991L, 1992L,
> 1993L, 1994L, 1996L, 1995L, 1996L, 1997L, 1998L, 2000L, 1994L,
> 1993L, 1999L, 1998L), DepthtoWater_bgs = c(317.85, 317.25, 321.25,
> 312.31, 313.01, 330.41, 321.01, 166.58, 167.55, 168.65, 168.95,
> 169.25, 168.85, 169.75, 260.6, 261.65, 262.15, 265.45, 266.15,
> 265.25, 265.05, 266.95, 267.75)), .Names = c("ID", "Date",
> "DepthtoWater_bgs"
> ), class = "data.frame", row.names = c(NA, -23L))
>
>
> I have been using this code to expand the entire panels, but it is not
> what exactly what I want.
>
> fexp <- expand.grid(ID=unique(wells$ID), Date=unique(wells$Date))
> merge(fexp, wells, all=TRUE)
>
> Any help would be much appreciated!
>
> Thanks,
> Steve
>
> [[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] t-test: many changing groups.

2015-03-08 Thread Adams, Jean
Hard to disentangle your code in the non-HTML world of r-help.  Please use
plain text in the future.  Below is one approach you could try.

Jean

# response variables
resp_vars <- runif(20)
names(resp_vars) <- paste0("sample_", seq(20))

# independent variables
ind_vars <- matrix(sample(c("A", "B"), 2000, TRUE), ncol=20,
  dimnames=list(paste0("obs_", seq(100)), names(resp_vars)))

# save the t-test results to a list
t_fit <- apply(ind_vars, 1, function(obs) t.test(resp_vars ~ obs))

# grab the estimates from each t-test and put it in a data frame
library(broom)
t_est <- do.call(rbind, lapply(t_fit, tidy))
names(t_est) <- c("diff", "meanA", "meanB", "t", "p.value", "df",
  "conf.low", "conf.high")

head(t_est)



On Sat, Mar 7, 2015 at 10:05 AM, White Sky 
wrote:

> I'd like to perform a t-test between groups 'A' and 'B'. The difficulty is
> that although there is only one response variable, there are many
> observations, and the grouping (A or B) differs with each observation. My
> code for generating the input data is shown below.
> I'd like to know how to approach doing the test, ideally so that the
> t-test results for each observation are presented in a table. I'm not sure
> where to start as other searches have been futile... something along the
> lines of t.test(ind_vars ~ resp_vars) , maybe using rapply, and separating
> groups by A and B each time...
> # Matrix for response variableN_samples <- 20resp_vars <-
> matrix(runif(n=N_samples, min=0, max=1))sample_names <- paste0("sample_",
> 1:N_samples )rownames(x=resp_vars) <- sample_namescolnames(x=resp_vars) <-
> "resp"resp_vars [1:5,]
> # Matrix for independent variablesN_observations <- 100ind_vars <-
> matrix(NA, N_observations, N_samples)ind_vars <- apply(ind_vars, c(1,2),
> function(x) sample(c("A", "B"),1))ind_var_names <- paste0("obs_",
> 1:N_observations)rownames(x=ind_vars) <- ind_var_namescolnames(x=ind_vars)
> <- sample_namesind_vars[1:3,1:5]
> [[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] xerror and xstd are missing from cptable of the Rpart package

2015-02-03 Thread Adams, Jean
Kim,

The "x" in "xerror" and "xstd" stands for cross validation.  But you have
specified no cross validations, xval=0.

Try:

model <- rpart(Product ~ ., data=trainData, control=rpart.control(minsplit=50,
cp=0.002))
model$cptable

Jean


On Tue, Feb 3, 2015 at 7:09 AM, Kim C.  wrote:

> Hello all,
> I'm making a decision tree with the rpart package. I want to prune the
> tree and in many tutorials it says to use cptable. Like so: opt <-
> which.min(model_rpart$cptable[, "xerror"])
> The problem is that when I look up model_rpart$cptable it only show the
> columns CP, nsplit, rel error. So xerror and xstd are missing. How can this
> be?
> Model looks like this: model <- rpart(Product~. , data=trainData,
> control=rpart.control(minsplit=50, cp=0.002, xval=0))
>
> Thank you.
> Kim
> [[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] naming rows/columns in 'array of matrices'

2015-02-02 Thread Adams, Jean
In your example, P is a three dimensional array.  You can assign names to
the three dimensions using the dimnames() function.  For example, this
command assigns names to the first two dimensions, but leaves the third
dimension without names.

dimnames(P) <- list(c("live", "dead"), c("live", "dead"), NULL)

Jean

On Fri, Jan 30, 2015 at 1:07 PM, Evan Cooch  wrote:

> Suppose I have the following situation:
>
> I have an array of 2 matrices, where each matrix is (2x2):
>
> P <- array(0, c(2,2,2))
>
> P[,,1] <- matrix(c(1,2,3,4),2,2,byrow=T);
> P[,,2] <- matrix(c(5,6,7,8),2,2,byrow=T);
>
> I want to label rows and columns of each matrix in the array, such that P
> would look like
>
>
> live dead
> live  12
> dead  34
>
> , , 2
>
> live  dead
>  live 56
>  dead 78
>
> I've tried 'direct, brute force" approaches like
>
> rownames(P[,,1]) <- c("live","dead")
> colnames(P[,,1]) <- c("live","dead")
>
> (repeated for the second matrix), but this doesn't work.
>
> Since all of the matrices are of the same dimension(s), and since I want
> the same rownames and colnames for each matrix, I'm hoping there is some
> simply magical permutation of lapply (I'm guessing) which will do the trick.
>
>  I'd also be interested in why the 'direct, brute force' approach (above)
> doesn't work, and what does, since I might need to manipulate row/col names
> for individual matrices in the array (if, say, dimensions of the matrices
> were not the same over the array).
>
> Thanks in advance!
>
> __
> 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] Proportion of equal entries in dist()?

2015-01-20 Thread Adams, Jean
Jorge,

I have not used it myself, but you might find the dist() function in the
proxy package to be useful.

http://cran.r-project.org/web/packages/proxy/index.html

Jean

On Mon, Jan 19, 2015 at 7:38 AM, Jorge I Velez 
wrote:

> Dear all,
>
> Given vectors "x" and "y", I would like to compute the proportion of
> entries that are equal, that is, mean(x == y).
>
> Now, suppose I have the following matrix:
>
> n <- 1e2
> m <- 1e4
> X <- matrix(sample(0:2, m*n, replace = TRUE), ncol = m)
>
> I am interested in calculating the above proportion for every pairwise
> combination of rows.  I came up with the following:
>
> myd <- function(X, p = NROW(X)){
> D <- matrix(NA, p, p)
> for(i in 1:p) for(j in 1:p) if(i > j) D[i, j] <- mean(X[i, ] == X[j,])
> D
> }
>
> system.time(d <- myd(X))
>
> However, in my application n and m are much more larger than in this
> example and the computational time might be an issue.  I would very much
> appreciate any suggestions on how to speed the "myd" function.
>
> Note:  I have done some experiments with the dist() function and despite
> being much, much, much faster than "myd", none of the default distances
> fits my needs.  I would also appreciate any suggestions on how to include
> "my own" distance function in dist().
>
> Thank you very much for your time.
>
> Best regards,
> Jorge Velez.-
>
> [[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] Manipulating Plots

2015-01-06 Thread Adams, Jean
Raphael,

I'm assuming that the tile.list() function you're using is from the deldir
package.  I'm not sure what the figure() function does.  Using an example
tessellation from the help file for the tile.list() function, I created two
plots: one with the full view and one with the zoomed in view.

library(deldir)
x <- runif(20)
y <- runif(20)
z <- deldir(x, y)
w <- tile.list(z)

# full view
plot(w, close=TRUE)

# zoomed in view
plot(0, 0, type="n", xlim=c(0.2, 0.6), ylim=c(0.2, 0.6))
plot(w, close=TRUE, add=TRUE)

Jean


On Tue, Jan 6, 2015 at 11:43 AM, Raphael Päbst 
wrote:

> The relevant bit of code should be this one:
>
> #Getting a list of Voronoi-Cells:
> VoronoiCells <- tile.list(DelTriCor)
> # plotting all of them:
> figure()
> plot(VoronoiCells,fillcol=CellColor,close=TRUE,xlim=xlim,ylim=ylim)
>
> I hope this helps.
>
> All the best!
>
> Raphael
>
> On 1/6/15, Adams, Jean  wrote:
> > It will be easier for folks to help you if you provide example code that
> > produces a plot like the one you are dealing with.
> >
> > Jean
> >
> > On Tue, Jan 6, 2015 at 11:23 AM, Raphael Päbst  >
> > wrote:
> >
> >> Hello,
> >> I have a somewhat complicated question and hope, someone can help me
> >> or that there is a solution at all for my problem.
> >> I am using R to plot the results of a Voronoi-Tesselation. I am
> >> however only interested in a small part of the plot, around the
> >> center. Is there a way to cut out the central part of the plot and
> >> enlarge it in R? I have quite a few of these plots and cutting and
> >> enlarging the image manually with another software is only the last
> >> option, if there is no other way to do it.
> >>
> >> I hope this explains my problem clearly enough and there is a solution
> >> for
> >> it.
> >>
> >> Many thanks in advance!
> >>
> >> Raphael
> >>
> >> __
> >> 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] Manipulating Plots

2015-01-06 Thread Adams, Jean
It will be easier for folks to help you if you provide example code that
produces a plot like the one you are dealing with.

Jean

On Tue, Jan 6, 2015 at 11:23 AM, Raphael Päbst 
wrote:

> Hello,
> I have a somewhat complicated question and hope, someone can help me
> or that there is a solution at all for my problem.
> I am using R to plot the results of a Voronoi-Tesselation. I am
> however only interested in a small part of the plot, around the
> center. Is there a way to cut out the central part of the plot and
> enlarge it in R? I have quite a few of these plots and cutting and
> enlarging the image manually with another software is only the last
> option, if there is no other way to do it.
>
> I hope this explains my problem clearly enough and there is a solution for
> it.
>
> Many thanks in advance!
>
> Raphael
>
> __
> 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] Problem with

2014-12-03 Thread Adams, Jean
This question is more about statistics than R.  I suggest that you post it
to Cross Validated instead, http://stats.stackexchange.com/.

Jean

On Wed, Dec 3, 2014 at 5:40 AM, Dries David  wrote:

>  Hey
>
> In my data set i have two variables: month (march or april) and wind
> direction (N,NE,E,SE,S,SW,W,NW). I have to know if there is a difference in
> wind direction between these months. What kind of test statistic should i
> use?
>
> Kind regards
>
> Dries David
>
> __
> 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] function to avoid <<-

2014-12-02 Thread Adams, Jean
Glad to see this query and the responses.  You all just helped me to
eliminate the use of global variables from my R package.  I knew they were
not recommended, but I didn't know how to get around using them.

Thanks!

Jean

On Tue, Dec 2, 2014 at 10:59 AM, Karim Mezhoud  wrote:

> OK thanks as:
>
> myenv <- new.env(parent = emptyenv())
> fun <- function(){
> fun1 <- function(){
> myenv$X <- 5
> }
>
> }
> fun()
> ls(myenv)
> #X
> X
> #5
>
>   Ô__
>  c/ /'_;kmezhoud
> (*) \(*)   ⴽⴰⵔⵉⵎ  ⵎⴻⵣⵀⵓⴷ
> http://bioinformatics.tn/
>
>
>
> On Tue, Dec 2, 2014 at 5:47 PM, Greg Snow <538...@gmail.com> wrote:
>
> > By "At the top level" Hadley meant to put that code outside of the
> > function definition.  In you source file that line should be very near
> the
> > top, before any function definitions.  Then "myenv" will not be temporary
> > (well it will go away when you end the R session).  Further, when this
> code
> > is compiled into a package then "myenv" becomes package local, meaning
> that
> > functions within the package can access it and the objects inside of it,
> > but it will not interfere with any other packages or the global
> environment.
> >
> > On Tue, Dec 2, 2014 at 9:32 AM, Karim Mezhoud 
> wrote:
> >
> >> Thanks Dr Hadley,
> >>
> >> but when I use a function the myenv remains temporary and I am to face
> the
> >> same problem.
> >>
> >>
> >> fun <- function(){
> >>
> >> myenv <- new.env(parent = emptyenv())
> >>
> >> fun1 <- function(){
> >> myenv$X <- 5
> >> }
> >>
> >> }
> >>
> >> ls(myEnv)
> >> #character(0)
> >>
> >>   Ô__
> >>  c/ /'_;kmezhoud
> >> (*) \(*)   ⴽⴰⵔⵉⵎ  ⵎⴻⵣⵀⵓⴷ
> >> http://bioinformatics.tn/
> >>
> >>
> >>
> >> On Tue, Dec 2, 2014 at 4:17 PM, Hadley Wickham 
> >> wrote:
> >>
> >> > At the top level do:
> >> >
> >> > myenv <- new.env(parent = emptyenv())
> >> >
> >> > Then in your functions do
> >> >
> >> > myenv$x <- 50
> >> > myenv$x
> >> >
> >> > etc
> >> >
> >> > You also should not be using data() in that way. Perhaps you want
> >> > R/sysdata.rda. See http://r-pkgs.had.co.nz/data.html for more
> details.
> >> >
> >> > Hadley
> >> >
> >> > On Tue, Dec 2, 2014 at 2:28 AM, Karim Mezhoud 
> >> wrote:
> >> > > Dear All,
> >> > >
> >> > > I am writing a GUIpackage that needs global variables.
> >> > > I had many warning message when I checked the code as for example:
> >> > > geteSet: no visible binding for global variable ‘curselectCases’
> >> > > I would like to write a function that creates a global place for
> >> Objects
> >> > to
> >> > > be loaded as:
> >> > >
> >> > >
> >> > > Fun <- function(){
> >> > >
> >> > > Object <- 5
> >> > >
> >> > > Var2Global <- function(Object){
> >> > > .myDataEnv <- new.env(parent=emptyenv()) # not exported
> >> > > isLoaded <- function(Object) {
> >> > > exists(Object, .myDataEnv)
> >> > > }
> >> > > getData <- function(Object) {
> >> > > if (!isLoaded(Object)) data(Object, envir=.myDataEnv)
> >> > > .myDataEnv[[Object]]
> >> > > }
> >> > > }
> >> > >
> >> > > }
> >> > >
> >> > > To avoid the use of:  Object <<- 5
> >> > >
> >> > > but it seems not working yet. Object == 5 is not a global variable
> >> after
> >> > > running Fun().
> >> > >
> >> > > Any Idea?
> >> > > Thanks
> >> > >   Ô__
> >> > >  c/ /'_;kmezhoud
> >> > > (*) \(*)   ⴽⴰⵔⵉⵎ  ⵎⴻⵣⵀⵓⴷ
> >> > > http://bioinformatics.tn/
> >> > >
> >> > > [[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.
> >> >
> >> >
> >> >
> >> > --
> >> > http://had.co.nz/
> >> >
> >>
> >> [[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.
> >>
> >
> >
> >
> > --
> > Gregory (Greg) L. Snow Ph.D.
> > 538...@gmail.com
> >
>
> [[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 

Re: [R] SVYPLOT

2014-11-20 Thread Adams, Jean
Raphael

I just ran an example from the help file, and the xlim argument worked
fine.  Can you post a small example where the xlim argument doesn't work?

Jean

library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
svyplot(api00~api99, design=dstrat, style="bubble")
svyplot(api00~api99, design=dstrat, style="bubble", xlim=c(500, 700))


On Thu, Nov 20, 2014 at 12:54 AM, Raphael Fraser 
wrote:

> How do I set the limits of my x and y axis in svyplot? xlim and ylim does
> not work.
>
> Regards,
> Raphael
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


  1   2   3   >