[R] mclustBIC version 3.3.1

2009-09-11 Thread madmax1425

Hi there,
I started getting a new error with the latest mclust package version 3.3.1.
My only solution was to install the older package 3.2.1 or even 3.1-10. , (i
think older ones will still work since i ve been using it for a while)

the sentence giving trouble is:

BIC <- mclustBIC(as.vector(data), G = 1:3, modelNames=c("E"))

Quite often i get "missing groups" suggesting the data is not appropriate
for that clustering into 3 groups. I could not cast the results with NULL
values in order to continue my process.

Does anybody know anything about the new version of this function and how
its effectiveness got reduced so drastically? Its functionalities seem to
behave expanded handling noise etc etc as per changelog.

Any ideas or workaround?

Thanks a lot for the contribution in advance.

Max

-- 
View this message in context: 
http://www.nabble.com/mclustBIC-version-3.3.1-tp25411550p25411550.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] bar chart with means - using ggplot

2009-09-11 Thread Dianne Cook

I would recommend not representing means by bars at all.

Bars are for counts, stacking from zero. Means are point estimates.  
ggplot has a lot of routines for displaying means with errors bars:  
geom_linerange, geom_pointrange. To hone your ggplot skills I  
recommend looking into these geoms.



On Sep 11, 2009, at 4:32 PM, Felipe Carrillo wrote:



Like this?

# example using qplot
library(ggplot2)
meanprice <- tapply(diamonds$price, diamonds$cut, mean);meanprice
cut <- factor(levels(diamonds$cut), levels = levels(diamonds$cut))
qplot(cut, meanprice, geom="bar", stat="identity", fill = I("grey50"))
dev.new() # create a new graph to compare with qplot
# Example using ggplot
ggdata <- data.frame(meanprice,cut);ggdata
ggplot(ggdata,aes(y=meanprice,x=cut)) +  
geom_bar(fill="grey50",stat='identity')


Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA


--- On Fri, 9/11/09, Andreas Christoffersen  
 wrote:



From: Andreas Christoffersen 
Subject: bar chart with means - using ggplot
To: "ggplot2" 
Date: Friday, September 11, 2009, 1:50 PM

In the help pages hadley provides the following example
showing how to
achieve bar charts with y being means of a variable instead
of counts.
The example uses qplot however - and not ggplot. Since i
would like to
understand ggplot better I would really like to see how
this could be
done in ggplot.

# example using qplot
library(ggplot2)
meanprice <- tapply(diamonds$price, diamonds$cut, mean)
cut <- factor(levels(diamonds$cut), levels =
levels(diamonds$cut))
qplot(cut, meanprice, geom="bar", stat="identity", fill =
I("grey50"))











--~--~-~--~~~---~--~~
You received this message because you are subscribed to the ggplot2  
mailing list.

To post to this group, send email to ggpl...@googlegroups.com
To unsubscribe from this group, send email to
ggplot2+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ggplot2
-~--~~~~--~~--~--~---



---
Dianne Cook
dic...@iastate.edu

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


Re: [R] Accumulating results from "for" loop in a list/array

2009-09-11 Thread Johannes Hüsing

Steven Kang schrieb:

Dear R users,


I would like to accumulate objects generated from 'for' loop to a list or
array.

To illustrate the problem, arbitrary data set and script is shown below,


x <- data.frame(a = c(rep("n",3),rep("y",2),rep("n",3),rep("y",2)), b =
c(rep("y",2),rep("n",4),rep("y",3),"n"), c = c(rep("n",7),rep("y",3)), d =
c("y", rep("n",4), rep("y",2), rep("n",3)))

for (i in 1:(dim(x)[2]))  {
 assign(paste("ind", i, sep = ""), which(x[ , i] == "y"))
  accum <- c(ind1, ind2, ind3, ind4)
}

  


Using "for" loops is not idiomatic; I tend to use them only if I really 
need intermediate results.


res <- apply(x, 2, function(answer) which(answer == "y"))

names(res) <- paste("ind", 1:ncol(x), sep="")


ind1


[1]  4  5  9 10
  

ind2


[1] 1 2 7 8 9
  

ind3


[1]  8  9 10
  

ind4


[1] 1 6 7
  

accum


 [1]  4  5  9 10  1  2  7  8  9  8  9 10  1  6  7

Are there any alternative method where the highlighted statement above can
be represented without typing individual objects manually? (as it can be
very tedious with large number of objects; i.e ind1, ind2, ., ind100)

  

/I think you are looking for unlist()./


Also, is there any way to extract individual objects ('ind1' etc) from
'accum'?

  
Well, I think they are not objects by themselves anymore. You may want 
to give the vector elements individual names based on their origin and 
then extract appropriate elements by string matching.


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


Re: [R] generating multiple sequences in subsets of data

2009-09-11 Thread David Winsemius
Have you tried running merged_cut_col$pickts through something that is  
less complex? Perhaps:


table(merged_cut_col$pickts)

... to see if there are problems with the "inner" functions? Also I  
think the as.numeric might be superfluous, since Dates are really just  
integers with some attitude,  er, attributes.


--
David.

On Sep 11, 2009, at 4:36 PM, Jason Baucom wrote:

My apologies for bringing up an old topic, but still having some  
problems!


I got this code to work, and it was running perfectly fine. I tried  
it with a larger data set and it crashed my machine, slowly chewing  
up memory until it could not allocate any more for the process. The  
following line killed me:


merged_cut_col$pickseq<- 
with(merged_cut_col,ave(as.numeric(as.Date(pickts)),cpid,FUN=seq))


So, I thought I'd try it another way, using the transformBy in the  
doBy package:


merged_cut_col<- 
transformBy(~cpid,data=merged_cut_col,pickseqREDO=seq(cpid))


This too ran for hours until eventually running out of memory. I've  
tried it on a beefier machine and I run in to the same problem.


Is there an alternative to these methods that would be less memory/ 
time intensive? This is a fairly simple routine I'm trying, just  
generating sequence numbers based on simple criteria. I'm surprised  
it's bringing my computer to its knees. I'm running about 1M rows  
now, but doing other operations such as merges or adding new columns/ 
rows seems fine.


-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net]
Sent: Thursday, August 27, 2009 12:48 PM
To: Jason Baucom
Cc: Henrique Dallazuanna; r-help@r-project.org; Steven Few
Subject: Re: [R] generating multiple sequences in subsets of data


On Aug 27, 2009, at 11:58 AM, Jason Baucom wrote:


I got this to work. Thanks for the insight! row7 is what I need.




checkLimit <-function(x) x<3



stuff$row6<-checkLimit(stuff$row1)


You don't actually need those intermediate steps:


stuff$row7 <- with(stuff, ave(row1, row2, row1 < 3, FUN = seq))
stuff

   row1 row2 row7
1 011
2 112
3 213
4 311
5 412
6 513
7 121
8 222
9 321
10422

The expression row1 < 3 gets turned into a logical vector that ave()
is perfectly happy with.

--
David Winsemius




stuff$row7 <- with(stuff, ave(row1,row2, row6, FUN = sequence))



stuff


 row1 row2 row3 row4 row5  row6 row7

1 01111  TRUE1

2 11222  TRUE2

3 21333  TRUE3

4 31414 FALSE1

5 41515 FALSE2

6 51616 FALSE3

7 12111  TRUE1

8 22222  TRUE2

9 32313 FALSE1

1042414 FALSE2



Jason





From: Henrique Dallazuanna [mailto:www...@gmail.com]
Sent: Thursday, August 27, 2009 11:02 AM
To: Jason Baucom
Cc: r-help@r-project.org; Steven Few
Subject: Re: [R] generating multiple sequences in subsets of data



Try this;

stuff$row3 <- with(stuff, ave(row1, row2, FUN = seq))

I don't understand the fourth column

On Thu, Aug 27, 2009 at 11:55 AM, Jason Baucom
 wrote:

I'm running into a problem I can't seem to find a solution for. I'm
attempting to add sequences into an existing data set based on  
subsets

of the data.  I've done this using a for loop with a small subset of
data, but attempting the same process using real data (200k rows) is
taking way too long.



Here is some sample data and my ultimate goal


row1<-c(0,1,2,3,4,5,1,2,3,4)



row2<-c(1,1,1,1,1,1,2,2,2,2)



stuff<-data.frame(row1=row1,row2=row2)



stuff


row1 row2

1 01

2 11

3 21

4 31

5 41

6 51

7 12

8 22

9 32

1042





I need to derive 2 columns. I need a sequence for each unique row2,
and
then I need a sequence that restarts based on a cutoff value for row1
and unique row2. The following table is what is -should- look like
using
a cutoff of 3 for row4



row1 row2 row3 row4

1 0111

2 1122

3 2133

4 3141

5 4152

6 5163

7 1211

8 2222

9 3231

104242



I need something like row3<-sequence(nrow(unique(stuff$row2))) that
actually works :-) Here is the for loop that functions properly for
row3:



stuff$row3<-c(1)

for (i in 2:nrow(stuff)) { if ( stuff$row2[i] == stuff$row2[i-1]) {
stuff$row3[i] = stuff$row3[i-1]+1}}

Thanks!



Jason Baucom

Ateb, Inc.

919.882.4992 O

919.872.1645 F

www.ateb.com 




 [[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:/

Re: [R] Moving to Mac OS X

2009-09-11 Thread Victor Manuel Garcia Guerrero
Thanks to everybody for your comments.
 
All the best.
 
Víctor Manuel García Guerrero
Doctorado en Estudios de Población,
CEDUA, COLMEX
Camino al Ajusco N° 20, Pedregal de Sta. Teresa
C.P.10740, Tlalpan, México, D.F.
* : vmgar...@colmex.mx  
* : 5617-9016



De: r-help-boun...@r-project.org en nombre de Noah Silverman
Enviado el: vie 11/09/2009 03:03
Para: r help
Asunto: Re: [R] Moving to Mac OS X



Thanks Steve,

That's a big help.



On 9/11/09 12:48 PM, Steve Lianoglou wrote:
> Hi,
>
> On Sep 11, 2009, at 3:40 PM, Noah Silverman wrote:
>
>> Steve,
>>
>> You make a good point.  I confused 64 bit with a multi-core setup.
>>
>> That said, I don't belive the pretty packaged up GUI has a 64 bit
>> version, just the "raw terminal" version does.
>
> There is a 64bit version of the R.app GUI, you can get it from here:
>
> http://r.research.att.com/#GUI
>
> For some reason the 2.9-leopard.dmg is missing (though the 2.10-devel
> is there). This was just noticed on R-sig-mac earlier today and,
> AFAIK, it should be back soon.
>
> -steve
>
>>
>>
>>
>> On 9/11/09 12:38 PM, Steve Lianoglou wrote:
>>> Hi,
>>>
>>> On Sep 11, 2009, at 3:08 PM, Noah Silverman wrote:
 3) I purposefully chose NOT to install 64bit R.  I have a dual-core
 machine.  With the 32 bit version, R will happily keep one core
 running at 100%, but then I have other core free for my "regular"
 work.
>>>
>>> Using 64bit R shouldn't change your CPU usage, so if you want to use
>>> it to deal with larger data, feel free to do so ... unless you
>>> explicitly write code to use >1 cpu, you'll still have another cpu
>>> free to do with what you will (assuming you have enough ram).
>>>
>>> -steve
>>>
 On 9/11/09 10:32 AM, Marc Schwartz wrote:
> On Sep 11, 2009, at 12:15 PM, Victor Manuel Garcia Guerrero wrote:
>
>> Hi all,
>>
>> I have been using R on Windows for a long time, but now I am
>> ready to move to Mac OS X, but I was just wondering if R works
>> better on Mac than on Windows. This is because I had some memory
>> size issues in the past.
>>
>> Another question is if some of you know an R editor for Mac (just
>> like Tinn-R).
>>
>> Thanks.
>
> The notion of "better" is always in the eyes of the useR and will
> depend upon specific criteria.
>
> OSX can run R in both 32 bit and 64 bit modes and indeed the
> default OSX download for R provided by Simon installs and supports
> both. If you use the 32 bit version, then from a memory management
> standpoint, you will not see demonstrable gains over Windows.
> However, with the 64 bit version, you will avail yourself of a
> much larger memory address space as compared to running 32 bit R
> on Windows. That of course presumes that you have a lot of RAM in
> your Mac to actually take advantage of the larger address space.
>
> The 64 bit memory address space is also available via Linux, with
> appropriate hardware.
>
>
> You might want to review the R OSX FAQ:
>
> http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html
>
> and also note that there is a OSX specific e-mail list:
>
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>
>
> As far as editors, I am not familiar with the details of Tinn-R,
> but ESS/Emacs is available for OSX and this is what I use
> (continuing what I had been using on Linux for the past number of
> years).  Others will likely be able to provide other
> recommendations and you might want to search the R-SIG-Mac list
> archives as no doubt there have been such discussions in the past.
>
> HTH,
>
> Marc Schwartz
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
>>>
>>> --
>>> Steve Lianoglou
>>> Graduate Student: Computational Systems Biology
>>>  |  Memorial Sloan-Kettering Cancer Center
>>>  |  Weill Medical College of Cornell University
>>> Contact Info: http://cbio.mskcc.org/~lianos/contact
>>>
>>
>> __
>> 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.
>
> --
> Steve Lianoglou
> Graduate Student: Computational Systems Biology

Re: [R] For sending my R package as part of R-project

2009-09-11 Thread Lio, Yuhlong
Thank you for your help.  We will read the intructions.  When it is ready, I or 
my co-authers will send our package to R-project.org.

Yuhlong  


From: Turner Rolf [r.tur...@auckland.ac.nz]
Sent: Friday, September 11, 2009 5:30 PM
To: Liviu Andronic; Lio, Yuhlong
Cc: r-help@r-project.org
Subject: RE: [R] For sending my R package as part of R-project


From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
Liviu Andronic [landronim...@gmail.com]
Sent: Saturday, September 12, 2009 8:42 AM
To: Lio, Yuhlong
Cc: r-help@r-project.org
Subject: Re: [R] For sending my R package as part of R-project

Hello

On Fri, Sep 11, 2009 at 4:40 PM, Lio, Yuhlong  wrote:
> The reviewers and editor suggest the R package for the sampling plans of the 
> paper be part of R-project. Please let me know what I should do to make the R 
> package available for R-project group.
>
I would suggest that you check this document [1].
Liviu

[1] http://cran.r-project.org/doc/manuals/R-exts.pdf

Explicitly, see page 21.

cheers,

Rolf Turner
##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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


Re: [R] help in matching two column vectors

2009-09-11 Thread jim holtman
Is this what you want:

> (a<-1:6)
[1] 1 2 3 4 5 6
> (b<-c(5,2))
[1] 5 2
> (m1<-match(a,b))
[1] NA  2 NA NA  1 NA
> cbind(a, b[m1])
 a
[1,] 1 NA
[2,] 2  2
[3,] 3 NA
[4,] 4 NA
[5,] 5  5
[6,] 6 NA
>

Your 'missing function b' in the first example was due to you thinking
'b(m1[i])' is equivalent to 'b[m1[i]]'; the first is a function call.
On Fri, Sep 11, 2009 at 5:00 PM, ravi  wrote:
> Dear list,
> I have a long list of two vectors with some matching elements. I would like 
> to line them up in two columns and have an NA in those positions of the 
> second vector where a match is absent. With a simple example, I will explain 
> my problem.
> (a<-1:6)
> (b<-c(5,2))
> (m1<-match(a,b))
> (ab<-cbind(a,m1))
> m2<-numeric(length(m1))
>  for (i in 1:length(m1))
>      {m2[i]<-ifelse(is.na(m1[i]),NA,b(m1[i]))}
> # what I want to get - ab2 (shown below)
> bsub<-c(NA,2,NA,NA,5,NA) # hoped to get this from m2 via the for loop above 
> (non NA elements from the b vector)
> (ab2<-cbind(a,bsub))
>
> I get an error message that the function b is not found. How do I define this 
> function?
> Are there any other simpler methods for achieving my final result? Without a 
> loop?
> I did find one solution that almost solved my problem.
> aa<-cbind(a,a)
> bb<-cbind(b,b)
> abm<-merge(aa,bb,by.x="a",by.y="b",all=TRUE)
> abm[,2:3] # just what I want
> However, if I choose a little more complicated version of the problem :
>
> rm(list=ls())
> (a<-c(8,5,4,7,3,4,5,2,1))
> (b<-c(5,2))
> (a1<-sort(a))
> (b1<-sort(b))
> aa<-cbind(a1,a1)
> bb<-cbind(b1,b1)
> (ab<-merge(aa,bb,by.x="a1",by.y="b1",all=TRUE))
> ab[,2:3]
> In this case, there is a match for both the 5's in a1. I want only one match 
> as there is only one 5 in b.
> My question is - is there any generalised solution for the above problem?
> One extra feature that would be interesting is if there are elements in the 
> 2nd vector that are missing in the 1st.
> In that case, I would like to have NA's in the 1st vector matching the extra 
> elements in the 2nd vector.
>
> I will appreciate any help that I can get.
> Thanks,
> Ravi
>
>
> __
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

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


[R] Way to iteratively change line color and line style

2009-09-11 Thread Jason Rupert
I would like to have a way to automatically change the line color and line 
style.  

Below is an example of the items I am plotting.  I've contemplated coming up 
with a list of desired colors and styles, but I am hoping there is an automated 
way for this to be accomplished as the number of lines I will be adding to a 
plot will be changing over time. 

Thanks again for any insights and feedback.


plot(1,1, xlim=c(1000,4000), ylim=c(10,80), col=0, 
xlab=c("Sq. Footage"), ylab=c("Cost ($)"))

square_footage_values<-c(1000:4000)
initial_val<-300

cost_per_square_footage_vals<-seq(from=100, to=200, by=10)
for(ii in 1:length(cost_per_square_footage_vals))
{
lines(square_footage_values, 
cost_per_square_footage_vals[ii]*square_footage_values)
}

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


Re: [R] help with for loop

2009-09-11 Thread Steve Lianoglou

Hi,

On Sep 11, 2009, at 6:35 PM, Edward Chen wrote:


example code:
P = function(whichday,columns){
y = which(pvalue[,whichday]0){
#diffbig = meandayxx0)
x[i] = raw_urine[x_index[i],1]
dayx[i]= raw_urine[x_index[i],day1_ind]
dayy[i] = raw_urine[x_index[i],columns]
jpeg("test 1.jpg",width=800, height = 800)
matplot(x[i],dayx[i],lwd = 3,pch=1,col = "black",xlim=xbound,  
ylim=ybound)

matpoints(x[i],dayy[i],lwd=3,pch=1,col="red")
dev.off()
return(length(y),length(x_index),diffbig)}
else{
xx_index[i] = which(diff[i]<0, arr.ind=TRUE)
xx[i] = raw_urine[xx_index[i],1]
dayxx[i] = raw_urine[xx_index[i],day1_ind]
dayyy[i] = raw_urine[xx_index[i],columns]
jpeg("test 2.jpg",width=800, height = 800)
matplot(xx[i],dayxx[i],lwd = 3,pch=1,col = "black",xlim=xbound,  
ylim=ybound)

matpoints(xx[i],dayyy[i],lwd=3,pch=1,col="red")
dev.off()
return(length(xx_index))}}}

I ran this code and I got "Error in 1:nrow(diff) : NA/NaN argument".  
I this

my problem is with the way I define the i index with the rest of the
functions.
Basically I want to run for every row of the matrix that is called the
"diff". without the for loop, I don't know how to make it work but  
with it,
I have a lot of bugs in there that hopefully someone can just point  
out a

general direction.


Sorry, I can't put the brainpower into figuring out what the code  
means, but it sounds like you want to run a given function over each  
row of your matrix, yes?


Look at the ``apply`` function, with MARGIN set to 1. Here I'm just  
calling the ``mean`` function over every row of my matrix:


R> m <- matrix(1:100, 10, 10)
R> apply(m, 1, mean)
 [1] 46 47 48 49 50 51 52 53 54 55

Substitute your own function for ``mean``

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


[R] help with for loop

2009-09-11 Thread Edward Chen
example code:
P = function(whichday,columns){
y = which(pvalue[,whichday]0){
#diffbig = meandayxx0)
x[i] = raw_urine[x_index[i],1]
dayx[i]= raw_urine[x_index[i],day1_ind]
dayy[i] = raw_urine[x_index[i],columns]
jpeg("test 1.jpg",width=800, height = 800)
matplot(x[i],dayx[i],lwd = 3,pch=1,col = "black",xlim=xbound, ylim=ybound)
matpoints(x[i],dayy[i],lwd=3,pch=1,col="red")
dev.off()
return(length(y),length(x_index),diffbig)}
else{
xx_index[i] = which(diff[i]<0, arr.ind=TRUE)
xx[i] = raw_urine[xx_index[i],1]
dayxx[i] = raw_urine[xx_index[i],day1_ind]
dayyy[i] = raw_urine[xx_index[i],columns]
jpeg("test 2.jpg",width=800, height = 800)
matplot(xx[i],dayxx[i],lwd = 3,pch=1,col = "black",xlim=xbound, ylim=ybound)
matpoints(xx[i],dayyy[i],lwd=3,pch=1,col="red")
dev.off()
return(length(xx_index))}}}

I ran this code and I got "Error in 1:nrow(diff) : NA/NaN argument". I this
my problem is with the way I define the i index with the rest of the
functions.
Basically I want to run for every row of the matrix that is called the
"diff". without the for loop, I don't know how to make it work but with it,
I have a lot of bugs in there that hopefully someone can just point out a
general direction.
Thank you very much!

-- 
Edward Chen
Email: edche...@gmail.com
Cell Phone: 510-371-4717

[[alternative HTML version deleted]]

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


Re: [R] For sending my R package as part of R-project

2009-09-11 Thread Turner Rolf


From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
Liviu Andronic [landronim...@gmail.com]
Sent: Saturday, September 12, 2009 8:42 AM
To: Lio, Yuhlong
Cc: r-help@r-project.org
Subject: Re: [R] For sending my R package as part of R-project

Hello

On Fri, Sep 11, 2009 at 4:40 PM, Lio, Yuhlong  wrote:
> The reviewers and editor suggest the R package for the sampling plans of the 
> paper be part of R-project. Please let me know what I should do to make the R 
> package available for R-project group.
>
I would suggest that you check this document [1].
Liviu

[1] http://cran.r-project.org/doc/manuals/R-exts.pdf

Explicitly, see page 21.

cheers,

Rolf Turner
##
Attention: 
This e-mail message is privileged and confidential. If you are not the 
intended recipient please delete the message and notify the sender. 
Any views or opinions presented are solely those of the author.

This e-mail has been scanned and cleared by MailMarshal 
www.marshalsoftware.com
##

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


Re: [R] Best R text editors?

2009-09-11 Thread Ted Harding
On 11-Sep-09 21:02:06, Patrick Connolly wrote:
> On Fri, 11-Sep-2009 at 03:46PM +0100, Ted Harding wrote:
> 
> []
> 
>|> Well, not really!! My point (and certainly Charles Curran's point)
>|> is that in touch-typing you know by proprioception and
>|> neuromuscular coordination where your fingers are relative to the
>|> keys on the keyboard, and what key you will press next, without
>|> looking; and you can accurately press several keys in rapid
>|> succession -- just as a pianist can play an arpeggio without
>|> looking.
> 
> []
> 
> I was mostly kidding when I mentioned my guess at the reasoning for
> the default settings. However, paradoxically, I mostly agree with
> Ted and avoid using the mouse for every process *except* copy/cut &
> paste.
> It's a horses for courses thing.  I use a bunch of other keyboard
> shortcuts such as looking up help files in preference to using the
> menu and mouse.  Emacs users who choose to change the default setting
> in question will be unable to use the ones I use and end up not
> becoming aware of the nifty things possible.
> 
> To that extent, I was not entirely joking.
> 
> [...]

Point taken, Patrick! Indeed, well taken. Your mouse-usage preferences
are very much the same as mine. When I'm developing R code, the left
part of the screen is occupied by an R CLI window, and the right by a
window in which I am editing a file of R code. When I think I've got
something that might be right, I mouse-copy it to the other window and
see what happens. At the end of the day the result can be made into an
R script, or left as a file of R code chunks which are known to work
for their respective tasks.

Perhaps the main difference is that you seem to use EMACS/ESS.
I use vim: all I need is the code. When it looks right I "mouse"
it across. So I'm content with a good text editor. I don't need
ESS-type interfaces with R, and I don't want to tangle with an
editor which has its own ideas about how code should be laid out.
(And don't ask about how close I once came to throwing my own
computer out of a 2nd-floor window, while trying to clean up
a student's thesis, written in Word ... talk about software which
thinks it knows better than you do  ).

Cheers,
Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 11-Sep-09   Time: 23:11:36
-- XFMail --

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


Re: [R] goodness of "prediction" using a model (lm, glm, gam, brt, regression tree .... )

2009-09-11 Thread jamesmcc

I think it's important to say why you're unhappy with your current measures?
Are they not capturing aspects of the data you understand? 

I typically use several residual measures in conjunction, each has it's
benefits/drawbacks. I just throw them all in a table. 


-- 
View this message in context: 
http://www.nabble.com/goodness-of-%22prediction%22-using-a-model-%28lm%2C-glm%2C-gam%2C-brt%2C-regression-tree--%29-tp25270261p25408808.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Best R text editors?

2009-09-11 Thread Nikos Alexandris
[Answering to the threads question]

For those who use Gnome's gedit, there is now RGedit:
http://sourceforge.net/projects/rgedit

Apologies if this was already posted,
Nikos

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


Re: [R] bar chart with means - using ggplot

2009-09-11 Thread Felipe Carrillo
Like this?

# example using qplot
library(ggplot2)
meanprice <- tapply(diamonds$price, diamonds$cut, mean);meanprice
cut <- factor(levels(diamonds$cut), levels = levels(diamonds$cut))
qplot(cut, meanprice, geom="bar", stat="identity", fill = I("grey50"))
dev.new() # create a new graph to compare with qplot
 # Example using ggplot
ggdata <- data.frame(meanprice,cut);ggdata
ggplot(ggdata,aes(y=meanprice,x=cut)) + geom_bar(fill="grey50",stat='identity')

Felipe D. Carrillo  
Supervisory Fishery Biologist  
Department of the Interior  
US Fish & Wildlife Service  
California, USA


--- On Fri, 9/11/09, Andreas Christoffersen  wrote:

> From: Andreas Christoffersen 
> Subject: bar chart with means - using ggplot
> To: "ggplot2" 
> Date: Friday, September 11, 2009, 1:50 PM
> 
> In the help pages hadley provides the following example
> showing how to
> achieve bar charts with y being means of a variable instead
> of counts.
> The example uses qplot however - and not ggplot. Since i
> would like to
> understand ggplot better I would really like to see how
> this could be
> done in ggplot.
> 
> # example using qplot
> library(ggplot2)
> meanprice <- tapply(diamonds$price, diamonds$cut, mean)
> cut <- factor(levels(diamonds$cut), levels =
> levels(diamonds$cut))
> qplot(cut, meanprice, geom="bar", stat="identity", fill =
> I("grey50"))
> 
> --~--~-~--~~~---~--~~
> You received this message because you are subscribed to the
> ggplot2 mailing list.
> To post to this group, send email to ggpl...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2
> -~--~~~~--~~--~--~---
> 
>

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


Re: [R] Using R for a slightly tricky survey analysis

2009-09-11 Thread Andreas Stefik
Hello folks,

I have recently finished a pilot study of a survey and am working to
complete the statistical analysis of the results in R. My Phd is technically
in computer science (not statistics), although I teach basic stats and have
a "decent" working knowledge of the area. With that said, my expertise in
psychometrics theory and factor analysis is weaker, so I thought I would
send an email here and try to solicit some advice on the proper technique
for my analysis.

First, in the survey, I have a series of "concepts" and word choices
regarding those concepts (e.g., how well does concept A relate to words A1
through AN), which each participant rates on a scale from 1 to 10. For each
question, I've gathered a significant amount of data with various answers to
the questions.

Now, what I'm most interested in is gathering whether there were
differences, for each answer in each question, between group A and B. The
total difference between A and B summed across all questions and answers in
the survey, isn't very meaningful. Similarly, the relationship between
questions are not meaningful at all, nor is the rate of change (if any)
between questions. In other words, there are probably correlations between
questions, as there are with many surveys, but they aren't of interest here.

It seems like there would be a few ways to tackle this. Since I'm only
interested the relationship between a list of answers to each question
individually, I was thinking I could run a simple ANOVA for each question
with appropriate post-hoc tests, but I'm not sure. First, there are quite a
few questions (about 12), and I'm a little worried about inflating my
family-wise error. Now, I could lower my alpha, but ...

Second, I know in some branches of survey analysis, they use factor analysis
and a series of complicated measures for determining the consistency of the
survey itself.  Since the relationships between questions doesn't have any
significant meaning, I'm not sure if that sort of analysis is the right way
to go here or not. For example, if a particular metric (chronbach's alpha),
said the survey was consistent or not, I don't know what that would even
mean in this case.

As for the data itself, it looks pretty good. Skew and Kurtosis values look
fine, the data appears reasonably normally distributed. There was no
discussion between participants or correlated error in that. In graphing and
going through the data, I don't see anything that pops out as unusual.

A couple questions:

1. Should I even be concerned about running measures for survey consistency
(chronbach's alpha or some kind of factor analysis related measures) if I'm
not particularly interested in the relationship between questions?

2. Should I run something more complex, like a MANOVA, in this case, to try
and weed out any correlated errors between the questions? Would a Wilks'
Lambda score even hold any meaning in a case like this, where the
correlations between the questions are quite coincidental anyway?


Or maybe I'm barking up the wrong tree completely and I should be doing a
thorough analysis of internal consistency measures, as that tells me
something I'm not quite realizing. Any hints out there from the R community,
perhaps from folks that do more survey analysis than I do?

Andreas Stefik, Ph.D.
Department of Computer Science
Southern Illinois University Edwardsville

[[alternative HTML version deleted]]

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


[R] Using R for a slightly tricky survey analysis

2009-09-11 Thread Andreas Stefik
Hello folks,

I have recently finished a pilot study of a survey and am working to
complete the statistical analysis of the results in R. My Phd is technically
in computer science (not statistics), although I teach basic stats and have
a "decent" working knowledge of the area. With that said, my expertise in
psychometrics theory and factor analysis is weaker, so I thought I would
send an email here and try to solicit some advice on the proper technique
for my analysis.

First, in the survey, I have a series of "concepts" and word choices
regarding those concepts (e.g., how well does concept A relate to words A1
through AN), which each participant rates on a scale from 1 to 10. For each
question, I've gathered a significant amount of data with various answers to
the questions.

Now, what I'm most interested in is gathering whether there were
differences, for each answer in each question, between group A and B. The
total difference between A and B summed across all questions and answers in
the survey, isn't very meaningful. Similarly, the relationship between
questions are not meaningful at all, nor is the rate of change (if any)
between questions. In other words, there are probably correlations between
questions, as there are with many surveys, but they aren't of interest here.

It seems like there would be a few ways to tackle this. Since I'm only
interested the relationship between a list of answers to each question
individually, I was thinking I could run a simple ANOVA for each question
with appropriate post-hoc tests, but I'm not sure. First, there are quite a
few questions (about 12), and I'm a little worried about inflating my
family-wise error. Now, I could lower my alpha, but ...

Second, I know in some branches of survey analysis, they use factor analysis
and a series of complicated measures for determining the consistency of the
survey itself.  Since the relationships between questions doesn't have any
significant meaning, I'm not sure if that sort of analysis is the right way
to go here or not. For example, if a particular metric (chronbach's alpha),
said the survey was consistent or not, I don't know what that would even
mean in this case.

As for the data itself, it looks pretty good. Skew and Kurtosis values look
fine, the data appears reasonably normally distributed. There was no
discussion between participants or correlated error in that. In graphing and
going through the data, I don't see anything that pops out as unusual.

A couple questions:

1. Should I even be concerned about running measures for survey consistency
(chronbach's alpha or some kind of factor analysis related measures) if I'm
not particularly interested in the relationship between questions?

2. Should I run something more complex, like a MANOVA, in this case, to try
and weed out any correlated errors between the questions? Would a Wilks'
Lambda score even hold any meaning in a case like this, where the
correlations between the questions are quite coincidental anyway?


Or maybe I'm barking up the wrong tree completely and I should be doing a
thorough analysis of internal consistency measures, as that tells me
something I'm not quite realizing. Any hints out there from the R community,
perhaps from folks that do more survey analysis than I do?

Andreas Stefik, Ph.D.
Department of Computer Science
Southern Illinois University Edwardsville

[[alternative HTML version deleted]]

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


Re: [R] Barplot+Table

2009-09-11 Thread Marc Schwartz


On Sep 11, 2009, at 1:20 PM, Andy Choens wrote:

I am trying to automate a report that my company does every couple  
of years
for the state of Maine. In the past we have used SPSS to run the  
data and then
used complicated Excel template to make the tables/graphics which we  
then
imported into Word. Since there are 256 tables/graphics for this  
report, this
work flow is a little painful. I would like to automate the process  
and I think
I can do so with odfWeave and R, but I've run into a problem. I  
can't seem to
get the output from R to look like what we have used in the past.  
Here's an

example of what I need it to look like (sorry for the long URL)

http://1.bp.blogspot.com/_TRRvdLHNnE8/SqpP5gFG3DI/BgY/09x-
LoLtfTI/s1600-h/example+graphic.png

My boss is open to using another tool (R) to get the work done but  
my final

output needs to look, more or less, like what we did last time.

I can make a table and I can make a bar graph that, essentially gets  
me where
I want to go (I can handle the tweaking) but I don't know how to put  
them

together and make things line up, as in my example (URL).

I have looked at iplot, ggplot, lattice, etc. I will confess that my  
knowledge
of R's graphical capabilities leaves a lot to be desired (as I am  
proving
today) but I really can not find an example or feature that seems to  
do what I
am trying to do. I am more or less satisfied with the plot, but I  
really would
like to line up the table with the graphics, which is why I don't  
just put a

table under the graph via odfweave.

Here's what I have thus far:

###
# These numbers are just BS I made up.
counties <-
c 
("County1 
","County2 
","County1 
","County2 
","County1 
","County2 
","County1 
","County2 
","County1 
","County2 
","County1 
","County2 
","County1 
","County2 
","County1 
","County2 
","County1 
","County2 
","County1","County2","County1","County2","County1","County2")


gender <- c("Male", "Male","Male", "Male", "Male", "Female","Female",
"Female","Male", "Male","Male", "Female","Male", "Female","Male",
"Female","Male", "Female","Female", "Female","Male",  
"Female","Male", "Male")


weight <- c(1,2,1,2,1,2,2,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2)

example.table<-xtabs(weight~counties+gender)
barplot(prop.table(example.table,1),beside=T)
###

I am open to using any of the various graphics systems provided in  
R. I am
willing/capable of learning and in fact, I want to learn how to do  
this but I
can't even figure out which system I should spend my time learning  
more about

and I don't have time to become an expert with all of them.

Thank you.



Using the data that is in the online plot rather than the above, here  
is a first go. Note that I am not drawing the background grid in the  
barplot or the lines for table below it. These could be added if you  
really need them.



# Create data
MyData <- matrix(c(57.1, 52.3, 13.5, 13.9, 7.9, 8.8, 5.4, 5.6,
   16.1, 19.4),
 nrow = 2)

# Note that by using '\n' in the text, the label will be plotted on
# two lines. '\n' is a newline character
colnames(MyData) <- c("0 occasions", "1-2 Occasions", "3-5 Occasions",
  "6-9 Occasions", "10 or more\nOccasions")

rownames(MyData) <- c("Androscoggin", "Maine")


> MyData
 0 occasions 1-2 Occasions 3-5 Occasions 6-9 Occasions
Androscoggin57.1  13.5   7.9   5.4
Maine   52.3  13.9   8.8   5.6
 10 or more\nOccasions
Androscoggin  16.1
Maine 19.4




# Set graph margins to make room for labels
# See ?par
par(mar = c(5, 8, 4, 1))


# Set colors
MyCols <- c("black", "grey80")


# Set label size
MyCex = 0.75


# Set lines for table data
MyLines <- 2:3


# do barplot, getting bar midpoints in 'mp'
# See ?barplot
mp <- barplot(MyData, beside = TRUE, ylim = c(0, 100),
  yaxt = "n", cex.names = MyCex, col = MyCols)


# mp contains the following. The mean of each column
# is the horizontal center of each pair of bars
> mp
 [,1] [,2] [,3] [,4] [,5]
[1,]  1.5  4.5  7.5 10.5 13.5
[2,]  2.5  5.5  8.5 11.5 14.5


# Put a box around it
box()


# Draw y axis tick marks and labels
axis(2, at = seq(0, 100, 10), las = 1)


# Draw values below plot
# Use the values of 'mp' from above.
# See ?mtext
mtext(side = 1, text = MyData,
  at = rep(colMeans(mp), each = nrow(MyData)),
  line = MyLines, cex = MyCex)


# Get min value for the x axis. See ?par 'usr'
min.x <- par("usr")[1]


# Draw categories using mtext
# See ?strwidth to get the length of the labels in
# user coordinates, which is then used for 'at'
# Setting 'adj = 0' left justifies the text
mtext(side = 1, line = MyLines, text = rownames(MyData),
  at = min.x - max(strwidth(rownames(MyData), cex = MyCex)),
  adj = 0, cex = MyCex)


# Draw the col

Re: [R] rpart - the xval argument in rpart.control and in xpred.rpart

2009-09-11 Thread jamesmcc

I have this *exact* same confusion. 

Adding to this is the fact that Everitt and Hothorn in their book, HSAUR,
say that setting xval=100 gives "100 runs of 10-fold cross-validation" (1st
ed., page 136).

Is this actually 1 run of 100-fold cross-validation? 

For large xval, doing multiple cross-validations is not super important. But
I would want to perform multiple cross-validataion with different partitions
of the data when xval is moderate or small wrt the size of the data set. In
that case do we need to do as Paolo suggests?




Paolo Radaelli wrote:
> 
> Usually 10-fold cross validation is performed more than once to get an 
> estimate of the misclassification rate thus I thought "number of 
> cross-validations" was different from the "number of cross-validation 
> groups". So, if I want to perform 10-fold cross-validation more than once 
> (say 5) in order to estimate the miscalssification rate I have to run 
> xpred.rpart 5 times ?
> Thanks
> Paolo
> 
> 
>>> I have some problems in understanding the meaning of the xval argument
>>> in
>>> the two functions rpart.control and xpred.rpart. In the former it is 
>>> defined
>>> as the number of cross-validations while in the latter it is defined as 
>>> the
>>> number of cross-validation groups.
>>  It is the same thing.  If xval=10 then the data is divided into 10 
>> disjoint
>> groups.  A model is fit with group 1 left out and that model is used to 
>> predict
>> the observations in group 1; then a model is fit with group 2 left out; 
>> then
>> group 3, ...
>>   So 10 groups = 10 fits of the model.
> 
> 
> 
> Actually I thought that in rpart.control
> 
>>
>>
>>
>>   Terry Therneau
>>
>>
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Re%3A-rpart---the-xval-argument-in-rpart.control-and-in-xpred.rpart-tp23942907p25408496.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Working with large matrix

2009-09-11 Thread A Ezhil
HI Steve,

Thanks a lot for your suggestions. I never used bigmemory and biglm before. Is 
there a way (using systems commands) to combine awk and R? I was thinking of 
calling a R program inside Awk, passing each row to R, do the lm, get back 
results and process it with awk. Will this make the calculation fast? If you 
have any experience with large matrices, could you please share it with me?

Thanks again,
Ezhil

--- On Fri, 9/11/09, Steve Lianoglou  wrote:

> From: Steve Lianoglou 
> Subject: Re: [R] Working with large matrix
> To: "A Ezhil" 
> Cc: R-help@r-project.org
> Date: Friday, September 11, 2009, 11:56 PM
> Hi,
> 
> On Sep 11, 2009, at 1:15 PM, A Ezhil wrote:
> 
> > Dear All,
> > 
> > I have large matrix (46000 x 11250). I would like to
> do the linear regression for each row. I wrote a simple
> function that has lm() and used apply(mat,1,func). The issue
> is that it takes ages to load the file and also to finish
> the lm. I am using LINUX 64 bit with 32G mem. Is there an
> elegant and fast way of completing this task?
> 
> Do bigmemory and biglm help?
> 
> http://cran.r-project.org/web/packages/bigmemory
> http://cran.r-project.org/web/packages/biglm
> 
> -steve
> 
> --
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
>   |  Memorial Sloan-Kettering Cancer Center
>   |  Weill Medical College of Cornell University
> Contact Info: http://cbio.mskcc.org/~lianos/contact
> 
> 




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


Re: [R] Alternative to Scale Function?

2009-09-11 Thread Noah Silverman
Genius,

That certainly is much faster that what I had worked out on my own.

I looked at sweep, but couldn't understand the rather thin help page.  
Your example makes it really clear

Thank You!!!

--
Noah


On 9/11/09 1:57 PM, Gavin Simpson wrote:
> On Fri, 2009-09-11 at 13:10 -0700, Noah Silverman wrote:
>
>> Hi,
>>
>> Is there an alternative to the scale function where I can specify my own
>> mean and standard deviation?
>>  
> A couple of calls to sweep?
>
> See ?sweep
>
> set.seed(123)
> dat<- data.frame(matrix(runif(10*10), ncol = 10))
> xbar<- colMeans(dat)
> sigma<- apply(dat, 2, sd)
>
> dat.std<- sweep(sweep(dat, 2, xbar, "-"), 2, sigma, "/")
>
> ## compare
> scale(dat)
>
> HTH
>
>
>> I've come across an interesting issue where this would help.
>>
>> I'm training and testing on completely different sets of data.  The
>> testing set is smaller than the training set.
>>
>> Using the standard scale function of R seems to introduce some error.
>> Since it scales data WITHIN the set, it may scale the same number to
>> different value since the range in the training and testing set may be
>> different.
>>
>> My thought was to scale the larger training set of data, then use the
>> mean and SD of the training data to scale the testing data according to
>> the same parameters.  That way a number will transform to the same
>> result regardless of whether it is in the training or testing set.
>>
>> I can't be the first one to have looked at this.  Does anyone know of a
>> function in R or if there is a scale alternative where I can control the
>> parameters?
>>
>> Thanks!
>>
>> --
>> Noah
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>  

[[alternative HTML version deleted]]

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


Re: [R] Alternative to Scale Function?

2009-09-11 Thread Mark Difford

>> The scale function will return the mean and sd of the data.

By default. Read ?scale.

Mark.


Noah Silverman-3 wrote:
> 
> I think I just answered my own question.
> 
> The scale function will return the mean and sd of the data.
> 
> So the process is fairly simple.
> scale training data varaible
> note mean and sd from the scale
> then manually scale the test data using the mean and sd from the 
> training data.
> 
> That should make sure that a value is transformed the same regardless of 
> which data set it is in.
> 
> Do I have this correct, or can anybody contribute any more to the concept?
> 
> Thanks!
> 
> 
> --
> Noah
> 
> On 9/11/09 1:10 PM, Noah Silverman wrote:
>> Hi,
>>
>> Is there an alternative to the scale function where I can specify my 
>> own mean and standard deviation?
>>
>> I've come across an interesting issue where this would help.
>>
>> I'm training and testing on completely different sets of data.  The 
>> testing set is smaller than the training set.
>>
>> Using the standard scale function of R seems to introduce some error.  
>> Since it scales data WITHIN the set, it may scale the same number to 
>> different value since the range in the training and testing set may be 
>> different.
>>
>> My thought was to scale the larger training set of data, then use the 
>> mean and SD of the training data to scale the testing data according 
>> to the same parameters.  That way a number will transform to the same 
>> result regardless of whether it is in the training or testing set.
>>
>> I can't be the first one to have looked at this.  Does anyone know of 
>> a function in R or if there is a scale alternative where I can control 
>> the parameters?
>>
>> Thanks!
>>
>> -- 
>> Noah
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Alternative-to-Scale-Function--tp25407625p25408289.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Best R text editors?

2009-09-11 Thread Patrick Connolly
On Fri, 11-Sep-2009 at 03:46PM +0100, Ted Harding wrote:

[]

|> Well, not really!! My point (and certainly Charles Curran's point)
|> is that in touch-typing you know by proprioception and
|> neuromuscular coordination where your fingers are relative to the
|> keys on the keyboard, and what key you will press next, without
|> looking; and you can accurately press several keys in rapid
|> succession -- just as a pianist can play an arpeggio without
|> looking.

[]

I was mostly kidding when I mentioned my guess at the reasoning for
the default settings.  However, paradoxically, I mostly agree with Ted
and avoid using the mouse for every process *except* copy/cut & paste.
It's a horses for courses thing.  I use a bunch of other keyboard
shortcuts such as looking up help files in preference to using the
menu and mouse.  Emacs users who choose to change the default setting
in question will be unable to use the ones I use and end up not
becoming aware of the nifty things possible.

To that extent, I was not entirely joking.

[...]

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

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


[R] help in matching two column vectors

2009-09-11 Thread ravi
Dear list,
I have a long list of two vectors with some matching elements. I would like to 
line them up in two columns and have an NA in those positions of the second 
vector where a match is absent. With a simple example, I will explain my 
problem.
(a<-1:6)
(b<-c(5,2))
(m1<-match(a,b))
(ab<-cbind(a,m1))
m2<-numeric(length(m1))
 for (i in 1:length(m1))
  {m2[i]<-ifelse(is.na(m1[i]),NA,b(m1[i]))}
# what I want to get - ab2 (shown below)
bsub<-c(NA,2,NA,NA,5,NA) # hoped to get this from m2 via the for loop above 
(non NA elements from the b vector)
(ab2<-cbind(a,bsub))

I get an error message that the function b is not found. How do I define this 
function?
Are there any other simpler methods for achieving my final result? Without a 
loop?
I did find one solution that almost solved my problem.
aa<-cbind(a,a)
bb<-cbind(b,b)
abm<-merge(aa,bb,by.x="a",by.y="b",all=TRUE)
abm[,2:3] # just what I want
However, if I choose a little more complicated version of the problem :

rm(list=ls())
(a<-c(8,5,4,7,3,4,5,2,1))
(b<-c(5,2))
(a1<-sort(a))
(b1<-sort(b))
aa<-cbind(a1,a1)
bb<-cbind(b1,b1)
(ab<-merge(aa,bb,by.x="a1",by.y="b1",all=TRUE))
ab[,2:3]
In this case, there is a match for both the 5's in a1. I want only one match as 
there is only one 5 in b.
My question is - is there any generalised solution for the above problem?
One extra feature that would be interesting is if there are elements in the 2nd 
vector that are missing in the 1st.
In that case, I would like to have NA's in the 1st vector matching the extra 
elements in the 2nd vector.

I will appreciate any help that I can get.
Thanks,
Ravi


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


Re: [R] Alternative to Scale Function?

2009-09-11 Thread Gavin Simpson
On Fri, 2009-09-11 at 13:10 -0700, Noah Silverman wrote:
> Hi,
> 
> Is there an alternative to the scale function where I can specify my own 
> mean and standard deviation?

A couple of calls to sweep?

See ?sweep

set.seed(123)
dat <- data.frame(matrix(runif(10*10), ncol = 10))
xbar <- colMeans(dat)
sigma <- apply(dat, 2, sd)

dat.std <- sweep(sweep(dat, 2, xbar, "-"), 2, sigma, "/")

## compare
scale(dat)

HTH

> 
> I've come across an interesting issue where this would help.
> 
> I'm training and testing on completely different sets of data.  The 
> testing set is smaller than the training set.
> 
> Using the standard scale function of R seems to introduce some error.  
> Since it scales data WITHIN the set, it may scale the same number to 
> different value since the range in the training and testing set may be 
> different.
> 
> My thought was to scale the larger training set of data, then use the 
> mean and SD of the training data to scale the testing data according to 
> the same parameters.  That way a number will transform to the same 
> result regardless of whether it is in the training or testing set.
> 
> I can't be the first one to have looked at this.  Does anyone know of a 
> function in R or if there is a scale alternative where I can control the 
> parameters?
> 
> Thanks!
> 
> --
> Noah
> 
> __
> 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.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

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


[R] ANN: rproto v1 (Protocol Buffers and R) [repost]

2009-09-11 Thread Saptarshi Guha
Hello,
(Previous message was scrubbed)

I apologize if this is not the list for package announcements. Having
said that I've released a package called rprotos which implements a
simple
serialization using Googles protocol buffers[1].
The package also includes some miscellaneous functions for
writing/reading variable length encoded integers, and Base64
encoding/decoding related functions.
The package can be downloaded from http://ml.stat.purdue.edu/rproto_1.0.tar.gz
it requires one to install libproto (Googles protobuffer library)

Brief Description:
The R objects that can be serialized are numerics, integers,strings,
logicals, raw,nulls and lists.
Attributes of the aforementioned are preserved. NA is also
preserved(for the above)
As such, the objects include factors and matrices.
The proto file can be found in the source.

Todo:
Very possible though needs some reading on my part: it is possible to
extend this to serialize functions, expressions, environments and
several other objects.
However that is some time in the future.

Regards
Saptarshi

[1] http://code.google.com/apis/protocolbuffers/docs/overview.html

Download:
http://ml.stat.purdue.edu/rproto_1.0.tar.gz

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


Re: [R] constrOptim parameters

2009-09-11 Thread Ravi Varadhan
Ivo,

Do you only have "box" constraints, i.e. upper and lower bounds on the
parameters themselves?  If so, you do not need to use `constrOptim'.  You
could use "L-BFGS-B" in `optim' or `nlminb' or `spg'.

You are mistaken about how `ui' is set up.  It should be a matrix with
dimension, Ni x p, where Ni is the number of inequality constraints and p is
the number of parameters.  So, in your case it should be a 2N x N matrix.  

Read the help carefully. 

Ravi.


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml

 




-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of ivo welch
Sent: Friday, September 11, 2009 4:21 PM
To: r-help
Subject: [R] constrOptim parameters

Dear R wizards:   I am playing (and struggling) with the example in the
constrOptim function.  simple example.  let's say I want to constrain my
variables to be within -1 and 1.I believe I want a whole lot of
constraints where ci is -1 and ui is either -1 or 1.  That is, I have 2*N
constraints.  Should the following work?

N=10
x= rep(1:N)
ci= rep(-1, 2*N)
ui= c(rep(1, N), rep(-1, N))
constrOptim( x, f, NULL, ui, ci, method="Nelder-Mead");

actually, my suggestions would be to give an example in the constrOptim docs
where the number of constraints is something like this example.  the current
ones have 2*2 constraints, so it is harder to figure out the appropriate
dimensions for different cases by extending the examples.  on another note,
the "non-conformable arguments" error could be a little more informative,
telling the end user what the two incompatible dimensions actually are.
this is not hard to find out by hand, but it would still be useful.

regards,

/iaw
-- 
Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)

[[alternative HTML version deleted]]

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

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


Re: [R] Alternative to Scale Function?

2009-09-11 Thread Noah Silverman

I think I just answered my own question.

The scale function will return the mean and sd of the data.

So the process is fairly simple.
scale training data varaible
note mean and sd from the scale
then manually scale the test data using the mean and sd from the 
training data.


That should make sure that a value is transformed the same regardless of 
which data set it is in.


Do I have this correct, or can anybody contribute any more to the concept?

Thanks!


--
Noah

On 9/11/09 1:10 PM, Noah Silverman wrote:

Hi,

Is there an alternative to the scale function where I can specify my 
own mean and standard deviation?


I've come across an interesting issue where this would help.

I'm training and testing on completely different sets of data.  The 
testing set is smaller than the training set.


Using the standard scale function of R seems to introduce some error.  
Since it scales data WITHIN the set, it may scale the same number to 
different value since the range in the training and testing set may be 
different.


My thought was to scale the larger training set of data, then use the 
mean and SD of the training data to scale the testing data according 
to the same parameters.  That way a number will transform to the same 
result regardless of whether it is in the training or testing set.


I can't be the first one to have looked at this.  Does anyone know of 
a function in R or if there is a scale alternative where I can control 
the parameters?


Thanks!

--
Noah

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


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


Re: [R] generating multiple sequences in subsets of data

2009-09-11 Thread Jason Baucom
A bit of debugging information

> merged_cut_col$pickseq <- 
> ave(as.numeric(as.Date(merged_cut_col$pickts)),merged_cut_col$cpid,as.numeric(as.Date(merged_cut_col$pickts))
>  > as.numeric(as.Date("2008-12-01")),FUN=seq)
Error: cannot allocate vector of size 55 Kb
> memory.size()
[1] 1882.56
> object.size(merged_cut_col)
75250816 bytes
> gc()
   used  (Mb) gc trigger   (Mb)  max used   (Mb)
Ncells   226664   6.11423891   38.1   3463550   92.5
Vcells 19186778 146.4  156381436 1193.1 241372511 1841.6

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Thursday, August 27, 2009 12:48 PM
To: Jason Baucom
Cc: Henrique Dallazuanna; r-help@r-project.org; Steven Few
Subject: Re: [R] generating multiple sequences in subsets of data


On Aug 27, 2009, at 11:58 AM, Jason Baucom wrote:

> I got this to work. Thanks for the insight! row7 is what I need.
>
>
>
>> checkLimit <-function(x) x<3
>
>> stuff$row6<-checkLimit(stuff$row1)

You don't actually need those intermediate steps:

 > stuff$row7 <- with(stuff, ave(row1, row2, row1 < 3, FUN = seq))
 > stuff
row1 row2 row7
1 011
2 112
3 213
4 311
5 412
6 513
7 121
8 222
9 321
10422

The expression row1 < 3 gets turned into a logical vector that ave()  
is perfectly happy with.

-- 
David Winsemius

>
>> stuff$row7 <- with(stuff, ave(row1,row2, row6, FUN = sequence))
>
>> stuff
>
>   row1 row2 row3 row4 row5  row6 row7
>
> 1 01111  TRUE1
>
> 2 11222  TRUE2
>
> 3 21333  TRUE3
>
> 4 31414 FALSE1
>
> 5 41515 FALSE2
>
> 6 51616 FALSE3
>
> 7 12111  TRUE1
>
> 8 22222  TRUE2
>
> 9 32313 FALSE1
>
> 1042414 FALSE2
>
>
>
> Jason
>
>
>
> 
>
> From: Henrique Dallazuanna [mailto:www...@gmail.com]
> Sent: Thursday, August 27, 2009 11:02 AM
> To: Jason Baucom
> Cc: r-help@r-project.org; Steven Few
> Subject: Re: [R] generating multiple sequences in subsets of data
>
>
>
> Try this;
>
> stuff$row3 <- with(stuff, ave(row1, row2, FUN = seq))
>
> I don't understand the fourth column
>
> On Thu, Aug 27, 2009 at 11:55 AM, Jason Baucom  
>  wrote:
>
> I'm running into a problem I can't seem to find a solution for. I'm
> attempting to add sequences into an existing data set based on subsets
> of the data.  I've done this using a for loop with a small subset of
> data, but attempting the same process using real data (200k rows) is
> taking way too long.
>
>
>
> Here is some sample data and my ultimate goal
>
>> row1<-c(0,1,2,3,4,5,1,2,3,4)
>
>> row2<-c(1,1,1,1,1,1,2,2,2,2)
>
>> stuff<-data.frame(row1=row1,row2=row2)
>
>> stuff
>
>  row1 row2
>
> 1 01
>
> 2 11
>
> 3 21
>
> 4 31
>
> 5 41
>
> 6 51
>
> 7 12
>
> 8 22
>
> 9 32
>
> 1042
>
>
>
>
>
> I need to derive 2 columns. I need a sequence for each unique row2,  
> and
> then I need a sequence that restarts based on a cutoff value for row1
> and unique row2. The following table is what is -should- look like  
> using
> a cutoff of 3 for row4
>
>
>
>  row1 row2 row3 row4
>
> 1 0111
>
> 2 1122
>
> 3 2133
>
> 4 3141
>
> 5 4152
>
> 6 5163
>
> 7 1211
>
> 8 2222
>
> 9 3231
>
> 104242
>
>
>
> I need something like row3<-sequence(nrow(unique(stuff$row2))) that
> actually works :-) Here is the for loop that functions properly for
> row3:
>
>
>
> stuff$row3<-c(1)
>
> for (i in 2:nrow(stuff)) { if ( stuff$row2[i] == stuff$row2[i-1]) {
> stuff$row3[i] = stuff$row3[i-1]+1}}
>
> Thanks!
>
>
>
> Jason Baucom
>
> Ateb, Inc.
>
> 919.882.4992 O
>
> 919.872.1645 F
>
> www.ateb.com 
>
>
>
>
>   [[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.
>
>
>
>
> -- 
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>
>
>   [[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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
https://s

Re: [R] For sending my R package as part of R-project

2009-09-11 Thread Liviu Andronic
Hello

On Fri, Sep 11, 2009 at 4:40 PM, Lio, Yuhlong  wrote:
> The reviewers and editor suggest the R package for the sampling plans of the 
> paper be part of R-project. Please let me know what I should do to make the R 
> package available for R-project group.
>
I would suggest that you check this document [1].
Liviu

[1] http://cran.r-project.org/doc/manuals/R-exts.pdf

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


Re: [R] generating multiple sequences in subsets of data

2009-09-11 Thread Jason Baucom
My apologies for bringing up an old topic, but still having some problems!

I got this code to work, and it was running perfectly fine. I tried it with a 
larger data set and it crashed my machine, slowly chewing up memory until it 
could not allocate any more for the process. The following line killed me:

merged_cut_col$pickseq<-with(merged_cut_col,ave(as.numeric(as.Date(pickts)),cpid,FUN=seq))

So, I thought I'd try it another way, using the transformBy in the doBy package:

merged_cut_col<-transformBy(~cpid,data=merged_cut_col,pickseqREDO=seq(cpid))

This too ran for hours until eventually running out of memory. I've tried it on 
a beefier machine and I run in to the same problem.

Is there an alternative to these methods that would be less memory/time 
intensive? This is a fairly simple routine I'm trying, just generating sequence 
numbers based on simple criteria. I'm surprised it's bringing my computer to 
its knees. I'm running about 1M rows now, but doing other operations such as 
merges or adding new columns/rows seems fine.

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Thursday, August 27, 2009 12:48 PM
To: Jason Baucom
Cc: Henrique Dallazuanna; r-help@r-project.org; Steven Few
Subject: Re: [R] generating multiple sequences in subsets of data


On Aug 27, 2009, at 11:58 AM, Jason Baucom wrote:

> I got this to work. Thanks for the insight! row7 is what I need.
>
>
>
>> checkLimit <-function(x) x<3
>
>> stuff$row6<-checkLimit(stuff$row1)

You don't actually need those intermediate steps:

 > stuff$row7 <- with(stuff, ave(row1, row2, row1 < 3, FUN = seq))
 > stuff
row1 row2 row7
1 011
2 112
3 213
4 311
5 412
6 513
7 121
8 222
9 321
10422

The expression row1 < 3 gets turned into a logical vector that ave()  
is perfectly happy with.

-- 
David Winsemius

>
>> stuff$row7 <- with(stuff, ave(row1,row2, row6, FUN = sequence))
>
>> stuff
>
>   row1 row2 row3 row4 row5  row6 row7
>
> 1 01111  TRUE1
>
> 2 11222  TRUE2
>
> 3 21333  TRUE3
>
> 4 31414 FALSE1
>
> 5 41515 FALSE2
>
> 6 51616 FALSE3
>
> 7 12111  TRUE1
>
> 8 22222  TRUE2
>
> 9 32313 FALSE1
>
> 1042414 FALSE2
>
>
>
> Jason
>
>
>
> 
>
> From: Henrique Dallazuanna [mailto:www...@gmail.com]
> Sent: Thursday, August 27, 2009 11:02 AM
> To: Jason Baucom
> Cc: r-help@r-project.org; Steven Few
> Subject: Re: [R] generating multiple sequences in subsets of data
>
>
>
> Try this;
>
> stuff$row3 <- with(stuff, ave(row1, row2, FUN = seq))
>
> I don't understand the fourth column
>
> On Thu, Aug 27, 2009 at 11:55 AM, Jason Baucom  
>  wrote:
>
> I'm running into a problem I can't seem to find a solution for. I'm
> attempting to add sequences into an existing data set based on subsets
> of the data.  I've done this using a for loop with a small subset of
> data, but attempting the same process using real data (200k rows) is
> taking way too long.
>
>
>
> Here is some sample data and my ultimate goal
>
>> row1<-c(0,1,2,3,4,5,1,2,3,4)
>
>> row2<-c(1,1,1,1,1,1,2,2,2,2)
>
>> stuff<-data.frame(row1=row1,row2=row2)
>
>> stuff
>
>  row1 row2
>
> 1 01
>
> 2 11
>
> 3 21
>
> 4 31
>
> 5 41
>
> 6 51
>
> 7 12
>
> 8 22
>
> 9 32
>
> 1042
>
>
>
>
>
> I need to derive 2 columns. I need a sequence for each unique row2,  
> and
> then I need a sequence that restarts based on a cutoff value for row1
> and unique row2. The following table is what is -should- look like  
> using
> a cutoff of 3 for row4
>
>
>
>  row1 row2 row3 row4
>
> 1 0111
>
> 2 1122
>
> 3 2133
>
> 4 3141
>
> 5 4152
>
> 6 5163
>
> 7 1211
>
> 8 2222
>
> 9 3231
>
> 104242
>
>
>
> I need something like row3<-sequence(nrow(unique(stuff$row2))) that
> actually works :-) Here is the for loop that functions properly for
> row3:
>
>
>
> stuff$row3<-c(1)
>
> for (i in 2:nrow(stuff)) { if ( stuff$row2[i] == stuff$row2[i-1]) {
> stuff$row3[i] = stuff$row3[i-1]+1}}
>
> Thanks!
>
>
>
> Jason Baucom
>
> Ateb, Inc.
>
> 919.882.4992 O
>
> 919.872.1645 F
>
> www.ateb.com 
>
>
>
>
>   [[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.
>
>
>
>
> -- 
> Henrique Dallazuanna
> C

[R] ANN: rproto v1 (Protocol Buffers and R)

2009-09-11 Thread Saptarshi Guha
Hello,
I apologize if this is not the list for package announcements. Having  
said that I've released a package called rprotos which implements a  
simple
serialization using Googles protocol buffers[1].
The package also includes some miscellaneous functions for writing/ 
reading variable length encoded integers, and Base64 encoding/decoding  
related functions.
The package can be downloaded from http://ml.stat.purdue.edu/rproto_1.0.tar.gz
it requires one to install libproto (Googles protobuffer library)

Brief Description:
The R objects that can be serialized are numerics, integers,strings,  
logicals, raw,nulls and lists.
Attributes of the aforementioned are preserved. NA is also  
preserved(for the above)
As such, the objects include factors and matrices.
The proto file can be found in the source.

Todo:
Very possible though needs some reading on my part: it is possible to  
extend this to serialize functions, expressions, environments and  
several other objects.
However that is some time in the future.

Regards
Saptarshi

[1] http://code.google.com/apis/protocolbuffers/docs/overview.html

Download:
http://ml.stat.purdue.edu/rproto_1.0.tar.gz

Saptarshi Guha | saptarshi.g...@gmail.com | http://www.stat.purdue.edu/~sguha


[[alternative HTML version deleted]]

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


Re: [R] How to do rotation for polygon?

2009-09-11 Thread Greg Snow
Does this do what you want?

library(TeachingDemos)
ms.pent <- function(ang=0,...) {
theta <- seq(ang, length.out=6, by=2*pi/5)
cbind( cumsum(cos(theta)/2), cumsum(sin(theta)/2) )
}

par(xpd=NA)
my.symbols( rep(1,5), rep(1,5), ms.pent, ang=seq(0, by=2*pi/5, length.out=5),
add=FALSE, col=2:6 )


--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111

From: Hemavathi Ramulu [mailto:hema.ram...@gmail.com]
Sent: Thursday, September 10, 2009 2:44 AM
To: Greg Snow
Cc: r-help@r-project.org
Subject: Re: [R] How to do rotation for polygon?

Hi everyone,

I still couldn't get the diagram as I mentioned before. I try Grey and Milton 
suggestion but
it confusing.
I hope anyone helped me.

Thanks in advance.

Regards,
Hema.
On Thu, Sep 3, 2009 at 11:39 PM, Greg Snow 
mailto:greg.s...@imail.org>> wrote:
The my.symbols and ms.polygon functions in the TeachingDemos package may help.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-
> project.org] On Behalf Of Hemavathi Ramulu
> Sent: Wednesday, September 02, 2009 11:05 PM
> To: r-help@r-project.org
> Subject: [R] How to do rotation for polygon?
>
> Hi everyone,
> I have coding for repeating pentagon as below:
>
> plot(0:11,type="n")
> for (i in 1:10 )polygon(rep(c(4,5,7,8,6)), i*c(.5,.3,.3,.5,.7), bor=2)
>
> which are increasing vertically.
>
> Now, I want to know how to rotate the pentagon, so that I will get
> pattern
> like flower.
> Basicly, repeating pentagon in circle.
>
> Thanks alot for helping me to solve this problem.
> --
> Hemavathi
>
>   [[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.



--
Hemavathi Ramulu

[[alternative HTML version deleted]]

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


[R] constrOptim parameters

2009-09-11 Thread ivo welch
Dear R wizards:   I am playing (and struggling) with the example in the
constrOptim function.  simple example.  let's say I want to constrain my
variables to be within -1 and 1.I believe I want a whole lot of
constraints where ci is -1 and ui is either -1 or 1.  That is, I have 2*N
constraints.  Should the following work?

N=10
x= rep(1:N)
ci= rep(-1, 2*N)
ui= c(rep(1, N), rep(-1, N))
constrOptim( x, f, NULL, ui, ci, method="Nelder-Mead");

actually, my suggestions would be to give an example in the constrOptim docs
where the number of constraints is something like this example.  the current
ones have 2*2 constraints, so it is harder to figure out the appropriate
dimensions for different cases by extending the examples.  on another note,
the "non-conformable arguments" error could be a little more informative,
telling the end user what the two incompatible dimensions actually are.
this is not hard to find out by hand, but it would still be useful.

regards,

/iaw
-- 
Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)

[[alternative HTML version deleted]]

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


[R] Alternative to Scale Function?

2009-09-11 Thread Noah Silverman

Hi,

Is there an alternative to the scale function where I can specify my own 
mean and standard deviation?


I've come across an interesting issue where this would help.

I'm training and testing on completely different sets of data.  The 
testing set is smaller than the training set.


Using the standard scale function of R seems to introduce some error.  
Since it scales data WITHIN the set, it may scale the same number to 
different value since the range in the training and testing set may be 
different.


My thought was to scale the larger training set of data, then use the 
mean and SD of the training data to scale the testing data according to 
the same parameters.  That way a number will transform to the same 
result regardless of whether it is in the training or testing set.


I can't be the first one to have looked at this.  Does anyone know of a 
function in R or if there is a scale alternative where I can control the 
parameters?


Thanks!

--
Noah

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


Re: [R] R on Multi Core

2009-09-11 Thread Romain Francois

On 09/11/2009 10:05 PM, Noah Silverman wrote:


Hi,

Our discussions about 64 bit R has led me to another thought.

I have a nice dual core 3.0 chip inside my Linux Box (Running Fedora 11.)

Is there a version of R that would take advantage of BOTH cores??
(Watching my system performance meter now is interesting, Running R will
hold a single core at 100% perfectly, but the other core sites idle.)

Thanks!

--
Noah


http://rforge.net/multicore/

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/y8y0 : search the graph gallery from R
|- http://tr.im/y8wY : new R package : ant
`- http://tr.im/xMdt : update on the ant package

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


Re: [R] Barplot+Table

2009-09-11 Thread Andy Choens
On Friday 11 September 2009 02:47:32 pm Henrique Dallazuanna wrote:
> Try the textplot function in the gplots package:

Thank you. That definitely gives me a direction to pursue. It doesn't look like 
there is an easy way to make things line up though, which is unfortunate but 
I'm sure it's possible to come up with a combination that will work. . . I 
just have to play with it enough.

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


[R] R on Multi Core

2009-09-11 Thread Noah Silverman

Hi,

Our discussions about 64 bit R has led me to another thought.

I have a nice dual core 3.0 chip inside my Linux Box  (Running Fedora 11.)

Is there a version of R that would take advantage of BOTH cores??
(Watching my system performance meter now is interesting, Running R will 
hold a single core at 100% perfectly, but the other core sites idle.)


Thanks!

--
Noah

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


Re: [R] Moving to Mac OS X

2009-09-11 Thread Noah Silverman

Thanks Steve,

That's a big help.



On 9/11/09 12:48 PM, Steve Lianoglou wrote:

Hi,

On Sep 11, 2009, at 3:40 PM, Noah Silverman wrote:


Steve,

You make a good point.  I confused 64 bit with a multi-core setup.

That said, I don't belive the pretty packaged up GUI has a 64 bit 
version, just the "raw terminal" version does.


There is a 64bit version of the R.app GUI, you can get it from here:

http://r.research.att.com/#GUI

For some reason the 2.9-leopard.dmg is missing (though the 2.10-devel 
is there). This was just noticed on R-sig-mac earlier today and, 
AFAIK, it should be back soon.


-steve





On 9/11/09 12:38 PM, Steve Lianoglou wrote:

Hi,

On Sep 11, 2009, at 3:08 PM, Noah Silverman wrote:
3) I purposefully chose NOT to install 64bit R.  I have a dual-core 
machine.  With the 32 bit version, R will happily keep one core 
running at 100%, but then I have other core free for my "regular" 
work.


Using 64bit R shouldn't change your CPU usage, so if you want to use 
it to deal with larger data, feel free to do so ... unless you 
explicitly write code to use >1 cpu, you'll still have another cpu 
free to do with what you will (assuming you have enough ram).


-steve


On 9/11/09 10:32 AM, Marc Schwartz wrote:

On Sep 11, 2009, at 12:15 PM, Victor Manuel Garcia Guerrero wrote:


Hi all,

I have been using R on Windows for a long time, but now I am 
ready to move to Mac OS X, but I was just wondering if R works 
better on Mac than on Windows. This is because I had some memory 
size issues in the past.


Another question is if some of you know an R editor for Mac (just 
like Tinn-R).


Thanks.


The notion of "better" is always in the eyes of the useR and will 
depend upon specific criteria.


OSX can run R in both 32 bit and 64 bit modes and indeed the 
default OSX download for R provided by Simon installs and supports 
both. If you use the 32 bit version, then from a memory management 
standpoint, you will not see demonstrable gains over Windows. 
However, with the 64 bit version, you will avail yourself of a 
much larger memory address space as compared to running 32 bit R 
on Windows. That of course presumes that you have a lot of RAM in 
your Mac to actually take advantage of the larger address space.


The 64 bit memory address space is also available via Linux, with 
appropriate hardware.



You might want to review the R OSX FAQ:

http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html

and also note that there is a OSX specific e-mail list:

https://stat.ethz.ch/mailman/listinfo/r-sig-mac


As far as editors, I am not familiar with the details of Tinn-R, 
but ESS/Emacs is available for OSX and this is what I use 
(continuing what I had been using on Linux for the past number of 
years).  Others will likely be able to provide other 
recommendations and you might want to search the R-SIG-Mac list 
archives as no doubt there have been such discussions in the past.


HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


--
Steve Lianoglou
Graduate Student: Computational Systems Biology
 |  Memorial Sloan-Kettering Cancer Center
 |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



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


--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



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


[R] ipred bagging segfault on 64 bit linux build

2009-09-11 Thread jamesmcc

I wanted to report this issue here so others may not find themselves alone
and as the author is apparently active on the list.

I havent done an exhaustive test by any means, cause I dont have time. But
here's a small example. Apparently the "ns" argument is the one that is
killing it. I've gotten several different segfault messages, the only other
one I remember said "out of memory". This one is probably most common from
the about 10 segfaults I've had. 

 *** caught segfault ***
address(nil), cause 'unknown'


I'm working on a 64bit build of R 2.8.1 on a linux machine. If you want more
details, I can surely get them.

It happens on the last line for the following for all different valies of
ns:

library(rpart)
library(ipred)

data("Forbes2000", package="HSAUR")
Forbes2000 <- subset(Forbes2000, !is.na(profits))
datasize=length(Forbes2000$profits)
f <- rpart(profits ~ assets + marketvalue + sales, data=Forbes2000)

fb <- bagging(profits ~ assets + marketvalue + sales, data=Forbes2000)
fb <- bagging(profits ~ assets + marketvalue + sales, data=Forbes2000,
  nbagg=100,coob=TRUE)
fb <- bagging(profits ~ assets + marketvalue + sales, data=Forbes2000,
  nbagg=100,coob=TRUE, ns=round(.9*datasize))

-- 
View this message in context: 
http://www.nabble.com/ipred-bagging-segfault-on-64-bit-linux-build-tp25407509p25407509.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Moving to Mac OS X

2009-09-11 Thread Steve Lianoglou

Hi,

On Sep 11, 2009, at 3:40 PM, Noah Silverman wrote:


Steve,

You make a good point.  I confused 64 bit with a multi-core setup.

That said, I don't belive the pretty packaged up GUI has a 64 bit  
version, just the "raw terminal" version does.


There is a 64bit version of the R.app GUI, you can get it from here:

http://r.research.att.com/#GUI

For some reason the 2.9-leopard.dmg is missing (though the 2.10-devel  
is there). This was just noticed on R-sig-mac earlier today and,  
AFAIK, it should be back soon.


-steve





On 9/11/09 12:38 PM, Steve Lianoglou wrote:

Hi,

On Sep 11, 2009, at 3:08 PM, Noah Silverman wrote:
3) I purposefully chose NOT to install 64bit R.  I have a dual- 
core machine.  With the 32 bit version, R will happily keep one  
core running at 100%, but then I have other core free for my  
"regular" work.


Using 64bit R shouldn't change your CPU usage, so if you want to  
use it to deal with larger data, feel free to do so ... unless you  
explicitly write code to use >1 cpu, you'll still have another cpu  
free to do with what you will (assuming you have enough ram).


-steve


On 9/11/09 10:32 AM, Marc Schwartz wrote:

On Sep 11, 2009, at 12:15 PM, Victor Manuel Garcia Guerrero wrote:


Hi all,

I have been using R on Windows for a long time, but now I am  
ready to move to Mac OS X, but I was just wondering if R works  
better on Mac than on Windows. This is because I had some memory  
size issues in the past.


Another question is if some of you know an R editor for Mac  
(just like Tinn-R).


Thanks.


The notion of "better" is always in the eyes of the useR and will  
depend upon specific criteria.


OSX can run R in both 32 bit and 64 bit modes and indeed the  
default OSX download for R provided by Simon installs and  
supports both. If you use the 32 bit version, then from a memory  
management standpoint, you will not see demonstrable gains over  
Windows. However, with the 64 bit version, you will avail  
yourself of a much larger memory address space as compared to  
running 32 bit R on Windows. That of course presumes that you  
have a lot of RAM in your Mac to actually take advantage of the  
larger address space.


The 64 bit memory address space is also available via Linux, with  
appropriate hardware.



You might want to review the R OSX FAQ:

http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html

and also note that there is a OSX specific e-mail list:

https://stat.ethz.ch/mailman/listinfo/r-sig-mac


As far as editors, I am not familiar with the details of Tinn-R,  
but ESS/Emacs is available for OSX and this is what I use  
(continuing what I had been using on Linux for the past number of  
years).  Others will likely be able to provide other  
recommendations and you might want to search the R-SIG-Mac list  
archives as no doubt there have been such discussions in the past.


HTH,

Marc Schwartz

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


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


--
Steve Lianoglou
Graduate Student: Computational Systems Biology
 |  Memorial Sloan-Kettering Cancer Center
 |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



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


--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


Re: [R] Moving to Mac OS X

2009-09-11 Thread Noah Silverman

Steve,

You make a good point.  I confused 64 bit with a multi-core setup.

That said, I don't belive the pretty packaged up GUI has a 64 bit 
version, just the "raw terminal" version does.




On 9/11/09 12:38 PM, Steve Lianoglou wrote:

Hi,

On Sep 11, 2009, at 3:08 PM, Noah Silverman wrote:
3) I purposefully chose NOT to install 64bit R.  I have a dual-core 
machine.  With the 32 bit version, R will happily keep one core 
running at 100%, but then I have other core free for my "regular" work.


Using 64bit R shouldn't change your CPU usage, so if you want to use 
it to deal with larger data, feel free to do so ... unless you 
explicitly write code to use >1 cpu, you'll still have another cpu 
free to do with what you will (assuming you have enough ram).


-steve


On 9/11/09 10:32 AM, Marc Schwartz wrote:

On Sep 11, 2009, at 12:15 PM, Victor Manuel Garcia Guerrero wrote:


Hi all,

I have been using R on Windows for a long time, but now I am ready 
to move to Mac OS X, but I was just wondering if R works better on 
Mac than on Windows. This is because I had some memory size issues 
in the past.


Another question is if some of you know an R editor for Mac (just 
like Tinn-R).


Thanks.


The notion of "better" is always in the eyes of the useR and will 
depend upon specific criteria.


OSX can run R in both 32 bit and 64 bit modes and indeed the default 
OSX download for R provided by Simon installs and supports both. If 
you use the 32 bit version, then from a memory management 
standpoint, you will not see demonstrable gains over Windows. 
However, with the 64 bit version, you will avail yourself of a much 
larger memory address space as compared to running 32 bit R on 
Windows. That of course presumes that you have a lot of RAM in your 
Mac to actually take advantage of the larger address space.


The 64 bit memory address space is also available via Linux, with 
appropriate hardware.



You might want to review the R OSX FAQ:

 http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html

and also note that there is a OSX specific e-mail list:

 https://stat.ethz.ch/mailman/listinfo/r-sig-mac


As far as editors, I am not familiar with the details of Tinn-R, but 
ESS/Emacs is available for OSX and this is what I use (continuing 
what I had been using on Linux for the past number of years).  
Others will likely be able to provide other recommendations and you 
might want to search the R-SIG-Mac list archives as no doubt there 
have been such discussions in the past.


HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



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


Re: [R] Moving to Mac OS X

2009-09-11 Thread Steve Lianoglou

Hi,

On Sep 11, 2009, at 3:08 PM, Noah Silverman wrote:
3) I purposefully chose NOT to install 64bit R.  I have a dual-core  
machine.  With the 32 bit version, R will happily keep one core  
running at 100%, but then I have other core free for my "regular"  
work.


Using 64bit R shouldn't change your CPU usage, so if you want to use  
it to deal with larger data, feel free to do so ... unless you  
explicitly write code to use >1 cpu, you'll still have another cpu  
free to do with what you will (assuming you have enough ram).


-steve


On 9/11/09 10:32 AM, Marc Schwartz wrote:

On Sep 11, 2009, at 12:15 PM, Victor Manuel Garcia Guerrero wrote:


Hi all,

I have been using R on Windows for a long time, but now I am ready  
to move to Mac OS X, but I was just wondering if R works better on  
Mac than on Windows. This is because I had some memory size issues  
in the past.


Another question is if some of you know an R editor for Mac (just  
like Tinn-R).


Thanks.


The notion of "better" is always in the eyes of the useR and will  
depend upon specific criteria.


OSX can run R in both 32 bit and 64 bit modes and indeed the  
default OSX download for R provided by Simon installs and supports  
both. If you use the 32 bit version, then from a memory management  
standpoint, you will not see demonstrable gains over Windows.  
However, with the 64 bit version, you will avail yourself of a much  
larger memory address space as compared to running 32 bit R on  
Windows. That of course presumes that you have a lot of RAM in your  
Mac to actually take advantage of the larger address space.


The 64 bit memory address space is also available via Linux, with  
appropriate hardware.



You might want to review the R OSX FAQ:

 http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html

and also note that there is a OSX specific e-mail list:

 https://stat.ethz.ch/mailman/listinfo/r-sig-mac


As far as editors, I am not familiar with the details of Tinn-R,  
but ESS/Emacs is available for OSX and this is what I use  
(continuing what I had been using on Linux for the past number of  
years).  Others will likely be able to provide other  
recommendations and you might want to search the R-SIG-Mac list  
archives as no doubt there have been such discussions in the past.


HTH,

Marc Schwartz

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


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


--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


Re: [R] how to determine if a variable is already set?

2009-09-11 Thread Duncan Murdoch

On 9/11/2009 1:15 PM, carol white wrote:

Hi,
It might be a primitive question but how it is possible to determine if a 
variable is initialized in an environment? Suppose that we start a R session 
and wants to run a script which use the variable i. Which function could 
evaluate if i is already initialized or not and if not, then ask interactively 
the user to set it? This is to avoid the error message: object i is not found.


See ?exists.

Duncan Murdoch

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


Re: [R] Matrix multiplication and random numbers

2009-09-11 Thread Henrique Dallazuanna
If I understand you can use replicate:

replicate(10, matmult(InitialPop, 1))


On Fri, Sep 11, 2009 at 1:11 PM, RFish  wrote:

>
> Hi
>
> Sorry I don't seem to have explained what I'm trying to do very clearly.
> The piece of code below multiplies the two matrices together a number of
> times based on the value in the matmult(InitialPop,1) term in this case one
> (year), this gives me the end population for the analysis.
>
> InitialPop<-matrix(c(500,0,0,0,0,0,0))
>
> matmult<-function(InitialPop,N){
>
> mat3<-matrix(c(0,rnorm(1,0.6021,0.0987),0,0,0,0,0,0,0,rnorm(1,0.6021,0.0987),0,0,0,0,1.9,0,0,rnorm(1,0.6021,0.0987),0,0,0,4.8,0,0,0,rnorm(1,0.6021,0.0987),0,0,9.7,0,0,0,0,rnorm(1,0.6021,0.0987),0,18,0,0,0,0,0,rnorm(1,0.6021,0.0987),32.6,0,0,0,0,0,0),nrow=7)
>
> for (i in 1:N){
>
> PVAmatrix<-matrix(c(0,rnorm(1,0.6021,0.0987),0,0,0,0,0,0,0,rnorm(1,0.6021,0.0987),0,0,0,0,1.9,0,0,rnorm(1,0.6021,0.0987),0,0,0,4.8,0,0,0,rnorm(1,0.6021,0.0987),0,0,9.7,0,0,0,0,rnorm(1,0.6021,0.0987),0,18,0,0,0,0,0,rnorm(1,0.6021,0.0987),32.6,0,0,0,0,0,0),nrow=7)
> mat3<-mat3%*%PVAmatrix
> }
> ans<-mat3 %*% InitialPop
> return(ans)
> }
> matmult(InitialPop,1)
>
> The problem i have is to repeat this process say 1000 times and store this
> output in a format I can export easily whilst maintaining the randomness of
> the result, so that every end population is different.
>
> Any help would be brilliant
>
> Tom
>
>
>
>
>
>
> Chris Stubben wrote:
> >
> >
> > RFish wrote:
> >>
> >> I new to using R and am struggling with some matrix multiplication.
> >>
> >
> > I'm not sure what you're trying to print, but you could place this vector
> > in an expression
> >
> >
> mat3<-expression(c(0,rnorm(1,0.6021,0.0987),0,0,0,0,0,0,0,rnorm(1,0.6021,0.0987),0,0,0,0,1.9,0,0,rnorm(1,0.6021,0.0987),0,0,0,4.8,0,0,0,rnorm(1,0.6021,0.0987),0,0,9.7,0,0,0,0,rnorm(1,0.6021,0.0987),0,18,0,0,0,0,0,rnorm(1,0.6021,0.0987),32.6,0,0,0,0,0,0))
> >
> > # and then evaluate to get a new matrix each time
> > matrix(eval(mat3), nrow=7)
> >
> > #I think this may be easier to follow. First create a matrix of zeros,
> > stick in fertilities and then add random survival probabilities each time
> >
> >
> > mat3<-diag(0,7)
> > #fertilities
> > mat3[1,3:7]<-c(1.9, 4.8, 9.7, 18, 32.6)
> > # random survival on sub-diagonal
> > mat3[row(mat3)==col(mat3)+1]<-rnorm(6,0.6021,0.0987)
> >
> >
> > # and if you want to project the population over 10 time steps in a loop
> ?
> >
> > n<-matrix(c(500,0,0,0,0,0,0))
> >
> > popsize <- matrix(numeric(7 * 10), nrow = 7)
> >  for (i in 1:10) {
> > popsize[, i] <- n
> >  mat3[row(mat3)==col(mat3)+1]<-rnorm(6,0.6021,0.0987)
> >  n <- mat3 %*% n
> > }
> >
> >
> >  [,1] [,2] [,3] [,4]  [,5]  [,6]   [,7]
> > [,8]
> > [1,]  500   0.   0. 531.6256 709.89940 940.19337 1697.52862
> > 3403.6610
> > [2,]0 352.5116   0.   0. 298.97874 424.71160  561.32525
> > 1027.1605
> > [3,]0   0. 279.8029   0.   0.0 231.45988  316.83352
> > 424.8883
> > [4,]0   0.   0. 147.8957   0.0   0.0  136.36804
> > 220.7370
> > [5,]0   0.   0.   0.  96.92715   0.00.0
> > 108.6551
> > [6,]0   0.   0.   0.   0.0  69.875270.0
> > 0.
> > [7,]0   0.   0.   0.   0.0   0.0   65.86229
> > 0.
> >
> >
> > Chris Stubben
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Matrix-multiplication-and-random-numbers-tp25365184p25403899.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

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


Re: [R] Moving to Mac OS X

2009-09-11 Thread Noah Silverman

Hi,

I'm a daily user of both mac and Linux so wanted to offer some thoughts:


1) R runs great on a Mac.  There is a standard install from the cran 
website that has a nice GUI built into it.  You can do things like drag 
files to the console and it will fill in the path name.


2) I like using BBedit for all my programming needs.  IMHO BBedit is the 
most powerful editor I've seen in my many years of programming.  There 
is a small plugin that understands the R language.  My general workflow 
is to write code in BBedit and then run it in R using the "source" 
function.


3) I purposefully chose NOT to install 64bit R.  I have a dual-core 
machine.  With the 32 bit version, R will happily keep one core running 
at 100%, but then I have other core free for my "regular" work.


--
N



On 9/11/09 10:32 AM, Marc Schwartz wrote:

On Sep 11, 2009, at 12:15 PM, Victor Manuel Garcia Guerrero wrote:


Hi all,

I have been using R on Windows for a long time, but now I am ready to 
move to Mac OS X, but I was just wondering if R works better on Mac 
than on Windows. This is because I had some memory size issues in the 
past.


Another question is if some of you know an R editor for Mac (just 
like Tinn-R).


Thanks.


The notion of "better" is always in the eyes of the useR and will 
depend upon specific criteria.


OSX can run R in both 32 bit and 64 bit modes and indeed the default 
OSX download for R provided by Simon installs and supports both. If 
you use the 32 bit version, then from a memory management standpoint, 
you will not see demonstrable gains over Windows. However, with the 64 
bit version, you will avail yourself of a much larger memory address 
space as compared to running 32 bit R on Windows. That of course 
presumes that you have a lot of RAM in your Mac to actually take 
advantage of the larger address space.


The 64 bit memory address space is also available via Linux, with 
appropriate hardware.



You might want to review the R OSX FAQ:

  http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html

and also note that there is a OSX specific e-mail list:

  https://stat.ethz.ch/mailman/listinfo/r-sig-mac


As far as editors, I am not familiar with the details of Tinn-R, but 
ESS/Emacs is available for OSX and this is what I use (continuing what 
I had been using on Linux for the past number of years).  Others will 
likely be able to provide other recommendations and you might want to 
search the R-SIG-Mac list archives as no doubt there have been such 
discussions in the past.


HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


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


Re: [R] How to Label Certain Lags for a PACF Graph

2009-09-11 Thread Henrique Dallazuanna
Try this:

pacf(data$R1, main = "Series R1 Residuals", xaxt = 'n')
axis(1, c(1, axTicks(1)))

On Fri, Sep 11, 2009 at 1:02 PM, Stephanie Cooke
wrote:

> When I use the command for PACF, lags 5, 10, 15, and 20 are labeled. I
> would
> like to label lag 1. I would greatly appreciate if someone could tell me
> how
> to do this. Below is the command that I am using:
>
> pacf(data$R1,main="Series R1 Residuals")
>
>[[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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

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


Re: [R] How to Label Certain Lags for a PACF Graph

2009-09-11 Thread Jorge Ivan Velez
Hi Stephanie,
Take a look at the "xaxt" argument under ?par as well as ?axis.  Here is an
example modified from ?pacf :

acf(lh, xaxt = "n")
axis(1,  0:16, 0:16,  cex.axis = 0.8)

HTH,
Jorge


On Fri, Sep 11, 2009 at 12:02 PM, Stephanie Cooke  wrote:

> When I use the command for PACF, lags 5, 10, 15, and 20 are labeled. I
> would
> like to label lag 1. I would greatly appreciate if someone could tell me
> how
> to do this. Below is the command that I am using:
>
> pacf(data$R1,main="Series R1 Residuals")
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] NLME

2009-09-11 Thread Jeff in NC

I am trying to use one of the variance function classes (e.g., varClasses
-varConstPower or varPower)

When I run the model under default conditions or specify varIdent explicitly
I do not have any problems.  If I try to use anything else I get error
messages of the form 

"Error in na.fail.default(list(USUBJID = c(1636L, 1636L, 1636L, 1636L,  : 
  missing values in object"

I have simplified my data to the bare minimum, I am positive there are no
missing records, and my initial parameter estimates are in a range where the
model happily converges otherwise. I am a bit unsure as to what is going on. 
Does anyone have anything to suggest for diagnosing this problem?

Thanks
-- 
View this message in context: 
http://www.nabble.com/NLME-tp25405582p25405582.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Matrix multiplication and random numbers

2009-09-11 Thread RFish

Hi

Sorry I don't seem to have explained what I'm trying to do very clearly.
The piece of code below multiplies the two matrices together a number of
times based on the value in the matmult(InitialPop,1) term in this case one
(year), this gives me the end population for the analysis. 

InitialPop<-matrix(c(500,0,0,0,0,0,0))

matmult<-function(InitialPop,N){
mat3<-matrix(c(0,rnorm(1,0.6021,0.0987),0,0,0,0,0,0,0,rnorm(1,0.6021,0.0987),0,0,0,0,1.9,0,0,rnorm(1,0.6021,0.0987),0,0,0,4.8,0,0,0,rnorm(1,0.6021,0.0987),0,0,9.7,0,0,0,0,rnorm(1,0.6021,0.0987),0,18,0,0,0,0,0,rnorm(1,0.6021,0.0987),32.6,0,0,0,0,0,0),nrow=7)

for (i in 1:N){
PVAmatrix<-matrix(c(0,rnorm(1,0.6021,0.0987),0,0,0,0,0,0,0,rnorm(1,0.6021,0.0987),0,0,0,0,1.9,0,0,rnorm(1,0.6021,0.0987),0,0,0,4.8,0,0,0,rnorm(1,0.6021,0.0987),0,0,9.7,0,0,0,0,rnorm(1,0.6021,0.0987),0,18,0,0,0,0,0,rnorm(1,0.6021,0.0987),32.6,0,0,0,0,0,0),nrow=7)
mat3<-mat3%*%PVAmatrix
}
ans<-mat3 %*% InitialPop
return(ans)
}
matmult(InitialPop,1)

The problem i have is to repeat this process say 1000 times and store this
output in a format I can export easily whilst maintaining the randomness of
the result, so that every end population is different. 

Any help would be brilliant

Tom  


 



Chris Stubben wrote:
> 
> 
> RFish wrote:
>> 
>> I new to using R and am struggling with some matrix multiplication. 
>> 
> 
> I'm not sure what you're trying to print, but you could place this vector
> in an expression
> 
> mat3<-expression(c(0,rnorm(1,0.6021,0.0987),0,0,0,0,0,0,0,rnorm(1,0.6021,0.0987),0,0,0,0,1.9,0,0,rnorm(1,0.6021,0.0987),0,0,0,4.8,0,0,0,rnorm(1,0.6021,0.0987),0,0,9.7,0,0,0,0,rnorm(1,0.6021,0.0987),0,18,0,0,0,0,0,rnorm(1,0.6021,0.0987),32.6,0,0,0,0,0,0))
> 
> # and then evaluate to get a new matrix each time
> matrix(eval(mat3), nrow=7)
> 
> #I think this may be easier to follow. First create a matrix of zeros,
> stick in fertilities and then add random survival probabilities each time
> 
> 
> mat3<-diag(0,7)
> #fertilities
> mat3[1,3:7]<-c(1.9, 4.8, 9.7, 18, 32.6)
> # random survival on sub-diagonal
> mat3[row(mat3)==col(mat3)+1]<-rnorm(6,0.6021,0.0987)
> 
> 
> # and if you want to project the population over 10 time steps in a loop ?
> 
> n<-matrix(c(500,0,0,0,0,0,0))
> 
> popsize <- matrix(numeric(7 * 10), nrow = 7)
>  for (i in 1:10) {
> popsize[, i] <- n
>  mat3[row(mat3)==col(mat3)+1]<-rnorm(6,0.6021,0.0987)
>  n <- mat3 %*% n
> }
> 
> 
>  [,1] [,2] [,3] [,4]  [,5]  [,6]   [,7] 
> [,8]
> [1,]  500   0.   0. 531.6256 709.89940 940.19337 1697.52862
> 3403.6610
> [2,]0 352.5116   0.   0. 298.97874 424.71160  561.32525
> 1027.1605
> [3,]0   0. 279.8029   0.   0.0 231.45988  316.83352 
> 424.8883
> [4,]0   0.   0. 147.8957   0.0   0.0  136.36804 
> 220.7370
> [5,]0   0.   0.   0.  96.92715   0.00.0 
> 108.6551
> [6,]0   0.   0.   0.   0.0  69.875270.0   
> 0.
> [7,]0   0.   0.   0.   0.0   0.0   65.86229   
> 0.
> 
> 
> Chris Stubben
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Matrix-multiplication-and-random-numbers-tp25365184p25403899.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] How to Label Certain Lags for a PACF Graph

2009-09-11 Thread Stephanie Cooke
When I use the command for PACF, lags 5, 10, 15, and 20 are labeled. I would
like to label lag 1. I would greatly appreciate if someone could tell me how
to do this. Below is the command that I am using:

pacf(data$R1,main="Series R1 Residuals")

[[alternative HTML version deleted]]

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


[R] R help:

2009-09-11 Thread Matthew Fantle
Hi

I have written a code to do some averaging of data over uneven  
intervals. The for loop keeps missing particular depths and I once got  
an error message reading:

  *** caught segfault ***
address 0xc023, cause 'memory not mapped'

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

The portion of the code that is giving me problems is:

if(length(which( interp.depth == highres.depth[i] )) >0 ) {
print(paste("depth = ",highres.depth[i],sep=""))
depth.tracker <- c(highres.depth[i],depth.tracker)
caco3.interp.vector <- 
c(mean(caco3.interp),caco3.interp.vector)
caco3.interp <- numeric(0)
}

When the routine misses a depth, it returns a length of zero for (say)  
depth = 1.4, or highres.depth[141]. but when i type in the value 1.4,  
I get the proper answer. Any idea what is going on here?

thanks
Matt

__
Matthew S. Fantle
Assistant Professor
Department of Geosciences
Penn State University
212 Deike Bldg.
University Park, PA 16802

Phone: 814-863-9968
mfan...@psu.edu

Departmental Homepage
http://www.geosc.psu.edu/people/faculty/personalpages/mfantle/index.html





[[alternative HTML version deleted]]

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


Re: [R] Barplot+Table

2009-09-11 Thread Henrique Dallazuanna
Try the textplot function in the gplots package:

nf <- layout(matrix(1:2), height = lcm(12))
par(mar = c(2, 8, 2, 2))
barplot(prop.table(example.table, 1), beside = TRUE)
textplot(round(prop.table(example.table, 1), 2), halign = 'left',
 mar = c(0,0,0,0), show.colnames = FALSE, cex = 2,
 cmar = 5)


On Fri, Sep 11, 2009 at 3:20 PM, Andy Choens  wrote:

> I am trying to automate a report that my company does every couple of years
> for the state of Maine. In the past we have used SPSS to run the data and
> then
> used complicated Excel template to make the tables/graphics which we then
> imported into Word. Since there are 256 tables/graphics for this report,
> this
> work flow is a little painful. I would like to automate the process and I
> think
> I can do so with odfWeave and R, but I've run into a problem. I can't seem
> to
> get the output from R to look like what we have used in the past. Here's an
> example of what I need it to look like (sorry for the long URL)
>
> http://1.bp.blogspot.com/_TRRvdLHNnE8/SqpP5gFG3DI/BgY/09x-
> LoLtfTI/s1600-h/example+graphic.png
>
> My boss is open to using another tool (R) to get the work done but my final
> output needs to look, more or less, like what we did last time.
>
> I can make a table and I can make a bar graph that, essentially gets me
> where
> I want to go (I can handle the tweaking) but I don't know how to put them
> together and make things line up, as in my example (URL).
>
> I have looked at iplot, ggplot, lattice, etc. I will confess that my
> knowledge
> of R's graphical capabilities leaves a lot to be desired (as I am proving
> today) but I really can not find an example or feature that seems to do
> what I
> am trying to do. I am more or less satisfied with the plot, but I really
> would
> like to line up the table with the graphics, which is why I don't just put
> a
> table under the graph via odfweave.
>
> Here's what I have thus far:
>
> ###
> # These numbers are just BS I made up.
> counties <-
>
> c("County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2")
>
> gender <- c("Male", "Male","Male", "Male", "Male", "Female","Female",
> "Female","Male", "Male","Male", "Female","Male", "Female","Male",
> "Female","Male", "Female","Female", "Female","Male", "Female","Male",
> "Male")
>
> weight <- c(1,2,1,2,1,2,2,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2)
>
> example.table<-xtabs(weight~counties+gender)
> barplot(prop.table(example.table,1),beside=T)
> ###
>
> I am open to using any of the various graphics systems provided in R. I am
> willing/capable of learning and in fact, I want to learn how to do this but
> I
> can't even figure out which system I should spend my time learning more
> about
> and I don't have time to become an expert with all of them.
>
> Thank you.
>
> __
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

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


[R] How to block data across multiple columns?

2009-09-11 Thread A Singh


Dear all,

Does anyone have any suggestions on how to block multiple columns of data 
one at a time in the midst of an analysis, having specified the blocking 
variable?


I am running a random effects model using lmer, and my data set has 
multiple columns.
Individuals in the study are grouped into 60 families- which is the 
blocking factor.
The random effects are markers (labeled Pxlyy below) that have two levels- 
1 (presence) or 0 (absence).


I need to estimate Variance Components for 'peg.no' (family wise, which is 
why this is the blocking factor), explained by each PxLyy, and by 'family' 
as well.


I have managed to run the lmer model for the first marker column (P1L55), 
and have been able to block it according to 'family' as follows:


vc<-read.table("P:\\R\\Testvcomp10.txt",header=T)
attach(vc)
family<-factor(family)
colms<-(vc)[4:13] ## these are the marker columns
lapply(colms,factor)
library(lme4)

for (f in levels(family)) {
print("Family")
print(f)
{
t<- vc [ family == f, ]
try(lmer<-fit(peg.no~1 + (1|P1L55) + (1|family), data=t, 
na.action=na.exclude))

print(summary(fit))
}}


However I need to do this for 10 PxLyy columns simultaneously, so that I 
have 60 families * 10 markers= 600 runs of the model.


To do this I tried,

for (c in 1:length (colms))
{
for (f in levels (family))
{
print("Marker")
print(c)
print ("Family")
print(f)

{
t<- vc[family == f,] ## this is where I lose the plot

try(fit<-lmer(peg.no~1 + (1|c)+ (1|family), data=t, na.action=na.exclude))
print(summary(fit))
}}}


This however, doesn't run at all after the first two loops.
I cannot figure out how to tell it to block each one of 10 columns in turn. 
This works for one marker, but not more in the same run.


Any suggestions please?

Thanks a lot,
Aditi



Data files at:

 (excel)
http://www.4shared.com/file/131980512/dc7308b/Testvcomp10.html
(txt)


-
A Singh
aditi.si...@bristol.ac.uk
School of Biological Sciences
University of Bristol

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


Re: [R] help with plotting

2009-09-11 Thread Steve Lianoglou

Hi Edward,

On Sep 11, 2009, at 1:47 PM, Edward Chen wrote:


HI all,
raw_urine =
read.table("Z:\\bruce.9.3.09.sample.stability.analysis\\urine\\mz.spot.sam.dat.new 
",

header = TRUE )
pvalue =
read.table("Z:\\bruce.9.3.09.sample.stability.analysis\\urine\\all.urine.features.t.test.result 
",

header = TRUE )
library(compositions)
p = function(a,b){
y = pvalue[,a]
if(y<0.01){
index = which(y, arr.ind=TRUE)
day1 = raw_urine[index,3:7]
day2 = raw_urine[index,b]
graph = {matplot(raw_urine[index,1],day1,lwd = 3)
matpoints(raw_urine[index,1],day2,lwd = 3, col="red")}
print(graph)
}}

the above is my sample code in which i'm trying to output some  
graphs. but

however, I can get return() to return value I want and all.


I don't see a return() call.


But I just don't
know if there's anything special I need to use to output graphs.
I get this error msg: " Warning message:
In if (y < 0.01) { :
 the condition has length > 1 and only the first element will be used"


That's not an error, but a warning -- your code runs, but might be  
doing something you don't expect it to be doing, since you're doing  
something a bit non-intuitive:


R> a <- c(TRUE, FALSE, TRUE, TRUE)
R> if (a) cat("Hi\n") else cat("Bye\n")
Hi
Warning message:
In if (a) cat("Hi\n") else cat("Bye\n") :
  the condition has length > 1 and only the first element will be used

You see how length(a) > 1 -- what should ``if (a)`` evaluate to? R is  
telling you that it's just evaluating a[1].


So, maybe your data isn't what you expect it to be?

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


Re: [R] Working with large matrix

2009-09-11 Thread Steve Lianoglou

Hi,

On Sep 11, 2009, at 1:15 PM, A Ezhil wrote:


Dear All,

I have large matrix (46000 x 11250). I would like to do the linear  
regression for each row. I wrote a simple function that has lm() and  
used apply(mat,1,func). The issue is that it takes ages to load the  
file and also to finish the lm. I am using LINUX 64 bit with 32G  
mem. Is there an elegant and fast way of completing this task?


Do bigmemory and biglm help?

http://cran.r-project.org/web/packages/bigmemory
http://cran.r-project.org/web/packages/biglm

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


[R] Barplot+Table

2009-09-11 Thread Andy Choens
I am trying to automate a report that my company does every couple of years 
for the state of Maine. In the past we have used SPSS to run the data and then 
used complicated Excel template to make the tables/graphics which we then 
imported into Word. Since there are 256 tables/graphics for this report, this 
work flow is a little painful. I would like to automate the process and I think 
I can do so with odfWeave and R, but I've run into a problem. I can't seem to 
get the output from R to look like what we have used in the past. Here's an 
example of what I need it to look like (sorry for the long URL)

http://1.bp.blogspot.com/_TRRvdLHNnE8/SqpP5gFG3DI/BgY/09x-
LoLtfTI/s1600-h/example+graphic.png

My boss is open to using another tool (R) to get the work done but my final 
output needs to look, more or less, like what we did last time. 

I can make a table and I can make a bar graph that, essentially gets me where 
I want to go (I can handle the tweaking) but I don't know how to put them 
together and make things line up, as in my example (URL).

I have looked at iplot, ggplot, lattice, etc. I will confess that my knowledge 
of R's graphical capabilities leaves a lot to be desired (as I am proving 
today) but I really can not find an example or feature that seems to do what I 
am trying to do. I am more or less satisfied with the plot, but I really would 
like to line up the table with the graphics, which is why I don't just put a 
table under the graph via odfweave.

Here's what I have thus far:

###
# These numbers are just BS I made up.
counties <- 
c("County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2","County1","County2")

gender <- c("Male", "Male","Male", "Male", "Male", "Female","Female", 
"Female","Male", "Male","Male", "Female","Male", "Female","Male", 
"Female","Male", "Female","Female", "Female","Male", "Female","Male", "Male")

weight <- c(1,2,1,2,1,2,2,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2) 

example.table<-xtabs(weight~counties+gender)
barplot(prop.table(example.table,1),beside=T)
###

I am open to using any of the various graphics systems provided in R. I am 
willing/capable of learning and in fact, I want to learn how to do this but I 
can't even figure out which system I should spend my time learning more about 
and I don't have time to become an expert with all of them.

Thank you.

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


[R] help with plotting

2009-09-11 Thread Edward Chen
HI all,
raw_urine =
read.table("Z:\\bruce.9.3.09.sample.stability.analysis\\urine\\mz.spot.sam.dat.new",
header = TRUE )
pvalue =
read.table("Z:\\bruce.9.3.09.sample.stability.analysis\\urine\\all.urine.features.t.test.result",
header = TRUE )
library(compositions)
p = function(a,b){
y = pvalue[,a]
if(y<0.01){
index = which(y, arr.ind=TRUE)
day1 = raw_urine[index,3:7]
day2 = raw_urine[index,b]
graph = {matplot(raw_urine[index,1],day1,lwd = 3)
matpoints(raw_urine[index,1],day2,lwd = 3, col="red")}
print(graph)
}}

the above is my sample code in which i'm trying to output some graphs. but
however, I can get return() to return value I want and all. But I just don't
know if there's anything special I need to use to output graphs.
I get this error msg: " Warning message:
In if (y < 0.01) { :
  the condition has length > 1 and only the first element will be used"

everything was fine until i put in graphing functions in the end.
Thanks.

-- 
Edward Chen
Email: edche...@gmail.com
Cell Phone: 510-371-4717

[[alternative HTML version deleted]]

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


Re: [R] Moving to Mac OS X

2009-09-11 Thread Steve Lianoglou

Hi,

On Sep 11, 2009, at 1:15 PM, Victor Manuel Garcia Guerrero wrote:


Hi all,

I have been using R on Windows for a long time, but now I am ready  
to move to Mac OS X, but I was just wondering if R works better on  
Mac than on Windows. This is because I had some memory size issues  
in the past.


64bit R (from http://r.research.att.com/) works great on 64 bit macs  
w/ OS X ... my R sessions have chewed up all of the 8gb of ram on my  
cpu that were available if need be (and choked the rest of my system).


Another question is if some of you know an R editor for Mac (just  
like Tinn-R).


I'm not sure that there's a consensus. Here's a very recent thread:

http://thread.gmane.org/gmane.comp.lang.r.general/161063/focus=161335

All the usual players:

 * Emacs w/ ESS
 * JGR
 * Eclipse + StatET plugin
 * I understand people are excited about an R plugin for jEdit that  
this guy is working on: http://romainfrancois.blog.free.fr/


I use TextMate .. there's an R.bundle for it which I don't really use  
aside from its syntax highlighting, though it does more (like sending  
commands to (some) R process). Works great w/ LaTeX+Sweave, too.  It  
seems that's all I really need as I spend most of my time in the  
terminal then sourcing some file that has the functions I'm trying to  
refine anyway ...


-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


Re: [R] Moving to Mac OS X

2009-09-11 Thread Marc Schwartz

On Sep 11, 2009, at 12:15 PM, Victor Manuel Garcia Guerrero wrote:


Hi all,

I have been using R on Windows for a long time, but now I am ready  
to move to Mac OS X, but I was just wondering if R works better on  
Mac than on Windows. This is because I had some memory size issues  
in the past.


Another question is if some of you know an R editor for Mac (just  
like Tinn-R).


Thanks.


The notion of "better" is always in the eyes of the useR and will  
depend upon specific criteria.


OSX can run R in both 32 bit and 64 bit modes and indeed the default  
OSX download for R provided by Simon installs and supports both. If  
you use the 32 bit version, then from a memory management standpoint,  
you will not see demonstrable gains over Windows. However, with the 64  
bit version, you will avail yourself of a much larger memory address  
space as compared to running 32 bit R on Windows. That of course  
presumes that you have a lot of RAM in your Mac to actually take  
advantage of the larger address space.


The 64 bit memory address space is also available via Linux, with  
appropriate hardware.



You might want to review the R OSX FAQ:

  http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html

and also note that there is a OSX specific e-mail list:

  https://stat.ethz.ch/mailman/listinfo/r-sig-mac


As far as editors, I am not familiar with the details of Tinn-R, but  
ESS/Emacs is available for OSX and this is what I use (continuing what  
I had been using on Linux for the past number of years).  Others will  
likely be able to provide other recommendations and you might want to  
search the R-SIG-Mac list archives as no doubt there have been such  
discussions in the past.


HTH,

Marc Schwartz

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


[R] R/S Programmer Employment Opportunity - New York, NY

2009-09-11 Thread Wesley Madison
R / S Programmer - New York

Description:
Kaplan Test Prep & Admissions is looking for a R / S Programmer to join
their research based in New York City. We are looking for highly
motivated individuals to work in a customer-focused environment.

This is a unique opportunity to develop with a leading educational
company with a diverse series of statistical applications in
education/learning, operations, marketing, and finance.

The Role



 

*   To provide ad-hoc programming services to customers
*   To create and deliver tailored software applications and
libraries to internal clients
*   To participate in the design and implementation of cloud-based
statistical high-performance computing applications


Qualifications



 

*   Knowledge of statistical languages: S-PLUS or R, and SQL
*   Excellent communication skills
*   Experience of general software systems is an advantage (eg.
Java, Ruby, Oracle, XML, HTML


Offering



 

*   Opportunity to extend your technical knowledge while working in
a dynamic environment with a diverse group of clients
*   Flexible working environment and working hours
*   Competitive salary depending on experience
*   Great benefits


If you are interested in applying for this position please send a copy
of your resume and cover letter to wesley.madi...@kaplan.com .  


Salary/Benefits: Salary commensurate with experience
Full time employees enjoy these outstanding benefits: 
*401(k) plan 
*Comprehensive health, dental and short term disability & long 
term disability plans 
*Business casual dress code 
*Sick days, personal days, holidays, and vacation days 
*A friendly, team oriented environment


Company URL: http://www.kaplan.com   

Company Profile:
Kaplan Test Prep and Admissions (www.kaptest.com), a division of Kaplan,
Inc., is a premier provider of educational and career services for
individuals, schools and businesses. Established in 1938, Kaplan Test
Prep and Admissions is the world leader in the test prep industry and
has served millions of students in nearly 70 years. With 3,000 classroom
locations worldwide, a comprehensive menu of online offerings and a
complete array of books and software, and private tutoring options,
Kaplan offers preparation for more than 60 standardized tests in the
U.S. and the U.K., including entrance exams for secondary school,
college and graduate school, as well as English language and
professional licensing exams. Kaplan also provides college and graduate
admissions consulting services, as well as after-school learning
programs for K-10 students through its SCORE! centers. Additionally, the
division's K12 Learning Services unit is a leading nationwide provider
of a broad range of academic intervention and support programs for
school districts seeking to meet the demands of No Child Left Behind
(NCLB).




[[alternative HTML version deleted]]

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


Re: [R] AIC and goodness of prediction - was: Re: goodness of "prediction" using a model (lm, glm, gam, brt,

2009-09-11 Thread Kingsford Jones
Hi Corrado,

Not being familiar with your research goals or data I can't make
recommendations, but I can suggest a couple of places to look for
information:  Frank Harrell's Regression Modeling Strategies and his
Design library available on CRAN, and Hastie et al's The Elements of
Statistical Learning.

A couple more comments below..

On Thu, Sep 10, 2009 at 11:48 AM, Corrado  wrote:
> Dear Kingsford,
>
> I apologise for breaking the thread, but I thought there were some more people
> who would be interested.
>
> What you propose is what I am using at the moment: the sum of the squares of
> the residuals, plus  variance / stdev. I am not really satisfied. I have also
> tried using R2, and it works well  but some people go a bit wild eyed when
> they see a negative R2 (which is perfectly reasonable when you use R2 as a
> measure of goodness of fit on prediction on a dataset different from the
> training set).

To get negative values I'm guessing you're using 1 - ((sum((obs -
pred)^2)) / (sum((obs - mean(obs))^2))?  If so a negative value
indicates the model is a worse predictor than using a constant.  Also
note the formula is just a linear transform of the one mentioned in my
last email.

>
> I was then wondering whether it would make sense to use AIC: the K in the
> formula will still be the number of parameters of the trained model, the "sum
> of square residuals" would be the (predicted - observed)^2, N would be the
> number of samples in the test dataset. I think it should work well.
>

Generally, when assessing predictive ability one is not concerned with
the number of parameters -- just how good the predictions are on data
that is independent of the model selection and fitting process.  Also,
the general definition of AIC uses likelihoods not SS residuals.
Also, using the SS resids you are once again back to a linear
transormation of the MSE estimate...


Kingsford




> What do you / other R list members think?
>
> Regards
>
> On Thursday 03 September 2009 15:06:14 Kingsford Jones wrote:
>> There are many ways to measure prediction quality, and what you choose
>> depends on the data and your goals.  A common measure for a
>> quantitative response is mean squared error (i.e. 1/n * sum((observed
>> - predicted)^2)) which incorporates bias and variance.  Common terms
>> for what you are looking for are "test error" and "generalization
>> error".
>>
>>
>> hth,
>> Kingsford
>>
>> On Wed, Sep 2, 2009 at 11:56 PM, Corrado wrote:
>> > Dear R-friends,
>> >
>> > How do you test the goodness of prediction of a model, when you predict
>> > on a set of data DIFFERENT from the training set?
>> >
>> > I explain myself: you train your model M (e.g. glm,gam,regression tree,
>> > brt) on a set of data A with a response variable Y. You then predict the
>> > value of that same response variable Y on a different set of data B (e.g.
>> > predict.glm, predict.gam and so on). Dataset A and dataset B are
>> > different in the sense that they contain the same variable, for example
>> > temperature, measured in different sites, or on a different interval
>> > (e.g. B is a subinterval of A for interpolation, or a different interval
>> > for extrapolation). If you have the measured values for Y on the new
>> > interval, i.e. B, how do you measure how good is the prediction, that is
>> > how well model fits the Y on B (that is, how well does it predict)?
>> >
>> > In other words:
>> >
>> > Y~T,data=A for training
>> > Y~T,data=B for predicting
>> >
>> > I have devised a couple of method based around 1) standard deviation 2)
>> > R^2, but I am unhappy with them.
>> >
>> > Regards
>> > --
>> > Corrado Topi
>> >
>> > Global Climate Change & Biodiversity Indicators
>> > Area 18,Department of Biology
>> > University of York, York, YO10 5YW, UK
>> > Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk
>> >
>> > __
>> > 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.
>
>
>
> --
> Corrado Topi
>
> Global Climate Change & Biodiversity Indicators
> Area 18,Department of Biology
> University of York, York, YO10 5YW, UK
> Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk
>
>

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


Re: [R] transposing a distance matrix in R

2009-09-11 Thread Henrique Dallazuanna
Try this also:

subset(as.data.frame.table(m), !is.na(Freq))

On Fri, Sep 11, 2009 at 1:48 PM, Steve Lianoglou <
mailinglist.honey...@gmail.com> wrote:

> Hi Jeannine,
>
> I'm just forwarding this Q&A back to the r-help list, you'll get more eyes
> on it and other people might have better solutions.
>
> Answers inline:
>
> On Sep 11, 2009, at 12:25 PM, Jeannine Cavender-Bares wrote:
>
>  Dear Steve,
>>
>> Greetings! You helped me earlier this summer with an R question in
>> response to a message Brian McCarthy put out on the listserv. I was
>> wondering if you happen to know the answer to the following question or if
>> you can explain how I subscribe to the listserv. Can one just send a message
>> to  r-h...@r-project.org?
>>
>
> You can subscribe to the listserv from here:
>
> https://stat.ethz.ch/mailman/listinfo/r-help
>
>  Here goes:
>> How does one convert a triangular distance matrix into a single column
>> distance matrix?: e.g.,
>>
>> traingular:
>>   A   B   C
>> A na na na
>> B 1   na na
>> C 0   1   na
>>
>> single column:
>> BA 1
>> CA 0
>> CB 1
>>
>
> Getting the distances from your matrix is pretty straightforward since
> they're all in the lower triangle of the matrix, see: ?lower.tri
>
> R> m <- matrix(c(NA,1,0,NA,NA,1,NA,NA,NA), 3)
> R> dimnames(m) <- list(c('A','B','C'), c('A','B','C'))
> R> m[lower.tri(m)]
> [1] 1 0 1
>
> Getting the names for the distances is a bit more tricky. I'm trying to do
> that with the "expand.grid" function, check it out to see how it works:
> ?expand.grid
>
> R> who.vs.who <- expand.grid(rownames(m), rownames(m))
> R> who.vs.who
>  Var1 Var2
> 1AA
> 2BA
> 3CA
> 4AB
> 5BB
> 6CB
> 7AC
> 8BC
> 9CC
>
> We can use the same index generated by ``lower.tri(m)`` to get the names of
> the rows vs cols since R stores the elements of a matrix in column major
> order[1] (note that when I created the matrix ``m``, I used a vector that
> filled a matrix column by column). When you use a single integer to index
> into a matrix, it calculates which position to pull out in the same (column
> major) order, so:
>
>  * ``m[1]`` is really element m[1,1]
>  * ``m[2]`` is really element m[2,1], etc ...
>
> So now:
>
> R> who.vs.who[lower.tri(m),]
>  Var1 Var2
> 2BA
> 3CA
> 6CB
>
> ... almost there, no just put it together:
>
> R> dist <- m[lower.tri(m)]
> R> who <- who.vs.who[lower.tri(m),]
> R> names(dist) <- paste(who[,1], who[,2], sep=".vs.")
> R> dist
> B.vs.A C.vs.A C.vs.B
> 1  0  1
>
> HTH,
> -steve
>
> [1] Column major format:
> http://en.wikipedia.org/wiki/Row-major_order#Column-major_order
>
> --
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
>  |  Memorial Sloan-Kettering Cancer Center
>  |  Weill Medical College of Cornell University
> Contact Info: 
> http://cbio.mskcc.org/~lianos/contact
>
> __
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

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


[R] how to determine if a variable has already been initialized?

2009-09-11 Thread carol white
Hi,
It might be a primitive question but how it is possible to determine if a 
variable is initialized in an environment? Suppose that we start a R session 
and wants to run a script which uses the variable i. Which function could 
evaluate if i exists already and has been initialized or not? The purpose is to 
avoid the message: error, object i is not found.

Regards,

Carol



  
[[alternative HTML version deleted]]

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


Re: [R] how to determine if a variable is already set?

2009-09-11 Thread Marc Schwartz

On Sep 11, 2009, at 12:15 PM, carol white wrote:


Hi,
It might be a primitive question but how it is possible to determine  
if a variable is initialized in an environment? Suppose that we  
start a R session and wants to run a script which use the variable  
i. Which function could evaluate if i is already initialized or not  
and if not, then ask interactively the user to set it? This is to  
avoid the error message: object i is not found.


Regards,

Carol



See ?exists

Note that this will tell you if the object exists, not if it contains  
a specifically desired initial value. You would have to check for the  
latter after determining that the object does indeed exist.


HTH,

Marc Schwartz

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


[R] Working with large matrix

2009-09-11 Thread A Ezhil
Dear All,

I have large matrix (46000 x 11250). I would like to do the linear regression 
for each row. I wrote a simple function that has lm() and used 
apply(mat,1,func). The issue is that it takes ages to load the file and also to 
finish the lm. I am using LINUX 64 bit with 32G mem. Is there an elegant and 
fast way of completing this task?

Thanks in advance.

Kind regards,
Ezhil

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


[R] Moving to Mac OS X

2009-09-11 Thread Victor Manuel Garcia Guerrero
Hi all,
 
I have been using R on Windows for a long time, but now I am ready to move to 
Mac OS X, but I was just wondering if R works better on Mac than on Windows. 
This is because I had some memory size issues in the past. 
 
Another question is if some of you know an R editor for Mac (just like Tinn-R).
 
Thanks.
 
Víctor Manuel García Guerrero
Doctorado en Estudios de Población,
CEDUA, COLMEX
Camino al Ajusco N° 20, Pedregal de Sta. Teresa
C.P.10740, Tlalpan, México, D.F.

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


[R] how to determine if a variable is already set?

2009-09-11 Thread carol white
Hi,
It might be a primitive question but how it is possible to determine if a 
variable is initialized in an environment? Suppose that we start a R session 
and wants to run a script which use the variable i. Which function could 
evaluate if i is already initialized or not and if not, then ask interactively 
the user to set it? This is to avoid the error message: object i is not found.

Regards,

Carol



  
[[alternative HTML version deleted]]

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


Re: [R] Completion for proto objects

2009-09-11 Thread Gabor Grothendieck
You might check the bugs section on the proto home page
and if any of those seem to apply try the devel version of
proto (or the workaround mentioned) as all known bugs are fixed
in the devel version.  If that does not help let me know offline
and I will try to help you.

See: http://r-proto.googlecode.com

On Fri, Sep 11, 2009 at 12:39 PM, Vitalie S.  wrote:
> On Fri, 11 Sep 2009 16:07:45 +0200, Gabor Grothendieck
>  wrote:
>
>> See ?assignInNamespace
>>
>
> thanks for the hint. It works to some extent. Functions are redefined in
> "base" but utils:::specialCompletions seems not to preform properly:
>
> ls.proto <- function(x){  # function to complete
>    .local <- function(x){
>        if(is(x[[".super"]], "proto")) c(ls.default(x),
> Recall(x[[".super"]]))
>        else ls.default(x)
>    }
>    unlist(.local(x))
> }
>
> ls1 <- base::ls # cache ls
>
> ls.default1 <- function(name, pos = -1, envir = as.environment(pos),
> all.names = FALSE,     pattern){
>    UseMethod("ls")
> }
>
> assignInNamespace("ls.default", ls1 , 'base')
> assignInNamespace("ls", ls.default1 , 'base')
> assignInNamespace("ls.proto", ls.proto , 'base')
>
> environment(ls) <- asNamespace('base')
> environment(ls.default) <- asNamespace('base')
> environment(ls.proto) <- asNamespace('base')
>
> p1 <- proto(p1_abc=123)
> p2 <- proto(.=p1, p2_abc=23423)
>
> ls(p2)
> [1] "p2_abc" "p1_abc"   #works fine 
>>
>> ls(p1)
>
> [1] "p1_abc"
>>
>
> Completion for $ works fine with environments and everything else, but not
> with proto objects.
> also ls.str (which uses ls internally) gives an error.
>
>> ls.str(p1)
>
> Error in ls(name, envir = envir, all.names = all.names, pattern = pattern) :
>  argument "name" is missing, with no default
>>
>
> What is going on??  My ls.proto works nicely in global env but does not when
> called from attached packages?
> Would really appreciate if someone can enlighten me.
>
> Thanks a lot.
>
> PS: I also tried to modify utils:::specialCompletions directly, did not wok
> either - it's something wrong with ls.proto above :(.
>
>> On Fri, Sep 11, 2009 at 10:02 AM, Vitalie S.  wrote:
>>>
>>> Hello everyone,
>>>
>>> I am trying to implement completion for proto objects. Proto extends
>>> environment in a hierarchical way. Thus completion should list all the
>>> names
>>> in all it's parent environments.
>>>
>>> For "normal" classes defining names.class would do the job, but
>>> completion
>>> for "environment" is  hard coded in utils:::specialCompletions by means
>>> of
>>> base::ls(). As result defining names.proto does not work.
>>>
>>> I tried to make "ls" generic and to do something like:
>>>
>>> environment(ls.default) <- asNamespace('utils')
>>> environment(ls) <- asNamespace('utils')
>>> environment(ls.proto) <- asNamespace('utils')
>>>
>>> That does not work either.
>>>
>>> Is there a way to make utils:::specialCompletions use my "ls" instead of
>>> "base::ls"??
>>>
>>> I know Deepayan Sarkar is working now on improving the completion system
>>> (potentially by introducing "completion" generic). That would definitely
>>> solve the problem. But for now, does a quick fix exist?
>>>
>>> Thanks a lot,
>>> Vitalie
>>>
>>> __
>>> 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.
>>>
>
>
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
>

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


Re: [R] transposing a distance matrix in R

2009-09-11 Thread Steve Lianoglou

Hi Jeannine,

I'm just forwarding this Q&A back to the r-help list, you'll get more  
eyes on it and other people might have better solutions.


Answers inline:

On Sep 11, 2009, at 12:25 PM, Jeannine Cavender-Bares wrote:


Dear Steve,

Greetings! You helped me earlier this summer with an R question in  
response to a message Brian McCarthy put out on the listserv. I was  
wondering if you happen to know the answer to the following question  
or if you can explain how I subscribe to the listserv. Can one just  
send a message to  r-h...@r-project.org?


You can subscribe to the listserv from here:

https://stat.ethz.ch/mailman/listinfo/r-help


Here goes:
How does one convert a triangular distance matrix into a single  
column distance matrix?: e.g.,


traingular:
   A   B   C
A na na na
B 1   na na
C 0   1   na

single column:
BA 1
CA 0
CB 1


Getting the distances from your matrix is pretty straightforward since  
they're all in the lower triangle of the matrix, see: ?lower.tri


R> m <- matrix(c(NA,1,0,NA,NA,1,NA,NA,NA), 3)
R> dimnames(m) <- list(c('A','B','C'), c('A','B','C'))
R> m[lower.tri(m)]
[1] 1 0 1

Getting the names for the distances is a bit more tricky. I'm trying  
to do that with the "expand.grid" function, check it out to see how it  
works: ?expand.grid


R> who.vs.who <- expand.grid(rownames(m), rownames(m))
R> who.vs.who
  Var1 Var2
1AA
2BA
3CA
4AB
5BB
6CB
7AC
8BC
9CC

We can use the same index generated by ``lower.tri(m)`` to get the  
names of the rows vs cols since R stores the elements of a matrix in  
column major order[1] (note that when I created the matrix ``m``, I  
used a vector that filled a matrix column by column). When you use a  
single integer to index into a matrix, it calculates which position to  
pull out in the same (column major) order, so:


  * ``m[1]`` is really element m[1,1]
  * ``m[2]`` is really element m[2,1], etc ...

So now:

R> who.vs.who[lower.tri(m),]
  Var1 Var2
2BA
3CA
6CB

... almost there, no just put it together:

R> dist <- m[lower.tri(m)]
R> who <- who.vs.who[lower.tri(m),]
R> names(dist) <- paste(who[,1], who[,2], sep=".vs.")
R> dist
B.vs.A C.vs.A C.vs.B
 1  0  1

HTH,
-steve

[1] Column major format: 
http://en.wikipedia.org/wiki/Row-major_order#Column-major_order

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


Re: [R] Completion for proto objects

2009-09-11 Thread Vitalie S.
On Fri, 11 Sep 2009 16:07:45 +0200, Gabor Grothendieck  
 wrote:



See ?assignInNamespace



thanks for the hint. It works to some extent. Functions are redefined in  
"base" but utils:::specialCompletions seems not to preform properly:


ls.proto <- function(x){  # function to complete
.local <- function(x){
if(is(x[[".super"]], "proto")) c(ls.default(x),  
Recall(x[[".super"]]))

else ls.default(x)
}
unlist(.local(x))
}

ls1 <- base::ls # cache ls

ls.default1 <- function(name, pos = -1, envir = as.environment(pos),  
all.names = FALSE, pattern){

UseMethod("ls")
}

assignInNamespace("ls.default", ls1 , 'base')
assignInNamespace("ls", ls.default1 , 'base')
assignInNamespace("ls.proto", ls.proto , 'base')

environment(ls) <- asNamespace('base')
environment(ls.default) <- asNamespace('base')
environment(ls.proto) <- asNamespace('base')

p1 <- proto(p1_abc=123)
p2 <- proto(.=p1, p2_abc=23423)

ls(p2)
[1] "p2_abc" "p1_abc"   #works fine 

ls(p1)

[1] "p1_abc"




Completion for $ works fine with environments and everything else, but not  
with proto objects.

also ls.str (which uses ls internally) gives an error.


ls.str(p1)
Error in ls(name, envir = envir, all.names = all.names, pattern = pattern)  
:

  argument "name" is missing, with no default




What is going on??  My ls.proto works nicely in global env but does not  
when called from attached packages?

Would really appreciate if someone can enlighten me.

Thanks a lot.

PS: I also tried to modify utils:::specialCompletions directly, did not  
wok either - it's something wrong with ls.proto above :(.


On Fri, Sep 11, 2009 at 10:02 AM, Vitalie S.   
wrote:


Hello everyone,

I am trying to implement completion for proto objects. Proto extends
environment in a hierarchical way. Thus completion should list all the  
names

in all it's parent environments.

For "normal" classes defining names.class would do the job, but  
completion
for "environment" is  hard coded in utils:::specialCompletions by means  
of

base::ls(). As result defining names.proto does not work.

I tried to make "ls" generic and to do something like:

environment(ls.default) <- asNamespace('utils')
environment(ls) <- asNamespace('utils')
environment(ls.proto) <- asNamespace('utils')

That does not work either.

Is there a way to make utils:::specialCompletions use my "ls" instead of
"base::ls"??

I know Deepayan Sarkar is working now on improving the completion system
(potentially by introducing "completion" generic). That would definitely
solve the problem. But for now, does a quick fix exist?

Thanks a lot,
Vitalie

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide  
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.




--

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


[R] Simple time series questions

2009-09-11 Thread gug

I'm sure this is a really simple problem, but I've spent hours digging and I
keep running into roadblocks.

I'm trying to get a simple chart with three time series.  Similar to the
attached example 
http://www.nabble.com/file/p25398419/Excel%2Bchart%2Bexample.pdf
Excel+chart+example.pdf , something that was quite easy to do in Excel,
except that I need a log y-axis: something that R can do and Excel can't.

The data is in the attached CSV file 
http://www.nabble.com/file/p25398419/test%2Bchart%2Bdata.csv
test+chart+data.csv .  I can read it in OK, and create separate charts:

testdata<- read.table("C:\\Files\\test chart data.csv", head = T, sep =
",",na.strings = "na")
test_date = as.Date(testdata$Date,"%d-%m-%y")
test_data_model = testdata$Model
test_date_baseA = testdata$BaseDataA
test_date_baseB = testdata$BaseDataB
plot(test_date, test_data_model,type='l',log="y")
plot(test_date, test_data_baseA,type='l',log="y")
plot(test_date, test_data_baseB,type='l',log="y")
grid()

(Clearly at this point, each chart over-writes the previous one.)

Next I try to get them onto a single chart, sharing the same y-axis.  I'm
sure I haven't done this very elegantly, but here goes:

frame_model = data.frame(a=test_date,b=test_data_model)
frame_A = data.frame(a=test_date,b=test_data_baseA)
frame_B = data.frame(a=test_date,b=test_data_baseB)
ts_model = ts(frame_model$b)
ts_a = ts(frame_A$b)
ts_b = ts(frame_B$b)
ts.plot(ts_model,ts_a,ts_b,col=c("blue","red","green"),log="y")

The problem is that I no longer have the date along the y-axis.  How can I
get that back?

Finally, when I plot the separate time series, the grid() function geneates
a grid where the vertical lines are not lined up with the year tick marks. 
I interpreted the topic help as saying that by default they would match the
tick marks.  How can I achieve that?

Thanks for any suggestions,

Guy Green
-- 
View this message in context: 
http://www.nabble.com/Simple-time-series-questions-tp25398419p25398419.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Is there any "month" object like "LETTERS" ?

2009-09-11 Thread Steve Murray

month.abb should do the trick

_
View your other email accounts from your Hotmail inbox. Add them now.

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


Re: [R] State Space models in R

2009-09-11 Thread Gabor Grothendieck
You might try:

RSiteSearch("state space")

and try the search engine at rseek.org

On Fri, Sep 11, 2009 at 11:04 AM, Giovanni Petris  wrote:
>
> Hello everybody,
>
> I am writing a review paper about State Space models in R, and I would
> like to cover as many packages as I reasonably can.
>
> So far I am familiar with the following tools to deal with SS models:
>
> * StructTS, Kalman* (in stats)
> * packages dse[1-2]
> * package sspir
> * package dlm
>
> I would like to have some input from users who work with SS models:
> are there any other packages for SS models that I am missing?, which
> package do you use and why?, what do you think are advantages/
> disadvantages of the package you use?
>
> Of course I do have my own preferences (biased, of course) and
> opinions about the different packages, but I would also like to
> summarize in my paper the feedback I get from the R community.
>
> Thank you in advance.
>
> Best,
> Giovanni Petris
>
> --
>
> Giovanni Petris  
> Associate Professor
> Department of Mathematical Sciences
> University of Arkansas - Fayetteville, AR 72701
> Ph: (479) 575-6324, 575-8630 (fax)
> http://definetti.uark.edu/~gpetris/
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


[R] Slow enumeration of vectors with restrictions

2009-09-11 Thread Bryan Keller
I have a vector T and a scalar m such that 1 <= m <= sum(T).  I also have a 
vector U that satisfies three properties...
 1. length(T)==length(U)
 2. sum(U)==m
 3. for (i in 1:length(T)) U[i]<=T[i]

The function "nextu" (given below) calculates the "next" vector subject to the 
same restrictions.  The recursion A(T,m) is given below.  It calculates the 
total number of different vectors there are for given T and m (in the example 
here it is 20). 

For example, if 

T <- c(2,4,3,1)
m <- 4

#first I generate the "first" value of U 
#to be plugged into function "nextu"

U.first <- numeric(c)
i<-1
while(sum(U.first) < m) {
if(T[i] > U.first[i]) {
U.first[i]<-(U.first[i]+1)
} else {
i<-(i+1)
}
}

#then I create a place to store the 
#vectors I will create with "nextu"

np <- A(T,m)
c <- length(T)
mat <- matrix(numeric(np*c),np,c)

#then I run nextu starting with U.first
#and store results in mat

i <- 1
U <- U.first
while (i <= np) {
for (j in 1:c) {
mat[i,j] <- U[j]
}
U <- nextu(U)
i <- i+1
}


In the example I gave above we get the following matrix...

  [,1] [,2] [,3] [,4]
 [1,]2200
 [2,]1300
 [3,]0400
 [4,]2110
 [5,]1210
 [6,]0310
 [7,]2020
 [8,]1120
 [9,]0220
[10,]1030
[11,]0130
[12,]2101
[13,]1201
[14,]0301
[15,]2011
[16,]1111
[17,]0211
[18,]1021
[19,]0121
[20,]0031

Although this works perfectly, it is way too slow to be useful in a program I 
am writing.  I’m wondering if anyone has any ideas about how to speed up the 
process.

If it helps, one can think of reversing the vectors and seeing them as numbers 
where addition is carried out in base T[i]+1 using carries from the (i-1) 
coordinate.

#function "nextu" creates the next
#sequential ordering of U that satisfies
#the restrictions given by T and m

nextu <- function(U) {
s <- -1
i <- 1

while (i <= c) {
if (U[i] == 0) {
i <- i+1
} else {
s <- s+U[i]
i <- i+1
break
}
}

while (i <=c) {
if (U[i] == T[i]) {
s <- s+U[i]
i <- i+1
} else {
k <<- i
U[k] <- (U[k] + 1)
i <- 1
break   
}
}

U[i] <- min(s,T[i])
s <- s-U[i]
i <- i+1

while (i < k) {
U[i] <- min(s,T[i])
s <- s-U[i]
i <- i+1
}
U
}
#end of function "nextu"

#function "A" implements a recursion to 
#get the total number of nextu calculations
#needed
#Thanks to Martin Morgan and Bill Dunlap for
#help speeding A(T,m) up more than 1000 times!

A <- function(T, m) {
C <- function(lt, m) {
if (lt == 1L) {
R <- as.numeric(0 <= m & m <= T[1])
} else if (lt == 2L) {
mu <- m - (0:T[2L])
R <- sum(mu <= T[1L] & 0L <= mu)
} else {
R <- 0
lt1 <- lt-1L
for (mu in m-(0:T[lt])) {
if (is.na(memo[lt1, offset + mu]))
memo[lt1, offset + mu] <<- C(lt1, mu)
R <- R + memo[lt1, offset + mu]
}
}
R
}
T <- rev(sort(T))
m <- as.integer(m)
offset <- sum(T[-1]) - m + 1L
nrow <- length(T) - 1L
memo <- matrix(rep(NA_real_, nrow * (offset + m)), nrow=nrow)
C(length(T), m)
}
#end of function A



-
Bryan Keller, Doctoral Student/Project Assistant
Educational Psychology - Quantitative Methods
The University of Wisconsin - Madison

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


Re: [R] Graph visualization

2009-09-11 Thread Martin Morgan
Arber Ngjela wrote:
> Hello,
> I am working with graph and adjacency matrix, the package 'graph' seems to be 
> appropriate for this. 
> An example in the package 
>> mat <- rbind(c(0, 0, 1, 1),
> +  c(0, 0, 1, 1),
> +  c(1, 1, 0, 1),
> +  c(1, 1, 1, 0))
>> rownames(mat) <- colnames(mat) <- letters[1:4]
>> graph1 <- new("graphAM", adjMat=mat)
>> graph1
> A graphAM graph with undirected edges
> Number of Nodes = 4 
> Number of Edges = 5 
> 
>  
> how can I plot the object graph1?

Hi Arber

Rgraphviz

 http://bioconductor.org/packages/2.4/bioc/html/Rgraphviz.html

is one option; it can be tricky to install on Windows / Mac where the
version of graphviz installed on your system needs to be the same as the
version used to build the package. See the README file in the package
source distribution

http://bioconductor.org/packages/2.4/bioc/src/contrib/Rgraphviz_1.22.1.tar.gz

Martin

> 
> Thanks in advance
> 
> Arber
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] : How wo read stability VAR plot?

2009-09-11 Thread Pfaff, Bernhard Dr.
>
>
>I have made program code for Vector Auto Regressive in terms
>of completing my undergraduate program using R. I have an important
>question related to my project.
>If I have:
>data(Canada)
>var.2c <- VAR(Canada, p = 2, type = "const")
>var.2c.stabil <- stability(var.2c, type = "OLS-CUSUM")
>I want to get the value of plot(var.2c.stabil). Can you 
>help me what should I do or write so the result can occur?

Dear Arif,

the stability function employs the package strucchange. Have a look at

str(var.2c.stabil$stability)

and then, for a particular equation (e.g. unemployment)

str(var.2c.stabil$stability$U)


the data for the process is contained in the list element "process".

HTH,
Bernhard

> 
>It means if I have source code:
>data(Canada)
>x=acf(Canada)
> 
>I will get the value of acf if I write x in R. Thanks in advance
>_
>
>
>ry-edit.aspx
>   [[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.
>
*
Confidentiality Note: The information contained in this ...{{dropped:10}}

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


[R] Rmetrics timeDate - business days between dates

2009-09-11 Thread Leonardo Miceli
Hi

One of the most important calculation in applied finance is the number of
days between dates.
That kind of calculus become annoying when a specific calendar must be used.
That is the case for the business days calculus.

The package timeDate has a function isBizday to perform that kind of thing.
The problem is that using this function to calculate the number of business
days between dates has taken a very long time. An example of such an
implementation is the function below.

Has anyone an optimized function to to this counts?

 Clearly I  have in mind to perform at least the basic analytics for a bond:
Duration, internal rate of return ,  net present value, etc... That is not
time feasible with a portfolio of bond  using the function below.

tks

library(timeDate)

BuziInDates <- function(start, end, holidays){
#calculates the number of business days
#between the dates start and end.

if(class(start) != "Date" | class(end) != "Date"){
  stop("Arguments must be of class Date.")
}

if(class(holidays) != "function"){
  stop("holidays must be a function")
}

if(start > end){
  stop("start date must not be greater than end date.")
}

y1 <- as.POSIXlt(start)$year + 1900
y2 <- as.POSIXlt(end)$year   + 1900

seqs  <- timeSequence(from = start, to = end, by = "day")

ndays <- length(seqs)

dts   <- NULL
temp  <- NULL
if( y1 == y2){
  temp  <- window(holidays(y1), start = start, end = end)
  dts   <- seqs[isBizday(seqs,temp)]
}else{
 temp <- holidays(y1)
 for(k in seq(from = y1+1, to = y2)){
temp <- c(temp,holidays(k))
 }
 temp   <- window(temp, start = start, end = end)
 dts<- seqs[isBizday(seqs,temp)]
}

bdays <- length(dts)

return(bdays)
}


### using the function...

BuziInDates(as.Date('2009-09-11'),  as.Date('2030-09-11') ,  holidayNYSE)

[[alternative HTML version deleted]]

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


Re: [R] State Space models in R

2009-09-11 Thread spencerg
Hi, Giovanni: 



 1.  I've used primarily "sspir" and "dlm".  There is apparently a 
new release of "sspir", which I have not used.  When I last tried 
"sspir", it did NOT have a forecast function, while "dlm" did.  The two 
packages have functions with the same name but incompatible code.  It 
would be good if the two were compatible, but unfortunately, I'm not in 
a position to volunteer to make them so. 



 2.  I'm very glad you are preparing such a review paper.  To check 
your lit search, you might try something like the following: 



library(sos)
ss <- ???"state space"
k <- ???"kalman"
sk <- ss|k
installPackages(sk)
writeFindFn2xls(sk)


 When I did this just now, it identified 272 help pages in 92 
packages matching either "state space" or "kalman".  In addition to the 
packages you mentioned, the following packages may also interest you:  
expsmooth, cts, KFAS, forecast, timsac, Stem, and deSolve;  these all 
have at least 6 help pages matching one of these terms.  The pomp 
package, with 5 matches, may also be of interest. 



 The "installPackages" command above only installed packages with 
at least 6 help pages in this example.  To extend this to 4, I used 
"installPackages(sk, 4)".  Then I deleted the "sk.xls" file in "getwd()" 
and reran "writeFindFn2xls(sk)" to get more information about packages 
with 5 and 4 matches. 


 To extend this search further, I added the following: 



dlm <- ???"dynamic linear model"
dlms <- ???"dynamic linear models"
dlsk <- sk|dlm|dlms
writeFindFn2xls(dlsk)


 This identified 320 help pages in 115 packages, but I don't know 
it added anything relevant to your question. 



 I created the "sos" package with help from Sundar Dorai-Raj and 
Romain Francois largely to help with this kind of search.  In seconds, 
it converted questions and insecurities about what relevant packages 
might be available into an embarrassment of riches.  An anonymous 
referee (or some other future reader) will be less likely to complain 
about something you've missed.  If it misses an important package, the 
package is either small or does not adequately match your search terms. 



 Hope this helps. 
 Spencer



Giovanni Petris wrote:

Hello everybody,

I am writing a review paper about State Space models in R, and I would
like to cover as many packages as I reasonably can. 


So far I am familiar with the following tools to deal with SS models:

* StructTS, Kalman* (in stats)
* packages dse[1-2] 
* package sspir

* package dlm

I would like to have some input from users who work with SS models:
are there any other packages for SS models that I am missing?, which
package do you use and why?, what do you think are advantages/
disadvantages of the package you use?

Of course I do have my own preferences (biased, of course) and
opinions about the different packages, but I would also like to
summarize in my paper the feedback I get from the R community.

Thank you in advance.

Best,
Giovanni Petris

  



--
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567

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


Re: [R] Simple time series questions

2009-09-11 Thread gug

Thanks - that works great.

Do you have any suggestions about the grid() problem - i.e. that the
vertical gridlines do not line up with the x-axis tickmarks (which are
years)?

I can't see on what basis the vertical gridlines are being positioned, but
it doesn't look good that they are not lined up with anything.

Thanks,

Guy


DKOD wrote:
> 
> This script worked for me. Be sure to put in your correct link.
> 
>   link <- "C:\\R_Home\\Charts & Graphs Blog\\R_Chart_Doc\\text_data.csv"
>   testdata<- read.table(link, head = T, sep = ",",na.strings = "na")
>   test_date = as.Date(testdata$Date,"%d-%m-%y") 
> 
>   plot(test_date, testdata$Model, type="l", log="y") 
>   points(test_date, testdata$BaseDataA, type = "l", col = "red")
>   points(test_date, testdata$BaseDataB, type = "l", col = "blue")
> 
> You add 2nd and 3rd series with points command
> 
> Hope this helps.
> 
> Kelly
> 
>  http://chartsgraphs.wordpress.com http://chartsgraphs.wordpress.com 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Simple-time-series-questions-tp25398419p25399928.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] R 2.9.2 memory max - object vector size

2009-09-11 Thread gug

At the risk of stating the obvious:

  - rm(.)  # clears specific objects out of memory as soon as they're no
longer needed in the routine.

  - sapply(ls(), function(x) object.size(get(x)))  #lists all objects with
the memory each is using.

  - rm(list=ls())  #clears out all objects, e.g. before the routine, to free
up memory.

Guy


S. Few wrote:
> 
> ##  PROBLEM:
> 
> I have memory limit problems. R and otherwise. My dataframes for
> merging or subsetting are about 300k to 900k records.
> I've had errors such as vector size too large. gc() was done.reset
> workspace, etc.
> 

-- 
View this message in context: 
http://www.nabble.com/R-2.9.2-memory-max---object-vector-size-tp25390745p25398830.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] format (?) problems with data imported from postgres

2009-09-11 Thread Tomas Lanczos
Being more specific:

On Fri, 2009-09-11 at 17:03 +0200, Tomas Lanczos wrote:
> Good day,
> 
> I read some data from a PostgreSQL database by a following script:
> 
> library(Rdbi)
> library(RdbiPgSQL)
> # conn becomes an object which contains the DB connection:
> conn <- dbConnect(PgSQL(), host="localhost", dbname="BVS",
> user="postgres", password = "***")
> 
> query_duj_kal <- dbSendQuery(conn, "select zdroj as well, cas as date,
> fe2, fe3, mn, nh4, no2, no3, o2, teplota as temperature from analystats
> where zdroj like 'Dunaj Kalinkovo'")
> watchem_duj_kal <- dbGetResult(query_duj_kal)
> 
> My intention with the data is to create a time series by a following
> script:
> 
> date <- (watchem_duj_kal$date)
> NO3 <- (watchem_duj_kal$no3)
> NH4 <- (watchem_duj_kal$nh4)
> maxy<-max(NO3,NH4)   
> miny<-min(NO3[NO3>0],NH4[NH4>0]) 
> date_p <- as.POSIXct(date, "CET")
> par(mfrow=c(2,1), ylog = TRUE, yaxp = c(0.01, 100, 3))
> plot(date_p, NO3,log = "y", type = "l", col = "darkred",
>  main = "NVZ-1", xlab = "time", ylab = "NO3-" )
> lines(date_p, NH4, col = "darkblue", lty = "dotted")
> plot(date_p, NH4, log = "y", type = "l", col = "darkblue", main =
> "NVZ-1",
> xlab = "time", ylab = "NH4+" )
> 
> The first problems comes with the definition maxy and miny (following a
> previous advice od Christian Poersching through this mailing list) what
> worked pretty well with data imported from a csv file by a read.table()
> function, but in this case I got NA output 
> 
> The next problem comes with the unambiguous format od the "date" field,
> which is in the database defined as -MM-DD, but in the resulting
> "watchem_duj_kal" dataset is strangely converted to DD-MM-, what is
> unambiguous for the as.POSIXct() function expecting -MM-DD. A
> function converting the format of the date should help, but I could not
> find untill now. 

the resulting "date" field is imported into the dataset as character:

> date
  [1] "03-04-1991" "07-04-1972" "10-03-1997" "02-12-1991" "04-11-1997"
  [6] "11-03-1996" "04-11-1975" "08-31-1992" "04-03-1991" "10-10-1994"
 [11] "05-10-1992" "03-28-1972" "11-30-1992" "03-20-1981" "08-26-1991"
 [16] "03-08-1992" "02-10-1991" "09-05-1995" "02-12-1975" "03-12-1990"
 [21] "06-04-1992" "01-14-1991" "09-12-1971" "06-11-1991" "02-06-1975"
 [26] "02-09-1981" "11-21-1980" "02-09-1991" "08-09-1997" "02-10-1990"
 [31] "09-09-1996" "11-19-1996" "06-08-1990" "08-11-1995" "01-25-1994"
 [36] "02-06-1992" "11-22-1994" "07-17-1995" "12-09-1994" "09-05-1994"
 [41] "03-09-1990" "04-22-1975" "03-13-1995" "11-08-1997" "01-07-1991"
 [46] "07-14-1997" "11-09-1995" "01-17-1995" "09-10-1974" "08-19-1995"
 [51] "02-14-1995" "05-27-1973" "06-21-1994" "07-15-1996" "09-23-1975"
 [56] "02-12-1997" "06-05-1991" "04-03-1992" "04-02-1975" "05-11-1990"
 [61] "12-21-1980" "05-10-1973" "08-29-1980" "03-06-1991" "03-02-1992"
 [66] "04-05-1992" "10-18-1995" "06-02-1991" "11-08-1975" "10-21-1996"
 [71] "09-17-1973" "06-01-1992" "06-07-1992" "12-04-1994" "12-08-1996"
 [76] "07-20-1981" "07-23-1973" "10-20-1980" "08-15-1994" "05-06-1995"
 [81] "06-17-1996" "02-06-1997" "06-10-1997" "03-31-1972" "04-14-1997"
 [86] "02-23-1981" "06-23-1975" "02-17-1994" "10-04-1995" "05-12-1995"
 [91] "05-15-1981" "10-16-1981" "09-04-1996" "03-12-1996" "10-02-1997"
 [96] "11-24-1981" "01-16-1996" "05-21-1996" "07-18-1994" "03-22-1994"
[101] "05-13-1997"


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

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


Re: [R] Is there any "month" object like "LETTERS" ?

2009-09-11 Thread William Dunlap
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Don MacQueen
> Sent: Friday, September 11, 2009 8:16 AM
> To: Gabor Grothendieck; megh
> Cc: r-help@r-project.org
> Subject: Re: [R] Is there any "month" object like "LETTERS" ?
> 
> On my R 2.9.2 installation, ?Constants just says "No documentation 
> ...". I don't know why Gabor and I would have different results.
> 
> However, ?LETTERS does provide the requested information.

In the upper left corner of the help for LETTERS is
Constants(base)
and usually that means that ?Constants would give
you the same help file.

All Rd files have one name entry and one or more alias
entries.  help() or ? looks in the list of alias entries, not
the name, but most help files include the name in the
aliases.  src/library/base/man/Constants.Rd does not
and probably should do that also.
 
> 
> -Don
> 
> At 7:30 AM -0400 9/11/09, Gabor Grothendieck wrote:
> >See ?Constants
> >
> >On Fri, Sep 11, 2009 at 3:13 AM, megh  wrote:
> >>
> >>  There is an object "LETTERS" which displays all letters 
> from "a" to "z". Is
> >>  there any similar object whicg displays the "months" as well in
> >>  chronological order? like "jan", "feb",...,"dec"
> >>
> >>  Thanks,
> >>  --
> >>  View this message in context: 
> >>http://*www.*nabble.com/Is-there-any-%22month%22-object-like
> -%22LETTERS%22---tp25396125p25396125.html
> >>  Sent from the R help mailing list archive at Nabble.com.
> >>
> >>  __
> >>  R-help@r-project.org mailing list
> >>  https://*stat.ethz.ch/mailman/listinfo/r-help
> >>  PLEASE do read the posting guide 
> >>http://*www.*R-project.org/posting-guide.html
> >>  and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >__
> >R-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.
> 
> 
> -- 
> --
> Don MacQueen
> Environmental Protection Department
> Lawrence Livermore National Laboratory
> Livermore, CA, USA
> 925-423-1062
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

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


Re: [R] RPostgreSQL package and libpq.dll file

2009-09-11 Thread Joe Conway
Lore M wrote:
> Dear all, I'd like to use the package RPostgreSQL. I'm using R
> version 2.8.1 and I've download the last version RPostgreSQL. When I
> load the package, I get something like "the file LIBPQ.DLL is
> missing". Do you have any idea about what I'm suppose to do ? Thanks
> everyone.

libpq.dll is the PostgreSQL client library. You should be able to get it
here: http://www.postgresql.org/download/windows

HTH

Joe



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


Re: [R] Is there any "month" object like "LETTERS" ?

2009-09-11 Thread Don MacQueen
On my R 2.9.2 installation, ?Constants just says "No documentation 
...". I don't know why Gabor and I would have different results.


However, ?LETTERS does provide the requested information.

-Don

At 7:30 AM -0400 9/11/09, Gabor Grothendieck wrote:

See ?Constants

On Fri, Sep 11, 2009 at 3:13 AM, megh  wrote:


 There is an object "LETTERS" which displays all letters from "a" to "z". Is
 there any similar object whicg displays the "months" as well in
 chronological order? like "jan", "feb",...,"dec"

 Thanks,
 --
 View this message in context: 
http://*www.*nabble.com/Is-there-any-%22month%22-object-like-%22LETTERS%22---tp25396125p25396125.html

 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://*stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://*www.*R-project.org/posting-guide.html

 and provide commented, minimal, self-contained, reproducible code.



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



--
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

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


[R] State Space models in R

2009-09-11 Thread Giovanni Petris

Hello everybody,

I am writing a review paper about State Space models in R, and I would
like to cover as many packages as I reasonably can. 

So far I am familiar with the following tools to deal with SS models:

* StructTS, Kalman* (in stats)
* packages dse[1-2] 
* package sspir
* package dlm

I would like to have some input from users who work with SS models:
are there any other packages for SS models that I am missing?, which
package do you use and why?, what do you think are advantages/
disadvantages of the package you use?

Of course I do have my own preferences (biased, of course) and
opinions about the different packages, but I would also like to
summarize in my paper the feedback I get from the R community.

Thank you in advance.

Best,
Giovanni Petris

-- 

Giovanni Petris  
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/

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


Re: [R] Best R text editors?

2009-09-11 Thread Ramon Diaz-Uriarte
Ted, I think I share your feelings about mice (e.g., that is why I use
window managers where the mouse is not needed or is actually
discouraged) but ...

On Fri, Sep 11, 2009 at 4:46 PM, Ted Harding
 wrote:
> On 11-Sep-09 14:16:44, Clint Bowman wrote:
>> On Fri, 11 Sep 2009, Duncan Murdoch wrote:
>>
>>> On 11/09/2009 6:53 AM, (Ted Harding) wrote:
  On 11-Sep-09 10:41:21, Jim Lemon wrote:
 >  On 09/11/2009 05:15 PM, Patrick Connolly wrote:
 > >  ...
 > > | >   and in previous versions, you could always do M-x cua-mode
 > > | >   for
 > > | >   the same effect. Talk about a well-hidden function mostly
 > > | >   directed
 > > | >   at beginners ...
 > >
 > >  Perhaps the thinking was that by the time they find it, they'll
 > >  already have noticed that they can cut/copy and paste using only
 > >  the
 > >  mouse buttons and won't be bothered with such inefficient
 > >  methods.
 > >
 > >  Though this be madness, yet there is a method in't. :-)
 > >
 >  Well, okay, let's look at it from the viewpoint of learning
 >  theory. We
 >  expect that if someone has learned a skill, they will prefer to
 >  engage
 >  in other behaviors where they can successfully use that skill.
 >  Upon
 >  this easily understood foundation rest the fortunes of many. Thus
 >  two of
 >  those entities, let us call them A and M for the purposes of
 >  discussion, spend a great deal of time and effort attempting to
 >  differentiate their
 >  interfaces from each other so that having trained their users,
 >  those
 >  users will be reluctant to switch to the competitor. However, they
 >  must
 >  remain similar enough so that the switch from the competitor is
 >  not
 >  impossible. Such is the dispiriting triumph of form over substance
 >  in
 >  interface design. Both have yet to abandon such atavists as myself
 >  who
 >  prefer to type rather than fiddle with a pointing device, though
 >  they
 >  try hard to convert us. A somewhat smaller organization that I
 >  will
 >  label G seems to have decided that it can build a user base by
 >  sticking
 >  to the arcane typoglyphics of the VT-100 era and enticing the
 >  largely
 >  amoral digirati with moral suasion. Now that's madness.
 >
 >  Jim

  Once again, I cannot resist citing the immortal quote (from Charles
  Curran, of the UK Unix Users Group):

    "I can touch-type, but I can't touch-mouse"
>>>
>>> That's a strange disability.  It took me several months to learn to
>>> touch-type (and years later I'm still not very good at the top-row
>>> numbers or
>>> the special symbols on them), but I memorized the location of the two
>>> buttons
>>> on my mouse in no time at all.
>>>
>>> Duncan Murdoch
>>
>> Ahh, just Ted's point--mice have three buttons (unless they are
>> connected to Apples).
>>
>> Clint
>
> Well, not really!! My point (and certainly Charles Curran's point)
> is that in touch-typing you know by proprioception and neuromuscular
> coordination where your fingers are relative to the keys on the
> keyboard, and what key you will press next, without looking; and
> you can accurately press several keys in rapid succession -- just
> as a pianist can play an arpeggio without looking.
>
> But "touch-mousing" isn't just knowing where the mouse itself is,
> nor the buttons. It would involve knowing from the sensations of
> moving the mouse where the mouse-pointer was on the screen, without
> looking, and also what graphic element (icon, on-screen button,
> tab in a drop-down menu) the mouse was over, also without looking.
>
> You can type accurately and rapidly withnout looking at the keyboard.
> You can't use a mouse with closely and accurately observing where
> the mouse-pointer is in the GUI. You can touch type. You can't

It is here that I disagree: if the idea is "typing without looking at
the keyboard", then the correct analogy seems to me to be "moving the
mouse around without looking at the mouse". And the later is certainly
doable.

(OK, you can type without looking at the keyboard AND without looking
at your monitor, such as when copying or translating, and that is not
feasible with mice).


> touch-mouse. (Unless you have one of those "accessibility" add-ons
> for the visually impaired, where a "SatNav" voice tells you what
> the mouse is over, and what is written in the tab from the drop-down
> menu).
>
> Also, the ocasionnal misstake in typing is usually fairly harmless.
> Mistakes in mousing can be catastrophic. However, when one is typing

Hummm... I am not sure that is a fair comparison either: certain mouse
actions can be bound to some catastrophic actions. But I could have a
command called "er" (e.g., ERase absolutely everything), which does
something equally catastrophic and accidentally type that instead of
"df".

The problem there is not in th

[R] format (?) problems with data imported from postgres

2009-09-11 Thread Tomas Lanczos
Good day,

I read some data from a PostgreSQL database by a following script:

library(Rdbi)
library(RdbiPgSQL)
# conn becomes an object which contains the DB connection:
conn <- dbConnect(PgSQL(), host="localhost", dbname="BVS",
user="postgres", password = "***")

query_duj_kal <- dbSendQuery(conn, "select zdroj as well, cas as date,
fe2, fe3, mn, nh4, no2, no3, o2, teplota as temperature from analystats
where zdroj like 'Dunaj Kalinkovo'")
watchem_duj_kal <- dbGetResult(query_duj_kal)

My intention with the data is to create a time series by a following
script:

date <- (watchem_duj_kal$date)
NO3 <- (watchem_duj_kal$no3)
NH4 <- (watchem_duj_kal$nh4)
maxy<-max(NO3,NH4)   
miny<-min(NO3[NO3>0],NH4[NH4>0]) 
date_p <- as.POSIXct(date, "CET")
par(mfrow=c(2,1), ylog = TRUE, yaxp = c(0.01, 100, 3))
plot(date_p, NO3,log = "y", type = "l", col = "darkred",
 main = "NVZ-1", xlab = "time", ylab = "NO3-" )
lines(date_p, NH4, col = "darkblue", lty = "dotted")
plot(date_p, NH4, log = "y", type = "l", col = "darkblue", main =
"NVZ-1",
xlab = "time", ylab = "NH4+" )

The first problems comes with the definition maxy and miny (following a
previous advice od Christian Poersching through this mailing list) what
worked pretty well with data imported from a csv file by a read.table()
function, but in this case I got NA output 

The next problem comes with the unambiguous format od the "date" field,
which is in the database defined as -MM-DD, but in the resulting
"watchem_duj_kal" dataset is strangely converted to DD-MM-, what is
unambiguous for the as.POSIXct() function expecting -MM-DD. A
function converting the format of the date should help, but I could not
find untill now. 

I appreciate every advice/suggestion/help.

Best regards

Tomas

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


Re: [R] Best R text editors?

2009-09-11 Thread Ted Harding
On 11-Sep-09 14:16:44, Clint Bowman wrote:
> On Fri, 11 Sep 2009, Duncan Murdoch wrote:
> 
>> On 11/09/2009 6:53 AM, (Ted Harding) wrote:
>>>  On 11-Sep-09 10:41:21, Jim Lemon wrote:
>>> >  On 09/11/2009 05:15 PM, Patrick Connolly wrote:
>>> > >  ...
>>> > > | >   and in previous versions, you could always do M-x cua-mode
>>> > > | >   for
>>> > > | >   the same effect. Talk about a well-hidden function mostly 
>>> > > | >   directed
>>> > > | >   at beginners ...
>>> > > 
>>> > >  Perhaps the thinking was that by the time they find it, they'll
>>> > >  already have noticed that they can cut/copy and paste using only
>>> > >  the
>>> > >  mouse buttons and won't be bothered with such inefficient
>>> > >  methods.
>>> > > 
>>> > >  Though this be madness, yet there is a method in't. :-)
>>> > > 
>>> >  Well, okay, let's look at it from the viewpoint of learning
>>> >  theory. We 
>>> >  expect that if someone has learned a skill, they will prefer to
>>> >  engage 
>>> >  in other behaviors where they can successfully use that skill.
>>> >  Upon
>>> >  this easily understood foundation rest the fortunes of many. Thus
>>> >  two of 
>>> >  those entities, let us call them A and M for the purposes of
>>> >  discussion, spend a great deal of time and effort attempting to 
>>> >  differentiate their
>>> >  interfaces from each other so that having trained their users,
>>> >  those 
>>> >  users will be reluctant to switch to the competitor. However, they
>>> >  must
>>> >  remain similar enough so that the switch from the competitor is
>>> >  not 
>>> >  impossible. Such is the dispiriting triumph of form over substance
>>> >  in 
>>> >  interface design. Both have yet to abandon such atavists as myself
>>> >  who 
>>> >  prefer to type rather than fiddle with a pointing device, though
>>> >  they 
>>> >  try hard to convert us. A somewhat smaller organization that I
>>> >  will 
>>> >  label G seems to have decided that it can build a user base by
>>> >  sticking
>>> >  to the arcane typoglyphics of the VT-100 era and enticing the
>>> >  largely 
>>> >  amoral digirati with moral suasion. Now that's madness.
>>> > 
>>> >  Jim
>>>
>>>  Once again, I cannot resist citing the immortal quote (from Charles
>>>  Curran, of the UK Unix Users Group):
>>>
>>>"I can touch-type, but I can't touch-mouse"
>>
>> That's a strange disability.  It took me several months to learn to 
>> touch-type (and years later I'm still not very good at the top-row
>> numbers or 
>> the special symbols on them), but I memorized the location of the two
>> buttons 
>> on my mouse in no time at all.
>>
>> Duncan Murdoch
> 
> Ahh, just Ted's point--mice have three buttons (unless they are 
> connected to Apples).
> 
> Clint

Well, not really!! My point (and certainly Charles Curran's point)
is that in touch-typing you know by proprioception and neuromuscular
coordination where your fingers are relative to the keys on the
keyboard, and what key you will press next, without looking; and
you can accurately press several keys in rapid succession -- just
as a pianist can play an arpeggio without looking.

But "touch-mousing" isn't just knowing where the mouse itself is,
nor the buttons. It would involve knowing from the sensations of
moving the mouse where the mouse-pointer was on the screen, without
looking, and also what graphic element (icon, on-screen button,
tab in a drop-down menu) the mouse was over, also without looking.

You can type accurately and rapidly withnout looking at the keyboard.
You can't use a mouse with closely and accurately observing where
the mouse-pointer is in the GUI. You can touch type. You can't
touch-mouse. (Unless you have one of those "accessibility" add-ons
for the visually impaired, where a "SatNav" voice tells you what
the mouse is over, and what is written in the tab from the drop-down
menu).

Also, the ocasionnal misstake in typing is usually fairly harmless.
Mistakes in mousing can be catastrophic. However, when one is typing
program code then of course one needs to scrutinise it carefully.
Even then, a typo usually results in an error message, rarely in
a disaster. A "mouso", however, will (almost by definition) result
in the execution of a correctly coded procedure. Tough luck if it's
the wrong one.

Ted.

>>>  Originally posted on Wed Nov 17 13:48:14 2004, in the context of an
>>>  extended discussion (still relevant to the present thread):
>>>
>>>http://finzi.psych.upenn.edu/R/Rhelp02/archive/41560.html
>>>
>>>  Best wishes to all,
>>>  Ted.
>>>
>>>  
>>>  E-Mail: (Ted Harding) 
>>>  Fax-to-email: +44 (0)870 094 0861
>>>  Date: 11-Sep-09   Time: 11:53:09
>>>  -- XFMail --
>>>
>>>  __
>>>  R-help@r-project.org mailing list
>>>  https://stat.ethz.ch/mailman/listinfo/r-help
>>>  PLEASE do read the posti

[R] Reading gzip data from a non zero file offset

2009-09-11 Thread Gregory Jefferis
Dear R users, 

I have a file that contains a text header followed by a gzipped data chunk.

I thought I would be able to read this by doing something like this.

con<-file('myfile','rb')
header<-readLines(con,10)
gzf<-gzcon(con)
data<-readBin(gzf,"int",n=1e7)

But what I find is that gzcon resets the original connection back to the
beginning of the file rather than reading from its current location.

Would anyone have any suggestions for how to handle this in R?  Right now I
am using system to call "tail" to copy the gzipped data into a temporary
file, but that isn't portable.

Many thanks for your help,

Greg.
 
-- 
Gregory Jefferis, PhD
Division of Neurobiology
MRC Laboratory of Molecular Biology,
Hills Road,
Cambridge, CB2 0QH, UK.

http://www2.mrc-lmb.cam.ac.uk/NB/jefferis_g
http://www.neuroscience.cam.ac.uk/directory/profile.php?gsxej2
http://flybrain.stanford.edu

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


[R] RPostgreSQL package and libpq.dll file

2009-09-11 Thread Lore M

Dear all,
I'd like to use the package RPostgreSQL. I'm using R version 2.8.1 and I've 
download the last version RPostgreSQL. When I load the package, I get something 
like "the file LIBPQ.DLL is missing".
Do you have any idea about what I'm suppose to do ? Thanks everyone.

_
[[elided Hotmail spam]]

[[alternative HTML version deleted]]

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


Re: [R] Mantel test least square line

2009-09-11 Thread swertie


Thank you it is what I was looking for.
-- 
View this message in context: 
http://www.nabble.com/Mantel-test-least-square-line-tp25235402p25401329.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Mapping factors to a new set of factors

2009-09-11 Thread james.arnold
Thanks Jorge,

That is what I was looking for.

Cheers,
James

From: Jorge Ivan Velez [mailto:jorgeivanve...@gmail.com] 
Sent: 08 September 2009 18:41
To: Arnold, James
Cc: r-help@r-project.org
Subject: Re: [R] Mapping factors to a new set of factors

Hi James,

Take a look at the "recode" function in the "car" package. It might be useful 
in this case.

HTH,
Jorge

On Tue, Sep 8, 2009 at 12:01 PM,  wrote:
Hello,

I am trying to map a factor variable within a data frame to a new variable 
whose entries are derived from the content of the original variable and there 
are fewer factors in the new variable. That is, I'm trying to set up a 
surjection.

After first thinking that this would be a common operation and would have a 
quite simple interface, I can not seem to find one, nor any similar posts on 
this topic (please correct me if there is something).

Therefore, I have written a function to perform this mapping. However, the 
function I have written doesn't seem to work with vectors greater than length 
1, and as such is useless. Is there any way to ensure the function would work 
appropriately for each element of the vector input?

mapLN <- function(x)
{
       Reg <- levels(df$Var1)
       if (x==Reg[1] | x==Reg[2] | x==Reg[13] | x==Reg[17] | x==Reg[20] | 
x==Reg[23] | x==Reg[27]) {"North"} else
       if (x==Reg[3] | x==Reg[5] | x==Reg[7] | x==Reg[14] | x==Reg[15] | 
x==Reg[24] | x==Reg[30]) {"East"} else
       if (x==Reg[4] | x==Reg[6] | x==Reg[8] | x==Reg[9] | x==Reg[11] | 
x==Reg[16] | x==Reg[18] | x==Reg[21] | x==Reg[22] | x==Reg[25] | x==Reg[28] | 
x==Reg[29] | x==Reg[31]) {"West"} else
       if (x==Reg[10] | x==Reg[12] | x==Reg[19] | x==Reg[26] | x==Reg[32]) 
{"South"} else
       stop("Not in original set")
}

Many thanks,
James

This E-Mail is confidential and intended solely for the use of the individual 
to whom it is addressed.  If you are not the addressee, any disclosure, 
reproduction, copying, distribution or other dissemination or use of this 
communication is strictly prohibited.  If you have received this transmission 
in error please notify the sender immediately by replying to this e-mail, or 
telephone 01382 207 222, and then delete this e-mail.

All outgoing messages are checked for viruses however no guarantee is given 
that this e-mail message, and any attachments, are free from viruses.  You are 
strongly recommend to check for viruses using your own virus scanner.  Neither 
SCRC or SSSC will accept responsibility for any damage caused as a result of 
virus infection.


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


This E-Mail is confidential and intended solely for the use of the individual 
to whom it is addressed.  If you are not the addressee, any disclosure, 
reproduction, copying, distribution or other dissemination or use of this 
communication is strictly prohibited.  If you have received this transmission 
in error please notify the sender immediately by replying to this e-mail, or 
telephone 01382 207 222, and then delete this e-mail.

All outgoing messages are checked for viruses however no guarantee is given 
that this e-mail message, and any attachments, are free from viruses.  You are 
strongly recommend to check for viruses using your own virus scanner.  Neither 
SCRC or SSSC will accept responsibility for any damage caused as a result of 
virus infection.

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


Re: [R] Mapping factors to a new set of factors

2009-09-11 Thread james.arnold
Thanks a lot Phil,

Recode is exactly what I was looking for. I managed to get my old function 
working using sapply, but the performance was horrendously slow!

One other thing was that the lvls vector can only seem to be set within the 
global scope of R, and local variables within a function do not seem to be able 
to be seen within the scope of a function that sets that variable and calls 
recode.

Thanks,
James

-Original Message-
From: Phil Spector [mailto:spec...@stat.berkeley.edu] 
Sent: 08 September 2009 22:25
To: Arnold, James
Subject: Re: [R] Mapping factors to a new set of factors

James -
If you need to do something like this, I strongly recommend
the recode function of the car package.  You can use it like this:

library(car)
recode(x,'lvls[c(1,2,13,17,20,23,27)]="North";
   lvls[c(3,5,7,14,15,24,30)] ="East";
   lvls[c(4,6,8,9,11,16,18,21,22,25,28,29,31)]="West";
   lvls[c(10,12,19,26,32)]="South";
   else="Not In Original Set"')

Including the as.factor=FALSE argument to recode will return 
a character vector -- by default it returns a factor.

 - Phil Spector
  Statistical Computing Facility
  Department of Statistics
  UC Berkeley
  spec...@stat.berkeley.edu



On Tue, 8 Sep 2009, james.arn...@sssc.uk.com wrote:

> Hello,
>
> I am trying to map a factor variable within a data frame to a new variable 
> whose entries are derived from the content of the original variable and there 
> are fewer factors in the new variable. That is, I'm trying to set up a 
> surjection.
>
> After first thinking that this would be a common operation and would have a 
> quite simple interface, I can not seem to find one, nor any similar posts on 
> this topic (please correct me if there is something).
>
> Therefore, I have written a function to perform this mapping. However, the 
> function I have written doesn't seem to work with vectors greater than length 
> 1, and as such is useless. Is there any way to ensure the function would work 
> appropriately for each element of the vector input?
>
> mapLN <- function(x)
> {
>   Reg <- levels(df$Var1)
>   if (x==Reg[1] | x==Reg[2] | x==Reg[13] | x==Reg[17] | x==Reg[20] | 
> x==Reg[23] | x==Reg[27]) {"North"} else
>   if (x==Reg[3] | x==Reg[5] | x==Reg[7] | x==Reg[14] | x==Reg[15] | 
> x==Reg[24] | x==Reg[30]) {"East"} else
>   if (x==Reg[4] | x==Reg[6] | x==Reg[8] | x==Reg[9] | x==Reg[11] | 
> x==Reg[16] | x==Reg[18] | x==Reg[21] | x==Reg[22] | x==Reg[25] | x==Reg[28] | 
> x==Reg[29] | x==Reg[31]) {"West"} else
>   if (x==Reg[10] | x==Reg[12] | x==Reg[19] | x==Reg[26] | x==Reg[32]) 
> {"South"} else
>   stop("Not in original set")
> }
>
> Many thanks,
> James
>
> This E-Mail is confidential and intended solely for the use of the individual 
> to whom it is addressed.? If you are not the addressee, any disclosure, 
> reproduction, copying, distribution or other dissemination or use of this 
> communication is strictly prohibited.? If you have received this transmission 
> in error please notify the sender immediately by replying to this e-mail, or 
> telephone 01382 207 222, and then delete this e-mail.
>
> All outgoing messages are checked for viruses however no guarantee is given 
> that this e-mail message, and any attachments, are free from viruses.  You 
> are strongly recommend to check for viruses using your own virus scanner.  
> Neither SCRC or SSSC will accept responsibility for any damage caused as a 
> result of virus infection.
>
>

This E-Mail is confidential and intended solely for the use of the individual 
to whom it is addressed.  If you are not the addressee, any disclosure, 
reproduction, copying, distribution or other dissemination or use of this 
communication is strictly prohibited.  If you have received this transmission 
in error please notify the sender immediately by replying to this e-mail, or 
telephone 01382 207 222, and then delete this e-mail.

All outgoing messages are checked for viruses however no guarantee is given 
that this e-mail message, and any attachments, are free from viruses.  You are 
strongly recommend to check for viruses using your own virus scanner.  Neither 
SCRC or SSSC will accept responsibility for any damage caused as a result of 
virus infection.

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


Re: [R] Mapping factors to a new set of factors

2009-09-11 Thread james.arnold
Thanks Jim,

I managed to get my function to work by putting it within an sapply. 
Unfortunately the performance was terrible, so I've gone with the suggestion of 
other posters to use recode in the car package.

Cheers,
James

-Original Message-
From: jim holtman [mailto:jholt...@gmail.com] 
Sent: 08 September 2009 18:37
To: Arnold, James
Cc: r-help@r-project.org
Subject: Re: [R] Mapping factors to a new set of factors

use 'ifelse'

# not tested; you supply data for the '%in%'
map <- function(x){
ifelse(x %in% c('a','b'), "North",
ifelse(x %in% c('c','d'), "South",
ifelse(x %in% c('e', 'f'), "East",
ifelse(x %in% c('g', 'h'), "West", NA
}

On Tue, Sep 8, 2009 at 12:01 PM,  wrote:
> Hello,
>
> I am trying to map a factor variable within a data frame to a new variable 
> whose entries are derived from the content of the original variable and there 
> are fewer factors in the new variable. That is, I'm trying to set up a 
> surjection.
>
> After first thinking that this would be a common operation and would have a 
> quite simple interface, I can not seem to find one, nor any similar posts on 
> this topic (please correct me if there is something).
>
> Therefore, I have written a function to perform this mapping. However, the 
> function I have written doesn't seem to work with vectors greater than length 
> 1, and as such is useless. Is there any way to ensure the function would work 
> appropriately for each element of the vector input?
>
> mapLN <- function(x)
> {
>        Reg <- levels(df$Var1)
>        if (x==Reg[1] | x==Reg[2] | x==Reg[13] | x==Reg[17] | x==Reg[20] | 
> x==Reg[23] | x==Reg[27]) {"North"} else
>        if (x==Reg[3] | x==Reg[5] | x==Reg[7] | x==Reg[14] | x==Reg[15] | 
> x==Reg[24] | x==Reg[30]) {"East"} else
>        if (x==Reg[4] | x==Reg[6] | x==Reg[8] | x==Reg[9] | x==Reg[11] | 
> x==Reg[16] | x==Reg[18] | x==Reg[21] | x==Reg[22] | x==Reg[25] | x==Reg[28] | 
> x==Reg[29] | x==Reg[31]) {"West"} else
>        if (x==Reg[10] | x==Reg[12] | x==Reg[19] | x==Reg[26] | x==Reg[32]) 
> {"South"} else
>        stop("Not in original set")
> }
>
> Many thanks,
> James
>
> This E-Mail is confidential and intended solely for the use of the individual 
> to whom it is addressed.  If you are not the addressee, any disclosure, 
> reproduction, copying, distribution or other dissemination or use of this 
> communication is strictly prohibited.  If you have received this transmission 
> in error please notify the sender immediately by replying to this e-mail, or 
> telephone 01382 207 222, and then delete this e-mail.
>
> All outgoing messages are checked for viruses however no guarantee is given 
> that this e-mail message, and any attachments, are free from viruses.  You 
> are strongly recommend to check for viruses using your own virus scanner.  
> Neither SCRC or SSSC will accept responsibility for any damage caused as a 
> result of virus infection.
>
>
> __
> 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.
>
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

This E-Mail is confidential and intended solely for the use of the individual 
to whom it is addressed.  If you are not the addressee, any disclosure, 
reproduction, copying, distribution or other dissemination or use of this 
communication is strictly prohibited.  If you have received this transmission 
in error please notify the sender immediately by replying to this e-mail, or 
telephone 01382 207 222, and then delete this e-mail.

All outgoing messages are checked for viruses however no guarantee is given 
that this e-mail message, and any attachments, are free from viruses.  You are 
strongly recommend to check for viruses using your own virus scanner.  Neither 
SCRC or SSSC will accept responsibility for any damage caused as a result of 
virus infection.

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


[R] voice recognition software

2009-09-11 Thread volinsky

Hello all.

Has anyone out there had experience using R with voice recognition 
software?  I got this query from a student with nerve damage in her hand 
who wants to program in R. 


Thanks,  Chris

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


Re: [R] Best R text editors?

2009-09-11 Thread Clint Bowman

On Fri, 11 Sep 2009, Duncan Murdoch wrote:


On 11/09/2009 6:53 AM, (Ted Harding) wrote:

 On 11-Sep-09 10:41:21, Jim Lemon wrote:
>  On 09/11/2009 05:15 PM, Patrick Connolly wrote:
> >  ...
> > | >   and in previous versions, you could always do M-x cua-mode for
> > | >   the same effect. Talk about a well-hidden function mostly 
> > | >   directed

> > | >   at beginners ...
> > 
> >  Perhaps the thinking was that by the time they find it, they'll

> >  already have noticed that they can cut/copy and paste using only the
> >  mouse buttons and won't be bothered with such inefficient methods.
> > 
> >  Though this be madness, yet there is a method in't. :-)
> > 
>  Well, okay, let's look at it from the viewpoint of learning theory. We 
>  expect that if someone has learned a skill, they will prefer to engage 
>  in other behaviors where they can successfully use that skill. Upon
>  this easily understood foundation rest the fortunes of many. Thus two of 
>  those entities, let us call them A and M for the purposes of
>  discussion, spend a great deal of time and effort attempting to 
>  differentiate their
>  interfaces from each other so that having trained their users, those 
>  users will be reluctant to switch to the competitor. However, they must
>  remain similar enough so that the switch from the competitor is not 
>  impossible. Such is the dispiriting triumph of form over substance in 
>  interface design. Both have yet to abandon such atavists as myself who 
>  prefer to type rather than fiddle with a pointing device, though they 
>  try hard to convert us. A somewhat smaller organization that I will 
>  label G seems to have decided that it can build a user base by sticking
>  to the arcane typoglyphics of the VT-100 era and enticing the largely 
>  amoral digirati with moral suasion. Now that's madness.
> 
>  Jim


 Once again, I cannot resist citing the immortal quote (from Charles
 Curran, of the UK Unix Users Group):

   "I can touch-type, but I can't touch-mouse"


That's a strange disability.  It took me several months to learn to 
touch-type (and years later I'm still not very good at the top-row numbers or 
the special symbols on them), but I memorized the location of the two buttons 
on my mouse in no time at all.


Duncan Murdoch


Ahh, just Ted's point--mice have three buttons (unless they are 
connected to Apples).


Clint





 Originally posted on Wed Nov 17 13:48:14 2004, in the context of an
 extended discussion (still relevant to the present thread):

   http://finzi.psych.upenn.edu/R/Rhelp02/archive/41560.html

 Best wishes to all,
 Ted.

 
 E-Mail: (Ted Harding) 
 Fax-to-email: +44 (0)870 094 0861
 Date: 11-Sep-09   Time: 11:53:09
 -- XFMail --

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


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



--
Clint BowmanINTERNET:   cl...@ecy.wa.gov
Air Quality Modeler INTERNET:   cl...@math.utah.edu
Department of Ecology   VOICE:  (360) 407-6815
PO Box 47600FAX:(360) 407-7534
Olympia, WA 98504-7600

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


Re: [R] Graph visualization

2009-09-11 Thread Steve Lianoglou

Hi,

On Sep 11, 2009, at 8:22 AM, Arber Ngjela wrote:


Hello,
I am working with graph and adjacency matrix, the package 'graph'  
seems to be appropriate for this.

An example in the package

mat <- rbind(c(0, 0, 1, 1),

+  c(0, 0, 1, 1),
+  c(1, 1, 0, 1),
+  c(1, 1, 1, 0))

rownames(mat) <- colnames(mat) <- letters[1:4]
graph1 <- new("graphAM", adjMat=mat)
graph1

A graphAM graph with undirected edges
Number of Nodes = 4
Number of Edges = 5


how can I plot the object graph1?


I haven't used the graph library, but I do use the igraph library a  
bit and it's quite good (highly recommended). There is a tkplot  
function implemented which not only plots your graph, but allows you  
to pull/push nodes around on the screen, select, etc (you'll need the  
tcl/tk stuff installed).


Like so:
library(igraph)
mat <- rbind(c(0, 0, 1, 1),
  c(0, 0, 1, 1),
  c(1, 1, 0, 1),
  c(1, 1, 1, 0))
dimnames(mat) <- list(LETTERS[1:4], LETTERS[1:4])
graph <- graph.adjacency(mat)
tkplot(graph)

(you can specify different layouts, too).

HTH,
-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


Re: [R] Modify functions in base packages (needed for completion for proto objects)

2009-09-11 Thread Gabor Grothendieck
See ?assignInNamespace

On Fri, Sep 11, 2009 at 10:02 AM, Vitalie S.  wrote:
>
> Hello everyone,
>
> I am trying to implement completion for proto objects. Proto extends
> environment in a hierarchical way. Thus completion should list all the names
> in all it's parent environments.
>
> For "normal" classes defining names.class would do the job, but completion
> for "environment" is  hard coded in utils:::specialCompletions by means of
> base::ls(). As result defining names.proto does not work.
>
> I tried to make "ls" generic and to do something like:
>
> environment(ls.default) <- asNamespace('utils')
> environment(ls) <- asNamespace('utils')
> environment(ls.proto) <- asNamespace('utils')
>
> That does not work either.
>
> Is there a way to make utils:::specialCompletions use my "ls" instead of
> "base::ls"??
>
> I know Deepayan Sarkar is working now on improving the completion system
> (potentially by introducing "completion" generic). That would definitely
> solve the problem. But for now, does a quick fix exist?
>
> Thanks a lot,
> Vitalie
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Simple time series questions

2009-09-11 Thread Gabor Grothendieck
Here it is using zoo and classic graphics.

1. Just paste this into your R session:

library(zoo)

URL <- "http://www.nabble.com/file/p25398419/test%2Bchart%2Bdata.csv";
z <- read.zoo(URL, header = TRUE, format = "%d-%m-%y", sep = ",")

cols <-  c("green", "red", "blue")
plot(z, screen = 1, col = cols)

# 2. Or try this fancier version using the same code
# replacing the plot statement above with all this

plot(z, screen = 1, col = cols, xaxt = "n")

legend("topleft", c("A", "B", "C"), col = cols, lty = 1)

# fancy X axis (code is from ?plot.zoo page)
ym <- as.yearmon(time(z))
mon <- as.numeric(format(ym, "%m"))
yy <- format(ym, "%y")
mm <- substring(month.abb[mon], 1, 1)
Axis(side = 1, at = time(z)[mon == 1], labels = yy[mon == 1], cex.axis = 0.7)
Axis(side = 1, at = time(z)[mon > 1], labels = mm[mon > 1], cex.axis =
0.5, tcl = -0.3)

abline(v = time(z)[mon == 1], col = grey(0.9))
abline(h = axTicks(2), col = grey(0.9))

On Fri, Sep 11, 2009 at 9:07 AM, DKOD  wrote:
>
> Try this script. I converted test_date to numeric decimal year
>
> link <- "C:\\R_Home\\Charts & Graphs Blog\\R_Chart_Doc\\text_data.csv"
>  testdata<- read.table(link, head = T, sep = ",",na.strings = "na")
>  test_date = as.Date(testdata$Date,"%d-%m-%y")
>
> # Convert dates to decimal year
>  my_yr <- as.numeric(format(test_date,format="%Y"))
>  my_mo <- as.numeric(format(test_date, format="%m"))
>  dec_yr <- my_yr + (my_mo+0.5)/12
>
>  plot(dec_yr, testdata$Model, type="l", log="y", xaxs="i", yaxs="i",
>     axes=T, xlim = c(2003, 2008))
>  points(dec_yr, testdata$BaseDataA, type = "l", col = "red")
>  points(dec_yr, testdata$BaseDataB, type = "l", col = "blue")
>  grid( col="grey",lty=1)
>  box()
>
> Kelly
>
> http://chartsgraphs.wordpress.com http://chartsgraphs.wordpress.com
>
>
> gug wrote:
>>
>> Thanks - that works great.
>>
>> Do you have any suggestions about the grid() problem - i.e. that the
>> vertical gridlines do not line up with the x-axis tickmarks (which are
>> years)?
>>
>> I can't see on what basis the vertical gridlines are being positioned, but
>> it doesn't look good that they are not lined up with anything.
>>
>> Thanks,
>>
>> Guy
>>
>>
>> DKOD wrote:
>>>
>>> This script worked for me. Be sure to put in your correct link.
>>>
>>>   link <- "C:\\R_Home\\Charts & Graphs Blog\\R_Chart_Doc\\text_data.csv"
>>>   testdata<- read.table(link, head = T, sep = ",",na.strings = "na")
>>>   test_date = as.Date(testdata$Date,"%d-%m-%y")
>>>
>>>   plot(test_date, testdata$Model, type="l", log="y")
>>>   points(test_date, testdata$BaseDataA, type = "l", col = "red")
>>>   points(test_date, testdata$BaseDataB, type = "l", col = "blue")
>>>
>>> You add 2nd and 3rd series with points command
>>>
>>> Hope this helps.
>>>
>>> Kelly
>>>
>>>  http://chartsgraphs.wordpress.com http://chartsgraphs.wordpress.com
>>>
>>>
>>
>>
>
> --
> View this message in context: 
> http://www.nabble.com/Simple-time-series-questions-tp25398419p25400652.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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