Re: [R] Summary of data for each year

2013-01-31 Thread Pascal Oettli

Hello,

One possibility is:

> creek <- read.csv("creek.csv")
> colnames(creek) <- c("date","flow")
> creek$date <- as.Date(creek$date, "%m/%d/%Y")
> creek <- within(creek, year <- format(date, '%Y'))

> with(creek, aggregate(flow, by=list(year=year), summary))

HTH,
Pascal


Le 01/02/2013 16:32, Janesh Devkota a écrit :

Hello All,

I have a data with two columns. In one column it is date and in another
column it is flow data.

I was able to read the data as date and flow data. I used the following
code:

creek <- read.csv("creek.csv")
library(ggplot2)
creek[1:10,]
colnames(creek) <- c("date","flow")
creek$date <- as.Date(creek$date, "%m/%d/%Y")

The link to my data is https://www.dropbox.com/s/eqpena3nk82x67e/creek.csv

Now, I want to find the summary of each year. I want to especially know
mean, median, maximum etc.

Thanks.

Janesh

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


[R] R code parallelized using plyr and doMC: error message: Error in do.ply(i) : task 1 failed - “could not find function ”getClass“”

2013-01-31 Thread Andrew Crane-Droesch
Dear list,

I'm just getting started learning how to use remote supercomputers for 
execution of parallelized code. I got a lot of initial help from this 

 
previous post, as well as one particularly helpful and patient XSEDE guy.

I'm only using one node (for the meantime), but each of its 32 cores. 
I'm using doMC instead of snow, because the guy at the supercomputer is 
in the process of getting Rmpi running. For now, 32 cores should be 
(more than) adequate for me. My script is of the sort:

|define a bunch of functions
load the data
call libraries
require(doMC)
require(plyr)
registerDoMC(32)

main.function  <-  function(data){
 *thefunction*
 }

results=  llply(1:500,  function(idx){out<-main.function(data)},.parallel=TRUE)

save(results,file="trestles_results")|

This runs fine on my own machine (setting it to run only a few times and 
registering only a couple of cores). But when I run it on the cluster, 
the output file shows that it ran each of the 500 iterations, but I get 
no output file, and I get the following error message:

|Error  in  do.ply(i)  :  task1  failed-  "could not find function"getClass""
Calls:  llply->  %dopar%  ->  
Execution  halted
Nodes: trestles-10-28|

Anybody have any idea what is going on here?

Thanks in advance!

Andrew

PS:  (Apologies for cross posting, this is also on stack overflow)


[[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] Summary of data for each year

2013-01-31 Thread Janesh Devkota
Hello All,

I have a data with two columns. In one column it is date and in another
column it is flow data.

I was able to read the data as date and flow data. I used the following
code:

creek <- read.csv("creek.csv")
library(ggplot2)
creek[1:10,]
colnames(creek) <- c("date","flow")
creek$date <- as.Date(creek$date, "%m/%d/%Y")

The link to my data is https://www.dropbox.com/s/eqpena3nk82x67e/creek.csv

Now, I want to find the summary of each year. I want to especially know
mean, median, maximum etc.

Thanks.

Janesh

[[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] Question on "plotCI" function

2013-01-31 Thread li li
Hi all,
   In my plotCI function, the argument x is chosen to be seq(0.05, 0.95,
by=0.05).
However, when I make the plot, the plot has the x coordinate goes  1:19.
   Does anyone know how to make the x coordinate to be (0,0.5, 0.1, ...,
0.95).
   Thank you.
  Hanna

[[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] the word "rand" comes up in console after typing a command

2013-01-31 Thread C W
I did not closely follow the Mac SIG, but I will look into it now.  Thanks
for pointing it out.
Mike

On Thu, Jan 31, 2013 at 11:16 PM, David Winsemius wrote:

> Better would have been to have been  following the Mac SIG mailing list.
> Had you been reading that list you would have known that this was
> investigated and fixed in the most recent release of the Mac GUI.
>
> --
> David.
>
>
>
> On Jan 31, 2013, at 9:49 PM, C W wrote:
>
>  Hi list,
>> I keep on getting this "rand" word come up on my console.  It shows up
>> maybe one out 20 times I type in R console.  I don't understand why it is
>> coming up?
>>
>>> mean(variables)
>>>
>> [1] -0.41
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand> mean(variables)
>>
>>  rm(list=ls())
>>>
>>
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand
>> rand>
>>
>> This is my session info.
>>
>>> sessionInfo()
>>>
>> R version 2.15.2 (2012-10-26)
>> Platform: x86_64-apple-darwin9.8.0/x86_**64 (64-bit)
>>
>> locale:
>> [1] en_US.UTF-8/en_US.UTF-8/en_US.**UTF-8/C/en_US.UTF-8/en_US.UTF-**8
>>
>> attached base packages:
>> [1] stats graphics  grDevices utils datasets  methods   base
>>
>> Thanks in advance
>> Mike
>>
>> [[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
> Alameda, CA, USA
>
>

[[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] Transforming 4x3 data frame into 2 column df in R

2013-01-31 Thread Gundala Viswanath
I have the following data frame:

> foo
   w x y z
n 1.51550092 1.4337572 1.2791624 1.1771230
q 0.09977303 0.8173761 1.6123402 0.1510737
r 1.17083866 1.2469347 0.8712135 0.8488029

What I want to do is to change it into :

> newdf
1 nw 1.51550092
2 q   w 0.09977303
3 r   w 1.17083866
4 nx 1.43375725
5 q   x 0.81737606
6 r   x 1.24693468
7 n   y 1.27916241
8 q   y 1.61234016
9 r   y 0.87121353
10   nz 1.17712302
11   q   z 0.15107369
12   rz 0.84880292

Whtat's the way to do it?

 - G.V.

[[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] weights for lmrob

2013-01-31 Thread mazlina Abu Bakar
dear experts,

i hv tried to put a different weights for regression using MM-estimator by
using the command:

lmrob(y ~ x, weights = w2rdf)

where weights are uniquely derived. somehow, R gives me Error - "Weights
are not yet implemented for this estimator".

In S-plus, similar command lmRobMM(y~x, weights=w2rdf) execute correctly.
Please help. TQ.

[[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] Help with multiple barplots

2013-01-31 Thread Duncan Mackay

Hi

Another possibility following on from Rich's example and to 
demonstrate what lattice can do with  the latticeExtra package


library(lattice)
library(latticeExtra)
useOuterStrips(
barchart(Freq ~ Var1 | topic + category, groups=Var2, data=opinion,
 stack=TRUE,
 layout=c(3,2),
 scales=list(x=list(relation="free")))
)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au



At 02:29 1/02/2013, you wrote:

Simon,

I think this is what you are looking for.

###Random Data
crime <- sample(c('agree' ,'disagree'), replace=TRUE, size=100)
guns <- sample(c('agree','disagree'), replace=TRUE, size=100)
climate <- sample(c('agree', 'disagree'), replace=TRUE, size=100)
gender <- sample(c('male','both' ,'female'), replace=TRUE, size=100)
age <- sample(c('old', 'neither', 'young'), replace=TRUE, size=100)

dat <- as.data.frame(cbind(crime, guns, climate, gender, age))
rm(crime, guns, climate, gender, age)

opinion <-
  rbind(
data.frame(table(dat[,4], dat[,1]), topic="crime", category="gender"),
data.frame(table(dat[,4], dat[,2]), topic="guns", category="gender"),
data.frame(table(dat[,4], dat[,3]), topic="climate", category="gender"),
data.frame(table(dat[,5], dat[,1]), topic="crime", category="age"),
data.frame(table(dat[,5], dat[,2]), topic="guns", category="age"),
data.frame(table(dat[,5], dat[,3]), topic="climate", category="age")
)


library(lattice)
barchart(Freq ~ Var1 | topic + category, groups=Var2, data=opinion,
stack=TRUE,
 layout=c(3,2), scales=list(x=list(relation="free")))


Rich

On Thu, Jan 31, 2013 at 10:42 AM, Simon Kiss  wrote:

> Hello: I need to create a six barplots from data that looks pretty close
> to what appears below. There are two grouping variables (age and gender)
> and three dependent variables for each grouping variables.  I'm not really
> familiar with trellis graphics, perhaps there is something that can do what
> I need there, i don't know.
> The thing is: I *need* these to appear on one row, with some way of
> differentiating between the three barplots of one grouping variable and the
> three from the other grouping variable.  It's for a grant application and
> space is at a premium.  The width of everything can be about 7 inches wide
> and the height maybe 2 to 2.5 inches. I also need an outer margin to place
> a legend.  I can do this with the following using the layout command, but I
> cannot figure out a nice way to differentiate the two groups of variables.
>  I'd like to find a way to put a little bit of space between the three from
> one grouping variable and the three from another grouping variable.
>
> If anyone has any thoughts, I'd be very grateful. Yours truly, Simon J.
> Kiss
>
> ###Random Data
> crime<-sample(c('agree' ,'disagree'), replace=TRUE, size=100)
> guns<-sample(c('agree','disagree'), replace=TRUE, size=100)
> climate<-sample(c('agree', 'disagree'), replace=TRUE, size=100)
> gender<-sample(c('male','both' ,'female'), replace=TRUE, size=100)
> age<-sample(c('old', 'neither', 'young'), replace=TRUE, size=100)
> dat<-as.data.frame(cbind(crime, guns, climate, gender, age))
> ###Code I'm working with now
> layout(matrix(c(1,2,3,4,5,6), c(1,6)))
> barplot(prop.table(table(dat$guns, dat$gender), 2))
> barplot(prop.table(table(dat$crime, dat$gender), 2))
> barplot(prop.table(table(dat$climate, dat$gender), 2))
> barplot(prop.table(table(dat$guns, dat$gender), 2))
> barplot(prop.table(table(dat$crime, dat$age), 2))
> barplot(prop.table(table(dat$climate, dat$age), 2))
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


[R] D_f_norm function

2013-01-31 Thread eman kamel
Hi every body,
i am using D_f_norm function from library stat in R
i am using it to find the standard deviation of the output of a function 
'calculate_Z0' that has one of it is inputs as a random variable 'W' , with a 
standard deviation 'Sigm3LER', when i change the mean of this random variable 
'Width', i expected the standard deviation output from d_f_norm to change 
respectively.
here is the code i use



Z0_extra <- function(W, Thickness,Height,Spacing)
{
 f <- function(vec) { calculate_Z0(vec[1],Thickness, Height,Spacing) }
 tmp <- D_f_norm(f, means=c(Width), sds=c(Sigm3LER))
 list(mean=tmp$mean ,sd=tmp$sd )
}

calculate_Z0 <- function(W,Thickness, Height, Spacing)
{
Z0 
<- sqrt((Resistivity/(Thickness * 
W))/(2*3.14*5*10^9*(epsilon*(1.15*(W/Height) + 2.8* 
(Thickness/Height)^0.222 + 2*( 
0.03*(W/Height)+0.83*(Thickness/Height)-.07*(Thickness/Height)^0.222)*(Spacing/Height)^
 (-1.34)) )))
}

but this does not happen, although i change the mean of the output "Width", the 
standard deviation of the output function 'Z0_extra' does not change.
i do not no if this the correct output and i have to change my expectations or 
there is something wrong in the way i use D_f_norm.

can any one advise me on that?

thanks and best regards
Eman


[[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] glm poisson and quasipoisson

2013-01-31 Thread Wim Kreinen
Hello,

I have a question about modelling via  glm. I have a dataset (see dput)
that looks like as if it where poisson distributed (actually I would
appreciate that) but it isnt because  mean unequals var.


> mean (x)
[1] 901.7827
> var (x)
[1] 132439.3


Anyway, I tried to model it via poisson and quasipoisson. Actually, just to
get an impression how glm works. But I dont know how to interprete the
data. Of course this is the case because my knowledge concerning logistic
regressions is rather limited. Hoping there is somebody with mercy I would
like to understand which parameters are important, e.g. which paramter
might give me a hint that a poisson model is a bad idea. For hints
concerning some tutorials  about reading glm-output I would appreciate as
well.

Thanks
Wim


> skn300.glmp <- glm (freq~n, data=skn300.tab, family=poisson)
> summary (skn300.glmp)

Call:
glm(formula = freq ~ n, family = poisson, data = skn300.tab)

Deviance Residuals:
Min   1Q   Median   3Q  Max
-51.332   -9.383   -6.599   -3.959   55.111

Coefficients:
  Estimate Std. Error z value Pr(>|z|)
(Intercept)  7.2374375  0.0093285   775.8   <2e-16 ***
n   -0.0539424  0.0003699  -145.8   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

Null deviance: 71731  on 96  degrees of freedom
Residual deviance: 37383  on 95  degrees of freedom
AIC: 37800

Number of Fisher Scoring iterations: 6

>
> skn300.glmq <- glm (freq~n, data=skn300.tab, family=quasipoisson)
> summary (skn300.glmq)

Call:
glm(formula = freq ~ n, family = quasipoisson, data = skn300.tab)

Deviance Residuals:
Min   1Q   Median   3Q  Max
-51.332   -9.383   -6.599   -3.959   55.111

Coefficients:
 Estimate Std. Error t value Pr(>|t|)
(Intercept)  7.237438   0.186381  38.831  < 2e-16 ***
n   -0.053942   0.007391  -7.298  8.8e-11 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for quasipoisson family taken to be 399.1874)

Null deviance: 71731  on 96  degrees of freedom
Residual deviance: 37383  on 95  degrees of freedom
AIC: NA

Number of Fisher Scoring iterations: 6


>  dput (skn300.tab)
structure(list(n = 1:97, freq = c(0L, 0L, 0L, 0L, 1L, 7L, 40L,
100L, 276L, 543L, 952L, 1414L, 1853L, 2199L, 2435L, 2270L, 2042L,
1679L, 1386L, 1108L, 922L, 792L, 642L, 597L, 453L, 424L, 370L,
297L, 278L, 218L, 208L, 172L, 174L, 149L, 124L, 98L, 98L, 67L,
78L, 67L, 46L, 34L, 31L, 42L, 34L, 21L, 28L, 18L, 18L, 18L, 10L,
19L, 6L, 9L, 10L, 6L, 6L, 5L, 3L, 9L, 4L, 3L, 4L, 5L, 2L, 6L,
4L, 2L, 2L, 3L, 3L, 0L, 0L, 0L, 0L, 2L, 1L, 0L, 0L, 0L, 0L, 0L,
1L, 0L, 0L, 1L, 2L, 1L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 1L),
kum = c(0L, 0L, 0L, 0L, 1L, 8L, 48L, 148L, 424L, 967L, 1919L,
L, 5186L, 7385L, 9820L, 12090L, 14132L, 15811L, 17197L,
18305L, 19227L, 20019L, 20661L, 21258L, 21711L, 22135L, 22505L,
22802L, 23080L, 23298L, 23506L, 23678L, 23852L, 24001L, 24125L,
24223L, 24321L, 24388L, 24466L, 24533L, 24579L, 24613L, 24644L,
24686L, 24720L, 24741L, 24769L, 24787L, 24805L, 24823L, 24833L,
24852L, 24858L, 24867L, 24877L, 24883L, 24889L, 24894L, 24897L,
24906L, 24910L, 24913L, 24917L, 24922L, 24924L, 24930L, 24934L,
24936L, 24938L, 24941L, 24944L, 24944L, 24944L, 24944L, 24944L,
24946L, 24947L, 24947L, 24947L, 24947L, 24947L, 24947L, 24948L,
24948L, 24948L, 24949L, 24951L, 24952L, 24952L, 24952L, 24952L,
24952L, 24954L, 24954L, 24954L, 24954L, 24955L)), .Names = c("n",
"freq", "kum"), row.names = c(NA, -97L), class = "data.frame")

[[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] Fw: D_f_norm function

2013-01-31 Thread eman kamel


-

Hi every body,
i am using D_f_norm function from library stat in R
i am using it to find the standard deviation of the output of a function 
'calculate_Z0' that has one of it is inputs as a random variable 'W' , with a 
standard deviation 'Sigm3LER', when i change the mean of this random variable 
'Width', i expected the standard deviation output from d_f_norm to change 
respectively.
here is the code i use



Z0_extra <- function(W, Thickness,Height,Spacing)
{
 f <- function(vec) { calculate_Z0(vec[1],Thickness, Height,Spacing) }
 tmp <- D_f_norm(f, means=c(Width), sds=c(Sigm3LER))
 list(mean=tmp$mean ,sd=tmp$sd )
}

calculate_Z0 <- function(W,Thickness, Height, Spacing)
{
Z0 
<- sqrt((Resistivity/(Thickness * 
W))/(2*3.14*5*10^9*(epsilon*(1.15*(W/Height) + 2.8* 
(Thickness/Height)^0.222 + 2*( 
0.03*(W/Height)+0.83*(Thickness/Height)-.07*(Thickness/Height)^0.222)*(Spacing/Height)^
 (-1.34)) )))
}

but this does not happen, although i change the mean of the output "Width", the 
standard deviation of the output function 'Z0_extra' does not change.
i do not no if this the correct output and i have to change my expectations or 
there is something wrong in the way i use D_f_norm.

can any one advise me on that?

thanks and best regards
Eman


[[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] the word "rand" comes up in console after typing a command

2013-01-31 Thread David Winsemius
Better would have been to have been  following the Mac SIG mailing  
list. Had you been reading that list you would have known that this  
was investigated and fixed in the most recent release of the Mac GUI.


--
David.


On Jan 31, 2013, at 9:49 PM, C W wrote:


Hi list,
I keep on getting this "rand" word come up on my console.  It shows up
maybe one out 20 times I type in R console.  I don't understand why  
it is

coming up?

mean(variables)

[1] -0.41
rand
rand
rand
rand
rand
rand
rand
rand
rand
rand
rand
rand
rand
rand
rand> mean(variables)


rm(list=ls())


rand
rand
rand
rand
rand
rand
rand
rand
rand
rand
rand
rand
rand
rand
rand
rand>

This is my session info.

sessionInfo()

R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

Thanks in advance
Mike

[[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
Alameda, CA, USA

__
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 on proportions

2013-01-31 Thread Srinivas Iyyer
Hi:
Apologies for asking the following question. As this may sound very basic and 
stupid for this forum , I honestly do not know how to solve it and I do not 
have a teacher who can help me understand. 
 
I have list of genes (200) that are involved in a particular process and I call 
this as a ProcSet.   From an independent experiment I found that out of 10,000 
genes, 1500 are significant and I call these1500 genes as ResultSet.   
 
The intersection of ResultSet and ProcSet are 80 genes.  
 
That means 40% of ProcSet are significant. 
 
 How do I calculate that 40% is significant and more than I expect by chance 
given ResultSet and 10,000 genes I evaluated in the experiment. 
 
What I have:
n = 200 (ProcSet)
p = 0.4
 
N = 1500  (ResultSet)
 
N1 =10,000  
 
Pn = 0.15
 
What kind of test will help me know that 0.4 is significant given 0.15. Any 
suggestions will greatly help me. 
 
Thank you. 
Srini

__
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] the word "rand" comes up in console after typing a command

2013-01-31 Thread C W
Hi list,
I keep on getting this "rand" word come up on my console.  It shows up
maybe one out 20 times I type in R console.  I don't understand why it is
coming up?
> mean(variables)
[1] -0.41
rand
rand
rand
 rand
rand
rand
 rand
rand
rand
 rand
rand
rand
 rand
rand
rand> mean(variables)

> rm(list=ls())

rand
rand
 rand
rand
rand
 rand
rand
rand
 rand
rand
rand
 rand
rand
rand
 rand
rand>

This is my session info.
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

Thanks in advance
Mike

[[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] rbind Missing Something: Need New Eyes

2013-01-31 Thread Peter Langfelder
On Thu, Jan 31, 2013 at 3:55 PM, Rich Shepard  wrote:
> I don't see what's missing in my statements to add rows to a data frame
> and someone else will probably see what needs to be added to the statements.
>
>   The data frame has this structure (without any data):
>
>  $ PHYLUM : chr
>  $ SUBPHYLUM  : chr
>  $ SUPERCLASS : chr
>  $ CLASS  : chr
>  $ SUBCLASS   : chr
>  $ INFRACLASS : chr
>  $ SUPERORDER : chr
>  $ ORDER  : chr
>  $ SUBORDER   : chr
>  $ INFRAORDER : chr
>  $ SUPERFAMILY: chr
>  $ FAMILY : chr
>  $ SUBFAMILY  : chr
>  $ TRIBE  : chr
>  $ SUBTRIBE   : chr
>  $ GENUS  : chr
>  $ TAXON  : chr
>
>   One command (all on one line) is:
>
> itis.ttable <- rbind(itis.ttable, data.frame(PHYLUM = "ARTHROPODA",
> SUBPHYLUM = "MANDIBULATA", SUPERCLASS = NA, CLASS = "INSECTA", SUBCLASS =
> "DICONDYLIA", INFRACLASS = "PTERYGOTA", SUPERORDER = "PANORPIDA", ORDER =
> "TRICHOPTERA", SUBORDER = "INTEGRIPALPIA", INFRAORDER = "PLENITENTORIA",
> SUPERFAMILY = "LIMNEPHILOIDAE", FAMILY = "LIMNEPHILIDAE", SUBFAMILY =
> "LIMNEPHILINAE", TRIBE = "STENOPHYLACINI", SUBTRIBE = NA, GENUS =
> "CHYRANDRA", TAXON = "CENTRALIS"))
>
>   R's response is to ask for more input by displaying the continuation
> prompt, +.
>

Can't reproduce your problem:

> data.frame(PHYLUM = "ARTHROPODA",
+ SUBPHYLUM = "MANDIBULATA", SUPERCLASS = NA, CLASS = "INSECTA", SUBCLASS =
+ "DICONDYLIA", INFRACLASS = "PTERYGOTA", SUPERORDER = "PANORPIDA", ORDER =
+ "TRICHOPTERA", SUBORDER = "INTEGRIPALPIA", INFRAORDER = "PLENITENTORIA",
+ SUPERFAMILY = "LIMNEPHILOIDAE", FAMILY = "LIMNEPHILIDAE", SUBFAMILY =
+ "LIMNEPHILINAE", TRIBE = "STENOPHYLACINI", SUBTRIBE = NA, GENUS =
+ "CHYRANDRA", TAXON = "CENTRALIS")
  PHYLUM   SUBPHYLUM SUPERCLASS   CLASS   SUBCLASS INFRACLASS SUPERORDER
1 ARTHROPODA MANDIBULATA NA INSECTA DICONDYLIA  PTERYGOTA  PANORPIDA
ORDER  SUBORDERINFRAORDERSUPERFAMILYFAMILY
1 TRICHOPTERA INTEGRIPALPIA PLENITENTORIA LIMNEPHILOIDAE LIMNEPHILIDAE
  SUBFAMILY  TRIBE SUBTRIBE GENUS TAXON
1 LIMNEPHILINAE STENOPHYLACINI   NA CHYRANDRA CENTRALIS

> itis.ttable = data.frame(PHYLUM = "ARTHROPODA",
+ SUBPHYLUM = "MANDIBULATA", SUPERCLASS = NA, CLASS = "INSECTA", SUBCLASS =
+ "DICONDYLIA", INFRACLASS = "PTERYGOTA", SUPERORDER = "PANORPIDA", ORDER =
+ "TRICHOPTERA", SUBORDER = "INTEGRIPALPIA", INFRAORDER = "PLENITENTORIA",
+ SUPERFAMILY = "LIMNEPHILOIDAE", FAMILY = "LIMNEPHILIDAE", SUBFAMILY =
+ "LIMNEPHILINAE", TRIBE = "STENOPHYLACINI", SUBTRIBE = NA, GENUS =
+ "CHYRANDRA", TAXON = "CENTRALIS")

> itis.ttable <- rbind(itis.ttable, data.frame(PHYLUM = "ARTHROPODA",
+ SUBPHYLUM = "MANDIBULATA", SUPERCLASS = NA, CLASS = "INSECTA", SUBCLASS =
+ "DICONDYLIA", INFRACLASS = "PTERYGOTA", SUPERORDER = "PANORPIDA", ORDER =
+ "TRICHOPTERA", SUBORDER = "INTEGRIPALPIA", INFRAORDER = "PLENITENTORIA",
+ SUPERFAMILY = "LIMNEPHILOIDAE", FAMILY = "LIMNEPHILIDAE", SUBFAMILY =
+ "LIMNEPHILINAE", TRIBE = "STENOPHYLACINI", SUBTRIBE = NA, GENUS =
+ "CHYRANDRA", TAXON = "CENTRALIS"))
>

All complete without any continuation prompts.

Peter

__
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] Problems Desing Package

2013-01-31 Thread Michael Weylandt
Use rms instead. 

MW

On Jan 31, 2013, at 10:09 PM, Gabriela Agostini  
wrote:

> Hi!
> 
> I need to work whir Desing Package.
> 
> I used
> 
>> library(Design)
> 
> but the following error is displayed on the console
> 
>> library("Design", lib.loc="C:/Program Files/R/R-2.15.1/library")
> Error en library("Design", lib.loc = "C:/Program Files/R/R-2.15.1/library") :
>  package ‘Design’ does not have a NAMESPACE and should be re-installed
> 
> I can´ t re-installed this package from reposity (CRAN, CRANextra) as
> always I do in similar circumstances.
> 
> Thanks!
> 
> 
> 
> 
> Lic. María Gabriela Agostini
> 
> 
> CIMA. Centro de Investigaciones del Medio Ambiente.
> 
> Facultad de Ciencias Exactas. UNLP
> 
> 47 y 115 s/n (1900) La Plata. Argentina
> 
> 
> Conservación de Anfibios en Agroecosistemas
> 
> Sapos y Ranas del Fondo de tu Casa
> 
> http://www.facebook.com/saposyranasdelfondodetucasa
> 
> __
> 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] rbind Missing Something: Need New Eyes [RESOLVED]

2013-01-31 Thread Rich Shepard

On Thu, 31 Jan 2013, Rich Shepard wrote:


   I don't see what's missing in my statements to add rows to a data frame
and someone else will probably see what needs to be added to the statements.


  Found the problem: a FUBAR'd R session.

Rich

__
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] rbind Missing Something: Need New Eyes

2013-01-31 Thread Rich Shepard

I don't see what's missing in my statements to add rows to a data frame
and someone else will probably see what needs to be added to the statements.

  The data frame has this structure (without any data):

 $ PHYLUM : chr
 $ SUBPHYLUM  : chr
 $ SUPERCLASS : chr
 $ CLASS  : chr
 $ SUBCLASS   : chr
 $ INFRACLASS : chr
 $ SUPERORDER : chr
 $ ORDER  : chr
 $ SUBORDER   : chr
 $ INFRAORDER : chr
 $ SUPERFAMILY: chr
 $ FAMILY : chr
 $ SUBFAMILY  : chr
 $ TRIBE  : chr
 $ SUBTRIBE   : chr
 $ GENUS  : chr
 $ TAXON  : chr

  One command (all on one line) is:

itis.ttable <- rbind(itis.ttable, data.frame(PHYLUM = "ARTHROPODA",
SUBPHYLUM = "MANDIBULATA", SUPERCLASS = NA, CLASS = "INSECTA", SUBCLASS =
"DICONDYLIA", INFRACLASS = "PTERYGOTA", SUPERORDER = "PANORPIDA", ORDER =
"TRICHOPTERA", SUBORDER = "INTEGRIPALPIA", INFRAORDER = "PLENITENTORIA",
SUPERFAMILY = "LIMNEPHILOIDAE", FAMILY = "LIMNEPHILIDAE", SUBFAMILY =
"LIMNEPHILINAE", TRIBE = "STENOPHYLACINI", SUBTRIBE = NA, GENUS =
"CHYRANDRA", TAXON = "CENTRALIS"))

  R's response is to ask for more input by displaying the continuation
prompt, +.

  What am I not seeing that R needs to add this row to the data frame?

Rich

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

2013-01-31 Thread Rolf Turner

On 01/25/2013 10:07 AM, Rosario Garcia Gil wrote:

Hello

I am using library(spatstat). I managed to test of the random distribution of a 
collection of sampled trees in the forest. But what I want now is to test if 
their diameter is randomly distributed across the forest, for example the 
bigger trees are not clustered together.

So far I have not managed that. Any one could help?


Sorry for the delay in responding.  I think that you can attack your problem
by applying the markcorr() function and/or the smooth.ppp() function (or its
specialized version markmean()).

You could then assess the randomness of the diameters in your data set
by using the envelope() function.  To apply envelope() make use of the
"simulate" argument so as to base the comparison on patterns generated
by randomly permuting the marks of the observed pattern.  Use the function
rlabel().

Let me know if you need more detail.

cheers,

Rolf Turner

__
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] RODBC and datetimes

2013-01-31 Thread Dave Mitchell
I've got a data.frame I'm trying to insert into a database table in an
ms sql server instance using RODBC.   When I save a table using
nothing but character and numeric columns things work fine.  However,
when I attempt to add another column of type POSIXct to the data.frame
and redefine the table to incorporate the new column (in the
DB),attempting to push the table to the DB using sqlSave results in
the following error:

Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test,  :
  missing columns in 'data'

Has anyone successfully been able to insert into a datetime field in
ms sql server?  If so, what type of variable did you use in R?  I'm
not really sure where to go or what to try next here.  Any advice is
appreciated.  Thanks!

Dave Mitchell

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

2013-01-31 Thread Uwe Ligges



On 31.01.2013 14:12, Duncan Murdoch wrote:

On 13-01-31 1:26 AM, Ortiz, John wrote:


Dear list,

Can I use a character to set the name of a R package? like this (-)

for example (sdp-R)


I can't quite parse your question, but I think the answer is in the
Writing R Extensions manual, section 1.1 "Package Structure".



Right, and "-" is not allowed (but used as a version number separator).

It took me 10 seconds to find out by creating a package "a-b" that does 
not R CMD build with a proper error message - reading the docs would 
also result in the same finding, but takes a minute or two.


Uwe Ligges



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.


__
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] Automated Start for new Rgui within existing R code?

2013-01-31 Thread Greg Snow
You could always just run something like

system("path/to/R/RScript myfile.R")

from within R.

But this also sounds like something that the parallel package  may be
helpful with to use your 8 cores to speed up your update process.


On Thu, Jan 31, 2013 at 2:12 PM, Brigid Mooney  wrote:

> Is there a way to start multiple instances of R in an automated manner?
>
> Since I'm not sure that question makes tons of sense, here's my scenario:
>
> I have a number of data updates that need to be completed on an ongoing
> basis with the data pulled from and then stored to another location.  The
> updates are manually triggered, so can build up in terms of the volume that
> needs to be updated.
>
> The updates can take a lot of time if I run everything from within a single
> Rgui, but it isn't a big deal if there aren't a lot of accumulated updates
> that need to be run.
>
> But say if I have a week or a month's worth of accumulated updates to run,
> this takes a LOT of time in a single Rgui.  If I split it up, I can run it
> on 6 Rgui's (I'm in windows 7 with an 8 Core machine) and increase my
> overall efficiency.  But this requires manual intervention as there are
> steps before (that figure out how big the updates that must be run are) and
> then steps after that summarize and give me some metadata.
>
> What I would love is something that will execute within an existing Rgui
> and allows me to send a command (such as source( "myfile.R" ) to a new
> Rgui.  Does such a command even exist or is this just wishful thinking?
>
> I'm trying to avoid writing a wrapfile in another language which would be
> able to source the .R file as most of this (before and after the ideal
> split point) is written in R already.
>
> (FWIW Windows 7, 8 core machine running 64bit R)
>
> Thanks,
> Brigid
>
> [[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.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@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.


Re: [R] Automated Start for new Rgui within existing R code?

2013-01-31 Thread Jeff Newmiller
?parallel::parallel

Only one gui, multiple cores working at once.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Brigid Mooney  wrote:

>Is there a way to start multiple instances of R in an automated manner?
>
>Since I'm not sure that question makes tons of sense, here's my
>scenario:
>
>I have a number of data updates that need to be completed on an ongoing
>basis with the data pulled from and then stored to another location. 
>The
>updates are manually triggered, so can build up in terms of the volume
>that
>needs to be updated.
>
>The updates can take a lot of time if I run everything from within a
>single
>Rgui, but it isn't a big deal if there aren't a lot of accumulated
>updates
>that need to be run.
>
>But say if I have a week or a month's worth of accumulated updates to
>run,
>this takes a LOT of time in a single Rgui.  If I split it up, I can run
>it
>on 6 Rgui's (I'm in windows 7 with an 8 Core machine) and increase my
>overall efficiency.  But this requires manual intervention as there are
>steps before (that figure out how big the updates that must be run are)
>and
>then steps after that summarize and give me some metadata.
>
>What I would love is something that will execute within an existing
>Rgui
>and allows me to send a command (such as source( "myfile.R" ) to a new
>Rgui.  Does such a command even exist or is this just wishful thinking?
>
>I'm trying to avoid writing a wrapfile in another language which would
>be
>able to source the .R file as most of this (before and after the ideal
>split point) is written in R already.
>
>(FWIW Windows 7, 8 core machine running 64bit R)
>
>Thanks,
>Brigid
>
>   [[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.


[R] Automated Start for new Rgui within existing R code?

2013-01-31 Thread Brigid Mooney
Is there a way to start multiple instances of R in an automated manner?

Since I'm not sure that question makes tons of sense, here's my scenario:

I have a number of data updates that need to be completed on an ongoing
basis with the data pulled from and then stored to another location.  The
updates are manually triggered, so can build up in terms of the volume that
needs to be updated.

The updates can take a lot of time if I run everything from within a single
Rgui, but it isn't a big deal if there aren't a lot of accumulated updates
that need to be run.

But say if I have a week or a month's worth of accumulated updates to run,
this takes a LOT of time in a single Rgui.  If I split it up, I can run it
on 6 Rgui's (I'm in windows 7 with an 8 Core machine) and increase my
overall efficiency.  But this requires manual intervention as there are
steps before (that figure out how big the updates that must be run are) and
then steps after that summarize and give me some metadata.

What I would love is something that will execute within an existing Rgui
and allows me to send a command (such as source( "myfile.R" ) to a new
Rgui.  Does such a command even exist or is this just wishful thinking?

I'm trying to avoid writing a wrapfile in another language which would be
able to source the .R file as most of this (before and after the ideal
split point) is written in R already.

(FWIW Windows 7, 8 core machine running 64bit R)

Thanks,
Brigid

[[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] LogLik of nls

2013-01-31 Thread Bert Gunter
methods(logLik)   ## for S3 methods
stats:::logLik.nls
### and look at the code!

-- Bert

On Thu, Jan 31, 2013 at 12:06 PM, Diviya Smith  wrote:
> Hello there,
>
> Can anyone point me to the code for logLik of an nls object? I found the
> code for logLik of an lm but could not find exactly what function is used
> for calculating the logLik of nls function?
>
> I am using the nls to fit the following model to data -
> Model 1: y ~ Ae^(-mx) + Be^(-nx) +c
>
> and want to understand what is the likelihood function used by nls.
> Presumably it is using -
> N(Ae^(-mx) + Be^(-nx) +c, var = residuals from nls)
>
> Thank  you in advance,
>
> Diviya
>
> [[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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
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] LogLik of nls

2013-01-31 Thread Diviya Smith
Hello there,

Can anyone point me to the code for logLik of an nls object? I found the
code for logLik of an lm but could not find exactly what function is used
for calculating the logLik of nls function?

I am using the nls to fit the following model to data -
Model 1: y ~ Ae^(-mx) + Be^(-nx) +c

and want to understand what is the likelihood function used by nls.
Presumably it is using -
N(Ae^(-mx) + Be^(-nx) +c, var = residuals from nls)

Thank  you in advance,

Diviya

[[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 loop on data frame

2013-01-31 Thread Jeff Newmiller
Your example is not reproducible. See 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

I would guess you have tabs at the ends of your lines in the input file. This 
is a fairly common problem when you muck with data in Excel.

To find these problems yourself, learn to examine the objects you create by 
executing the statements one-to-one and interspersing ?str calls and printing 
objects so you understand what the code is working with.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Esam Tolba  wrote:

>I am a beginner in R.
>I wrote a function to read a data frame from a file and then split it
>into certain number of data frames and write each one of them  in a
>separate txt file.
>the function is working perfectly for the first four files the it
>gives me files contain one column of NA values.
>
>split= function (filename,linesno,filesno) {
>i=1
>j=linesno
>k=1
>e=1
>  x=read.table(filename, sep=("\t"), header= FALSE)
>for (i in 1:filesno){
>xx=x[e:j, ]
>l=paste0(filename,0,k,".pdb")
>write.table(xx, l, quote =FALSE, sep =
>"\t",row.names = FALSE, col.names = FALSE)
>k=k+1
>e=e+j
>j=2*j
>}
>}
>what could be the problem?
>Esam
>
>__
>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] Locate Patients who have multiple high blood pressure readings

2013-01-31 Thread arun
Hi,

May be this helps:

#dd
res<-data.frame(Include=with(subset(dd,OBS_TYPE == "SBP" & Blood_Pressure >= 
140|OBS_TYPE=="DBP" & 
Blood_Pressure>=90),apply(tapply(Blood_Pressure,list(PT_ID,OBS_TYPE),length)>=2,1,any,na.rm=T)))
res
 #    Include
#1900    TRUE
#2900   FALSE
#3900   FALSE
A.K.




- Original Message -
From: Weijia Wang 
To: r-help@r-project.org
Cc: 
Sent: Thursday, January 31, 2013 10:51 AM
Subject: [R] Locate Patients who have multiple high blood pressure readings

On Thu, Jan 31, 2013 at 10:29 AM, Weijia Wang  wrote:

> Hi,
>
>
>
> I have a new question about subsetting in R.
>
>
>
> Say we have this data frame:
>
>
>
>     PT_ID Blood_Pressure OBS_TYPE
>
> 92   1900      90.0      DBP
>
> 94   1900      90.0      DBP
>
> 174  2900     140.0      SBP
>
> 176  2900     130.0      SBP
>
> 180  3900     120.0      SBP
>
> 268  3900     150.0      SBP
>
> 268  3900      90.0      DBP
>
>
>
> I need to obtain those with 2+ DBP>=90 or 2+ SBP>=140.
>
>
>
> PT_ID=1900, he has 2 DBP>=90, so he will be included.
>
> PT_ID=2900, he has 1 SBP>=140, so he will NOT be included.
>
> PT_ID=3900, he has 1 SBP>=140 and 1 DBP>=90, so he will still NOT be
> included.
>
>
>
> So, the condition requires TWO OR MORE values higher than the threshold.
> It could be either SBP or DBP or both of them.
>
>
>
> I have tried ddply, but I don’t know how to add the condition 2+ inside
> ddply.
>
>
>
> Any help is appreciated!!
>
>
>
> Weijia
>
>
>

    [[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] Locate Patients who have multiple high blood pressure readings

2013-01-31 Thread Gabor Grothendieck
On Thu, Jan 31, 2013 at 10:51 AM, Weijia Wang  wrote:
> On Thu, Jan 31, 2013 at 10:29 AM, Weijia Wang  wrote:
>
>> Hi,
>>
>>
>>
>> I have a new question about subsetting in R.
>>
>>
>>
>> Say we have this data frame:
>>
>>
>>
>> PT_ID Blood_Pressure OBS_TYPE
>>
>> 92   1900  90.0  DBP
>>
>> 94   1900  90.0  DBP
>>
>> 174  2900 140.0  SBP
>>
>> 176  2900 130.0  SBP
>>
>> 180  3900 120.0  SBP
>>
>> 268  3900 150.0  SBP
>>
>> 268  3900  90.0  DBP
>>
>>
>>
>> I need to obtain those with 2+ DBP>=90 or 2+ SBP>=140.
>>
>>
>>
>> PT_ID=1900, he has 2 DBP>=90, so he will be included.
>>
>> PT_ID=2900, he has 1 SBP>=140, so he will NOT be included.
>>
>> PT_ID=3900, he has 1 SBP>=140 and 1 DBP>=90, so he will still NOT be
>> included.
>>
>>
>>
>> So, the condition requires TWO OR MORE values higher than the threshold.
>> It could be either SBP or DBP or both of them.
>>
>>
>>
>> I have tried ddply, but I don’t know how to add the condition 2+ inside
>> ddply.
>>

This can be specified in a reasonably natural fashion using SQL. Here
DF is the input data frame.:

> library(sqldf)
> sqldf("select
+   PT_ID,
+   sum(Blood_Pressure >= 90 and OBS_TYPE == 'DBP') DBP,
+   sum(Blood_Pressure >= 140 and OBS_TYPE == 'SBP') SBP
+from DF
+group by PT_ID
+having DBP >= 2 or SBP >= 2")
  PT_ID DBP SBP
1  1900   2   0

__
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] For loop on data frame

2013-01-31 Thread Esam Tolba
I am a beginner in R.
I wrote a function to read a data frame from a file and then split it
into certain number of data frames and write each one of them  in a
separate txt file.
the function is working perfectly for the first four files the it
gives me files contain one column of NA values.

split= function (filename,linesno,filesno) {
i=1
j=linesno
k=1
e=1
x=read.table(filename, sep=("\t"), header= FALSE)
for (i in 1:filesno){
xx=x[e:j, ]
l=paste0(filename,0,k,".pdb")
write.table(xx, l, quote =FALSE, sep =
"\t",row.names = FALSE, col.names = FALSE)
k=k+1
e=e+j
j=2*j
}
}
what could be the problem?
Esam

__
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] Locate Patients who have multiple high blood pressure readings

2013-01-31 Thread William Dunlap
> dd <-  # from dput() 
structure(list(ColA = c(92L, 94L, 174L, 176L, 180L, 268L, 268L
), PT_ID = c(1900L, 1900L, 2900L, 2900L, 3900L, 3900L, 3900L),
Blood_Pressure = c(90, 90, 140, 130, 120, 150, 90), OBS_TYPE = 
structure(c(1L,
1L, 2L, 2L, 2L, 2L, 1L), .Label = c("DBP", "SBP"), class = "factor")), 
.Names = c("ColA",
"PT_ID", "Blood_Pressure", "OBS_TYPE"), class = "data.frame", row.names = c(NA,
-7L))
> library(plyr)
> ddply(dd, .(PT_ID), summarize, Include=sum(OBS_TYPE=="DBP" & 
> Blood_Pressure>=90)>=2 || sum(OBS_TYPE=="SBP" & Blood_Pressure>=140)>=2)
  PT_ID Include
1  1900TRUE
2  2900   FALSE
3  3900   FALSE

sum(logicalVector) tells how many TRUE's are in logicalVector.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of Bert Gunter
> Sent: Thursday, January 31, 2013 9:52 AM
> To: Weijia Wang
> Cc: r-help@r-project.org
> Subject: Re: [R] Locate Patients who have multiple high blood pressure 
> readings
> 
> Well, since no one has responded
> 
> 
> Please use ?dput to provide data in your posts.
> 
>  There are likely  zillions of way to go about this. Following is one
> way based on ?duplicated that I think works, but I make no claims for
> either elegance or efficiency. Others may do lots better. But maybe it
> suffices.
> 
> 
> ## Untested
> ## I assume the data is provided in a data frame named dd.
> 
> ## All PT_ID's with >=1 high readings in SBP or in DBP
> > hiS <- with(dd,PT_ID[OBS_TYPE == "SBP" & Blood_Pressure >= 140])
> > hiD <-  with(dd,PT_ID[OBS_TYPE == "DBP" & Blood_Pressure > =90])
> 
> ## id's that appear more than once in either
> > union(unique(hiS[duplicated(hiS)]), unique(hiD[duplicated(hiD)])
> 
> ## you can subset your data frame to match just these,  e.g. via
> %in%, if you like.
> 
> 
> Cheers,
> Bert
> 
> 
> 
> 
> On Thu, Jan 31, 2013 at 7:51 AM, Weijia Wang  wrote:
> > On Thu, Jan 31, 2013 at 10:29 AM, Weijia Wang  wrote:
> >
> >> Hi,
> >>
> >>
> >>
> >> I have a new question about subsetting in R.
> >>
> >>
> >>
> >> Say we have this data frame:
> >>
> >>
> >>
> >> PT_ID Blood_Pressure OBS_TYPE
> >>
> >> 92   1900  90.0  DBP
> >>
> >> 94   1900  90.0  DBP
> >>
> >> 174  2900 140.0  SBP
> >>
> >> 176  2900 130.0  SBP
> >>
> >> 180  3900 120.0  SBP
> >>
> >> 268  3900 150.0  SBP
> >>
> >> 268  3900  90.0  DBP
> >>
> >>
> >>
> >> I need to obtain those with 2+ DBP>=90 or 2+ SBP>=140.
> >>
> >>
> >>
> >> PT_ID=1900, he has 2 DBP>=90, so he will be included.
> >>
> >> PT_ID=2900, he has 1 SBP>=140, so he will NOT be included.
> >>
> >> PT_ID=3900, he has 1 SBP>=140 and 1 DBP>=90, so he will still NOT be
> >> included.
> >>
> >>
> >>
> >> So, the condition requires TWO OR MORE values higher than the threshold.
> >> It could be either SBP or DBP or both of them.
> >>
> >>
> >>
> >> I have tried ddply, but I don’t know how to add the condition 2+ inside
> >> ddply.
> >>
> >>
> >>
> >> Any help is appreciated!!
> >>
> >>
> >>
> >> Weijia
> >>
> >>
> >>
> >
> > [[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.
> >
> 
> 
> 
> --
> 
> Bert Gunter
> Genentech Nonclinical Biostatistics
> 
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-
> biostatistics/pdb-ncb-home.htm
> 
> __
> 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] Locate Patients who have multiple high blood pressure readings

2013-01-31 Thread Bert Gunter
Well, since no one has responded


Please use ?dput to provide data in your posts.

 There are likely  zillions of way to go about this. Following is one
way based on ?duplicated that I think works, but I make no claims for
either elegance or efficiency. Others may do lots better. But maybe it
suffices.


## Untested
## I assume the data is provided in a data frame named dd.

## All PT_ID's with >=1 high readings in SBP or in DBP
> hiS <- with(dd,PT_ID[OBS_TYPE == "SBP" & Blood_Pressure >= 140])
> hiD <-  with(dd,PT_ID[OBS_TYPE == "DBP" & Blood_Pressure > =90])

## id's that appear more than once in either
> union(unique(hiS[duplicated(hiS)]), unique(hiD[duplicated(hiD)])

## you can subset your data frame to match just these,  e.g. via
%in%, if you like.


Cheers,
Bert




On Thu, Jan 31, 2013 at 7:51 AM, Weijia Wang  wrote:
> On Thu, Jan 31, 2013 at 10:29 AM, Weijia Wang  wrote:
>
>> Hi,
>>
>>
>>
>> I have a new question about subsetting in R.
>>
>>
>>
>> Say we have this data frame:
>>
>>
>>
>> PT_ID Blood_Pressure OBS_TYPE
>>
>> 92   1900  90.0  DBP
>>
>> 94   1900  90.0  DBP
>>
>> 174  2900 140.0  SBP
>>
>> 176  2900 130.0  SBP
>>
>> 180  3900 120.0  SBP
>>
>> 268  3900 150.0  SBP
>>
>> 268  3900  90.0  DBP
>>
>>
>>
>> I need to obtain those with 2+ DBP>=90 or 2+ SBP>=140.
>>
>>
>>
>> PT_ID=1900, he has 2 DBP>=90, so he will be included.
>>
>> PT_ID=2900, he has 1 SBP>=140, so he will NOT be included.
>>
>> PT_ID=3900, he has 1 SBP>=140 and 1 DBP>=90, so he will still NOT be
>> included.
>>
>>
>>
>> So, the condition requires TWO OR MORE values higher than the threshold.
>> It could be either SBP or DBP or both of them.
>>
>>
>>
>> I have tried ddply, but I don’t know how to add the condition 2+ inside
>> ddply.
>>
>>
>>
>> Any help is appreciated!!
>>
>>
>>
>> Weijia
>>
>>
>>
>
> [[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.
>



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
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 eigen() for extracting only few major eigenpairs

2013-01-31 Thread Pierrick Bruneau
Thanks a lot ! I'm going to try this very soon.

As the package seems general purpose (ie not dedicated to real symmetric
matrices), I hope it remains more efficient than the eigen function
parametrized for symmetric matrices.

Pierrick Bruneau
CRP Gabriel Lippmann

On Thu, Jan 31, 2013 at 2:51 PM, Mark Leeds  wrote:

> hi: the irlba package does what you're looking for.
>
>
> On Thu, Jan 31, 2013 at 3:32 AM, Pierrick Bruneau wrote:
>
>> Hi everyone,
>>
>> I am using eigen() to extract the 2 major eigenpairs from a large real
>> square symmetric matrix. The procedure is already rather efficient, but
>> becomes somehow slow for real time needs with moderately large matrices
>> (few thousand lines).
>>
>> The R implementation statically extracts all eigenvalues (and optionally
>> associated eigenvectors). I heard about optimizations of the eigen
>> decomposition when only few eigenpairs are needed : did somebody already
>> care about this problem (through a contributed package for example) ? Or
>> do
>> I have to directly try to mess around with the LAPACK library (and
>> contribute the package myself afterwards) ?
>>
>> Thanks by advance for your help,
>> Pierrick Bruneau
>> CRP Gabriel Lippmann
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

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


Re: [R] Modify objects in function

2013-01-31 Thread Simon Zehnder
Hi Barry,

this actually a good idea, to put them together! Probably even creating an 
object containing both of them. Haven't thought about it before. 

Best
Simon
On Jan 31, 2013, at 3:49 PM, Barry Rowlingson  
wrote:

> On Thu, Jan 31, 2013 at 11:52 AM, Simon Zehnder  wrote:
>> Dear R community,
>> 
>> I do know, that an R function is constructing a copy of any object passed as 
>> argument into a function. I program on a larger S4 project for a package, 
>> and I arrived at a point where I have to think a little harder on 
>> implementation style (especially to spare users complex object handling).
>> 
>> I have a function foo(), taking as input arguments two S4 objects of 
>> different class type
>> 
>> foo <- function(o1, o2) {
>>o1@att1 <- producesomething()
>>o2@att2 <- producesomethingelse()
>> 
>> }
>> 
>> Of course, this functions does not change the objects in the global 
>> environment. Now I have two choices
>> 
>> 1. Change the objects and return a list with both objects:
>> 
>>foo <- function(o1, o2) {
>>o1@att1 <- producesomething()
>>o2@att2 <- producesomethingelse()
>> 
>>l <- list(O1 = o1, O2 = o2)
>>return(l)
>>}
>> 
>> This is cumbersome for users, as they have then to assign the objects inside 
>> the returned list to the symbols used in the global environment. But it is 
>> the way intended by R.
> 
> By cumbersome you mean the following (anti-?) pattern has to be used,
> for example in a loop:
> 
> o1 = something()
> o2 = somethingelse()
> o12 = foo(o1,o2)
> o1 = o12$o1
> o2 = o12$o2
> 
> so that at the end of it you have a modified o1 and o2?
> 
> I suggest that if you have a function that modifies more than one of
> its arguments, then there is a strong case for making those arguments
> a single argument. So that you'd do:
> 
> foo = function(o12){
>o12$o1@att=bar()
>o12$o2@att=baz()
>return(o12)
>  }
> 
> o12 = list(something(), somethingelse())
> o12 = foo(o12)
> 
> and there you are, a modified o12 object. no packing/unpacking needed.
> 
> I suspect that either your o1 and o2 are so closely related that you
> should pack them in a list (or ideally, an object) or differently
> related such that you should treat them separately and not tweak both
> of them within the same function. That approach is binding behaviour
> very tightly to two structures, and probably won't give you very
> debuggable modular code.
> 
> 
> B

__
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] use name (not values!) of a dataframe inside a funktion

2013-01-31 Thread Winfried Moser
Dear Listers,

can anyone help me, please.

Since several days i try to figure out, how to assign values, vectors,
functions etc to variables with dynamically generated names inside of
functions.
Sometimes I succeed, but the success is rather arbitrary, it seems. up to
now i don't fully understand, why things like get, assign, <<- etc do
sometimes work, and sometimes not.

here's one of my daily examples, i am stuck with: Example 1 does work, but
example 2 doesn't?
How kann i tell R, that i want it to expand the string "dfb" to "dfb[,2]"
inside the function.
In the end i want the function to change the second variable of the
dataframe dfb permanently to factor (not just inside the function).

Thanks in advance!

Winfried


Example 1:
dfa <- data.frame(a=c(1:4),b=c(1:4))
dfa[,2] <- factor(dfa[,2])
is.factor(dfa[,2])
>TRUE

Example 2:
dfb <- data.frame(a=c(1:4),b=c(1:4))
f.fact <- function(x) {x[,2] <<- factor(x[,2])}
f.fact(dfb)
is.factor(dfb[,2])
>FALSE


PS: I tried a whole lot of other things like, ...
I really don't know where to keep on searching.


dfb <- data.frame(a=c(1,2,3,4),b=c(1,2,3,4))
f.fact <- function(x) {get(x)[,2] <<- factor(get(x)[,2])}
f.fact("dfb")
is.factor(dfb[,2])
> "Object 'x' nicht gefunden

dfb <- data.frame(a=c(1,2,3,4),b=c(1,2,3,4))
f.fact <- function(x) {get(x[,2]) <<- factor(x[,2])}
f.fact(dfb)
is.factor(dfb[,2])
> "Object 'x' nicht gefunden

dfb <- data.frame(a=c(1,2,3,4),b=c(1,2,3,4))
f.fact <- function(x) {get(x)[,2] <<- factor(x[,2])}
f.fact(dfb)
is.factor(dfb[,2])
> "Object 'x' nicht gefunden

dfb <- data.frame(a=c(1,2,3,4),b=c(1,2,3,4))
f.fact <- function(x) {assign(x[,2], factor(x[,2]))}
f.fact(dfb)
is.factor(dfb[,2])
> Ungültiges erstes Argument

dfb <- data.frame(a=c(1,2,3,4),b=c(1,2,3,4))
f.fact <- function(x) {quote(x)[,2], factor(x[,2])}
f.fact(dfb)
is.factor(dfb[,2])
> Unerwartetes ','

dfb <- data.frame(a=c(1,2,3,4),b=c(1,2,3,4))
f.fact <- function(x) {
name <- paste0(quote(x),"[,2]")
 assign(name, factor(x[,2]))}
f.fact(dfb)
is.factor(dfb[,2])
> FALSE

dfb <- data.frame(a=c(1,2,3,4),b=c(1,2,3,4))
f.fact <- function(x) {
name <- paste0(get(x),"[,2]")
assign(name, factor(x[,2]))}
f.fact("dfb")
is.factor(dfb[,2])
> Falsche Anzahl von Dimensionen

dfb <- data.frame(a=c(1,2,3,4),b=c(1,2,3,4))
f.fact <- function(x) {
 name <- paste0(x,"[,2]")
assign(name, factor(x[,2]))}
f.fact("dfb")
is.factor(dfb[,2])
> Falsche Anzahl von Dimensionen

ächz ...

[[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] Modify objects in function

2013-01-31 Thread Simon Zehnder
Dear Barry,

thank you very much for this information. This looks pretty interesting! 

Best

Simon
On Jan 31, 2013, at 4:09 PM, Barry Rowlingson  
wrote:

>> it lets you do:
>> 
>> (a~b~c) = foo()
> 
> Mistook. should be:
> 
> (a~b~c) %=% foo()
> 
> because it defines the %=% operator.
> 
> Barry

__
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 multiple barplots

2013-01-31 Thread Rui Barradas

Hello,

Maybe the following will help.

layout(matrix(c(1,2,3,0,4,5,6), c(1,6)))

Note the zero. It reserves space but no graph is put there.

There is an error in your code, you plot twice guns/gender. I think the 
second is meant to be guns/age.

Also, you can do those 6 barplot instructions like this:


lapply(c("gender", "age"), function(y) {
lapply(c("guns", "crime", "climate"), function(x)
barplot(prop.table(table(dat[[x]], dat[[y]]), 2)))})


Hope this helps,

Rui Barradas

Em 31-01-2013 15:42, Simon Kiss escreveu:

Hello: I need to create a six barplots from data that looks pretty close to 
what appears below. There are two grouping variables (age and gender) and three 
dependent variables for each grouping variables.  I'm not really familiar with 
trellis graphics, perhaps there is something that can do what I need there, i 
don't know.
The thing is: I *need* these to appear on one row, with some way of 
differentiating between the three barplots of one grouping variable and the 
three from the other grouping variable.  It's for a grant application and space 
is at a premium.  The width of everything can be about 7 inches wide and the 
height maybe 2 to 2.5 inches. I also need an outer margin to place a legend.  I 
can do this with the following using the layout command, but I cannot figure 
out a nice way to differentiate the two groups of variables.  I'd like to find 
a way to put a little bit of space between the three from one grouping variable 
and the three from another grouping variable.

If anyone has any thoughts, I'd be very grateful. Yours truly, Simon J. Kiss

###Random Data
crime<-sample(c('agree' ,'disagree'), replace=TRUE, size=100)
guns<-sample(c('agree','disagree'), replace=TRUE, size=100)
climate<-sample(c('agree', 'disagree'), replace=TRUE, size=100)
gender<-sample(c('male','both' ,'female'), replace=TRUE, size=100)
age<-sample(c('old', 'neither', 'young'), replace=TRUE, size=100)
dat<-as.data.frame(cbind(crime, guns, climate, gender, age))
###Code I'm working with now
layout(matrix(c(1,2,3,4,5,6), c(1,6)))
barplot(prop.table(table(dat$guns, dat$gender), 2))
barplot(prop.table(table(dat$crime, dat$gender), 2))
barplot(prop.table(table(dat$climate, dat$gender), 2))
barplot(prop.table(table(dat$guns, dat$gender), 2))
barplot(prop.table(table(dat$crime, dat$age), 2))
barplot(prop.table(table(dat$climate, dat$age), 2))

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



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


[R] rgenoud and snow

2013-01-31 Thread michele caseposta
Hello everyone.
I am trying to use rgenoud in a parallel environment.
While making some tests, I noticed that rgenoud seems not to be using the 
cluster created by makeCluster, doing all the computation in the main node.

Following is the example:

ncores <- 5
cl <- makeCluster(rep('localhost', ncores), type='SOCK')

evalFunc3 <- function(x){
  r <- rnorm(100)
  print(Sys.getpid())
  return(x[1]/2-x[2]^3+0.5)
}

genResSeq <- genoud(evalFunc3, nvars=2, max=T, pop.size=ncores, cluster = cl)

stopCluster(cl)

Is this the expected behavior? I would have guessed each node to be busy with 
the evaluation of the function for each individual, but it does not seem to be 
the case.
__
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 multiple barplots

2013-01-31 Thread Richard M. Heiberger
Simon,

I think this is what you are looking for.

###Random Data
crime <- sample(c('agree' ,'disagree'), replace=TRUE, size=100)
guns <- sample(c('agree','disagree'), replace=TRUE, size=100)
climate <- sample(c('agree', 'disagree'), replace=TRUE, size=100)
gender <- sample(c('male','both' ,'female'), replace=TRUE, size=100)
age <- sample(c('old', 'neither', 'young'), replace=TRUE, size=100)

dat <- as.data.frame(cbind(crime, guns, climate, gender, age))
rm(crime, guns, climate, gender, age)

opinion <-
  rbind(
data.frame(table(dat[,4], dat[,1]), topic="crime", category="gender"),
data.frame(table(dat[,4], dat[,2]), topic="guns", category="gender"),
data.frame(table(dat[,4], dat[,3]), topic="climate", category="gender"),
data.frame(table(dat[,5], dat[,1]), topic="crime", category="age"),
data.frame(table(dat[,5], dat[,2]), topic="guns", category="age"),
data.frame(table(dat[,5], dat[,3]), topic="climate", category="age")
)


library(lattice)
barchart(Freq ~ Var1 | topic + category, groups=Var2, data=opinion,
stack=TRUE,
 layout=c(3,2), scales=list(x=list(relation="free")))


Rich

On Thu, Jan 31, 2013 at 10:42 AM, Simon Kiss  wrote:

> Hello: I need to create a six barplots from data that looks pretty close
> to what appears below. There are two grouping variables (age and gender)
> and three dependent variables for each grouping variables.  I'm not really
> familiar with trellis graphics, perhaps there is something that can do what
> I need there, i don't know.
> The thing is: I *need* these to appear on one row, with some way of
> differentiating between the three barplots of one grouping variable and the
> three from the other grouping variable.  It's for a grant application and
> space is at a premium.  The width of everything can be about 7 inches wide
> and the height maybe 2 to 2.5 inches. I also need an outer margin to place
> a legend.  I can do this with the following using the layout command, but I
> cannot figure out a nice way to differentiate the two groups of variables.
>  I'd like to find a way to put a little bit of space between the three from
> one grouping variable and the three from another grouping variable.
>
> If anyone has any thoughts, I'd be very grateful. Yours truly, Simon J.
> Kiss
>
> ###Random Data
> crime<-sample(c('agree' ,'disagree'), replace=TRUE, size=100)
> guns<-sample(c('agree','disagree'), replace=TRUE, size=100)
> climate<-sample(c('agree', 'disagree'), replace=TRUE, size=100)
> gender<-sample(c('male','both' ,'female'), replace=TRUE, size=100)
> age<-sample(c('old', 'neither', 'young'), replace=TRUE, size=100)
> dat<-as.data.frame(cbind(crime, guns, climate, gender, age))
> ###Code I'm working with now
> layout(matrix(c(1,2,3,4,5,6), c(1,6)))
> barplot(prop.table(table(dat$guns, dat$gender), 2))
> barplot(prop.table(table(dat$crime, dat$gender), 2))
> barplot(prop.table(table(dat$climate, dat$gender), 2))
> barplot(prop.table(table(dat$guns, dat$gender), 2))
> barplot(prop.table(table(dat$crime, dat$age), 2))
> barplot(prop.table(table(dat$climate, dat$age), 2))
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] Longitudinal RelaImpo in LME4

2013-01-31 Thread Torvon
I am currently using the relaimpo package to estimate the relative
importance of regressors (N= 4000):

> m1 <- lm(y ~ x1+x2+x3+x4+x5+, data=data)
> calc.relimp(m1, rela=TRUE)
> m2=boot.relimp(m1, boot = 500, rela=TRUE, type="lmg")
> booteval.relimp(m2)
> plot(booteval.relimp(m2))

In a new dataset with 3 measurement points (0,6,12 weeks), I want to
perform a similar analysis, and want overall relative importance estimates
over all 3 time points.

A standard mixed effects model would be adding time as fixed and subject as
random effect:

> m1 <- lmer(y ~ x1+x2+x3+x4+x5+time+(1| subject), data=data)
> m1.p = pvals.fnc(m1)

Unfortunately, that does not allow me to estimate relative importance
because relaimpo cannot handle LME4 output.
> Error in calc.relimp.default.intern(object =  "mer">,  :  If x is NULL, then object must be a data frame or a
> matrix.

Would it be possible to transform the LME4 output in a way that relaimpo
could read it? Do you have other ideas as to how to tackle this, e.g. other
ways of tackling the concept of relative importance / strength of the
regressors?

Thank you
EF

[[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] Regression Modeling Strategies 3-Day Short Course March 2013

2013-01-31 Thread Frank Harrell

*RMS Short Course 2013*
Frank E. Harrell, Jr., Ph.D., Professor and Chair
Department of Biostatistics, Vanderbilt University School of Medicine

*March 4, 5 & 6, 2013*
8:00am - 4:30pm
Student Life Center Board of Trust Room
Vanderbilt University
Nashville Tennessee USA

See http://biostat.mc.vanderbilt.edu/2013RMSShortCourse for details.

The course includes statistical methodology, case studies, and use of 
the R rms package.


Please email interest to Eve Anderson { eve.a.ander...@vanderbilt.edu }

--
Frank E Harrell Jr Professor and Chairman  School of Medicine
   Department of Biostatistics Vanderbilt University

__
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] obtainl survival curves for single strata

2013-01-31 Thread Bond, Stephen
Dear useRs,

What is the syntax to obtain survival curves for single strata on many subjects?

I have a model based on Surv(time,response) object, so there is a single row 
per subject and no start,stop and no switching of strata.

The newdata has many subjects and each subject has a strata and the survival 
based on the subject risk and the subject strata is needed.

If I do

newpred <- survfit(cph.approve,new=newapp,se=F)

I get all strata for every subject.

Attempting

> newpred <- survfit(cph.approve,new=newapp,id=CertId,se=F)
Error in survfit.coxph(cph.approve, new = newapp, id = CertId, se = F) : 
  The individual option is  only valid for start-stop data
> newpred <- survfit(cph.approve,new=newapp,indi=T,se=F)
Error in survfit.coxph(cph.approve, new = newapp, indi = T, se = F) : 
  The individual option is  only valid for start-stop data

Please, advise if obtaining a single strata for a basic (time,response) model 
is possible? Due to differing lengths of the surv for different strata this 
will not go in a "wide" data.frame without padding.

Thanks everybody and have a great day.

Stephen B

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

2013-01-31 Thread Ivan Calandra

Thanks Bert for your example.
I wouldn't say that I understand why everything happens the way it does, 
but at least I now know what happens!

I think I now need to use it and try around!

Ivan

--
Ivan CALANDRA
Université de Bourgogne
UMR CNRS/uB 6282 Biogéosciences
6 Boulevard Gabriel
21000 Dijon, FRANCE
+33(0)3.80.39.63.06
ivan.calan...@u-bourgogne.fr
http://biogeosciences.u-bourgogne.fr/calandra

Le 30/01/13 18:44, Bert Gunter a écrit :

Because R can be interactive, I find that a little exploring through
the use of strategically placed browser() calls (?browser if you are
unfamiliar with this handy debugging tool) is often the fastest way to
solve little R puzzles like this.

For example, try this (in an R GUI):

f2 <- function(y,...){ browser(); list(...) }
f1 <- function(x,...){ browser(); f2(x,...) }

Now at the command line:


f1( x=1, z= 2:4)

## In the f1 browser  do ls() to see what's in the f1 environment
## and then do list(...) to see what's in the dots argument
## then issue the browser command  c  to continue
## and do the same in the f2 browser .

## then try:

f1( x=1, y= 2:4)  ## and
f1( 2:4)
f1( y=2:4) ## this will produce an error in f2

I think this help give you a better idea of what's going on (or
totally confuse?!).

-- Bert




On Wed, Jan 30, 2013 at 8:15 AM, Patrick Burns  wrote:

There is now a blog post that attempts to
answer the question in the subject line:

http://www.burns-stat.com/the-three-dots-construct-in-r/

Pat

On 17/01/2013 14:36, Ivan Calandra wrote:

Dear users,

I'm trying to learn how to use the "...".

I have written a function (simplified here) that uses doBy::summaryBy():
# 'dat' is a data.frame from which the aggregation is computed
# 'vec_cat' is a integer vector defining which columns of the data.frame
should be use on the right side of the formula
# 'stat_fun' is the function that will be run to aggregate
stat.group <- function(dat, vec_cat, stat_fun){
  require(doBy)
  df <-

summaryBy(as.formula(paste0(".~",paste0(names(dat)[vec_cat],collapse="+"))),
data=dat, FUN=stat_fun)
  return(df)
}

Example, works fine:
my_data <- structure(list(cat = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L), .Label = c("A", "B"), class = "factor"), varnum =
c(-0.754816565434373,
-1.94101630973709, -0.102461836059522, -0.519952759645808,
-1.73772800855664,
-1.13939178585609, 0.522356715260142, -0.701428514907824,
1.45197576541159,
0.0844567413828095)), .Names = c("cat", "varnum"), row.names = c(NA,
-10L), class = "data.frame")
stat.group(dat=my_data, vec_cat=1, stat_fun=mean)


Now summaryBy() has an "..." argument and I would like to use it.
For example, I would like to be able to add the trim argument to my call
like this:
stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2)


I know I can do it using this "..." but I have no idea how to do it.
I've tried to search for it, but a search with "..." doesn't yield
interesting results!


Thank you in advance for your help!
Ivan


--
Patrick Burns
pbu...@pburns.seanet.com
twitter: @burnsstat @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of:
  'Impatient R'
  'The R Inferno'
  'Tao Te Programming')

__
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] Locate Patients who have multiple high blood pressure readings

2013-01-31 Thread Weijia Wang
On Thu, Jan 31, 2013 at 10:29 AM, Weijia Wang  wrote:

> Hi,
>
>
>
> I have a new question about subsetting in R.
>
>
>
> Say we have this data frame:
>
>
>
> PT_ID Blood_Pressure OBS_TYPE
>
> 92   1900  90.0  DBP
>
> 94   1900  90.0  DBP
>
> 174  2900 140.0  SBP
>
> 176  2900 130.0  SBP
>
> 180  3900 120.0  SBP
>
> 268  3900 150.0  SBP
>
> 268  3900  90.0  DBP
>
>
>
> I need to obtain those with 2+ DBP>=90 or 2+ SBP>=140.
>
>
>
> PT_ID=1900, he has 2 DBP>=90, so he will be included.
>
> PT_ID=2900, he has 1 SBP>=140, so he will NOT be included.
>
> PT_ID=3900, he has 1 SBP>=140 and 1 DBP>=90, so he will still NOT be
> included.
>
>
>
> So, the condition requires TWO OR MORE values higher than the threshold.
> It could be either SBP or DBP or both of them.
>
>
>
> I have tried ddply, but I don’t know how to add the condition 2+ inside
> ddply.
>
>
>
> Any help is appreciated!!
>
>
>
> Weijia
>
>
>

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

2013-01-31 Thread Ivan Calandra

Dear Patrick,

This is indeed a nice post to address the three dot issues.
It is definitely much clearer to me now

Thanks!
Ivan

--
Ivan CALANDRA
Université de Bourgogne
UMR CNRS/uB 6282 Biogéosciences
6 Boulevard Gabriel
21000 Dijon, FRANCE
+33(0)3.80.39.63.06
ivan.calan...@u-bourgogne.fr
http://biogeosciences.u-bourgogne.fr/calandra

Le 30/01/13 17:15, Patrick Burns a écrit :

There is now a blog post that attempts to
answer the question in the subject line:

http://www.burns-stat.com/the-three-dots-construct-in-r/

Pat

On 17/01/2013 14:36, Ivan Calandra wrote:

Dear users,

I'm trying to learn how to use the "...".

I have written a function (simplified here) that uses doBy::summaryBy():
# 'dat' is a data.frame from which the aggregation is computed
# 'vec_cat' is a integer vector defining which columns of the data.frame
should be use on the right side of the formula
# 'stat_fun' is the function that will be run to aggregate
stat.group <- function(dat, vec_cat, stat_fun){
 require(doBy)
 df <-
summaryBy(as.formula(paste0(".~",paste0(names(dat)[vec_cat],collapse="+"))), 


data=dat, FUN=stat_fun)
 return(df)
}

Example, works fine:
my_data <- structure(list(cat = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L), .Label = c("A", "B"), class = "factor"), varnum =
c(-0.754816565434373,
-1.94101630973709, -0.102461836059522, -0.519952759645808,
-1.73772800855664,
-1.13939178585609, 0.522356715260142, -0.701428514907824, 
1.45197576541159,

0.0844567413828095)), .Names = c("cat", "varnum"), row.names = c(NA,
-10L), class = "data.frame")
stat.group(dat=my_data, vec_cat=1, stat_fun=mean)


Now summaryBy() has an "..." argument and I would like to use it.
For example, I would like to be able to add the trim argument to my call
like this:
stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2)


I know I can do it using this "..." but I have no idea how to do it.
I've tried to search for it, but a search with "..." doesn't yield
interesting results!


Thank you in advance for your help!
Ivan





__
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 multiple barplots

2013-01-31 Thread Simon Kiss
Hello: I need to create a six barplots from data that looks pretty close to 
what appears below. There are two grouping variables (age and gender) and three 
dependent variables for each grouping variables.  I'm not really familiar with 
trellis graphics, perhaps there is something that can do what I need there, i 
don't know.  
The thing is: I *need* these to appear on one row, with some way of 
differentiating between the three barplots of one grouping variable and the 
three from the other grouping variable.  It's for a grant application and space 
is at a premium.  The width of everything can be about 7 inches wide and the 
height maybe 2 to 2.5 inches. I also need an outer margin to place a legend.  I 
can do this with the following using the layout command, but I cannot figure 
out a nice way to differentiate the two groups of variables.  I'd like to find 
a way to put a little bit of space between the three from one grouping variable 
and the three from another grouping variable.  

If anyone has any thoughts, I'd be very grateful. Yours truly, Simon J. Kiss

###Random Data
crime<-sample(c('agree' ,'disagree'), replace=TRUE, size=100)
guns<-sample(c('agree','disagree'), replace=TRUE, size=100)
climate<-sample(c('agree', 'disagree'), replace=TRUE, size=100)
gender<-sample(c('male','both' ,'female'), replace=TRUE, size=100)
age<-sample(c('old', 'neither', 'young'), replace=TRUE, size=100)
dat<-as.data.frame(cbind(crime, guns, climate, gender, age))
###Code I'm working with now
layout(matrix(c(1,2,3,4,5,6), c(1,6)))
barplot(prop.table(table(dat$guns, dat$gender), 2))
barplot(prop.table(table(dat$crime, dat$gender), 2))
barplot(prop.table(table(dat$climate, dat$gender), 2))
barplot(prop.table(table(dat$guns, dat$gender), 2))
barplot(prop.table(table(dat$crime, dat$age), 2))
barplot(prop.table(table(dat$climate, dat$age), 2))

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


Re: [R] Modify objects in function

2013-01-31 Thread Gabor Grothendieck
On Thu, Jan 31, 2013 at 6:52 AM, Simon Zehnder  wrote:
> Dear R community,
>
> I do know, that an R function is constructing a copy of any object passed as 
> argument into a function. I program on a larger S4 project for a package, and 
> I arrived at a point where I have to think a little harder on implementation 
> style (especially to spare users complex object handling).
>
> I have a function foo(), taking as input arguments two S4 objects of 
> different class type
>
> foo <- function(o1, o2) {
> o1@att1 <- producesomething()
> o2@att2 <- producesomethingelse()
>
> }
>
> Of course, this functions does not change the objects in the global 
> environment. Now I have two choices
>
> 1. Change the objects and return a list with both objects:
>
> foo <- function(o1, o2) {
> o1@att1 <- producesomething()
> o2@att2 <- producesomethingelse()
>
> l <- list(O1 = o1, O2 = o2)
> return(l)
> }
>
> This is cumbersome for users, as they have then to assign the objects inside 
> the returned list to the symbols used in the global environment. But it is 
> the way intended by R.
>
> 2. Change the objects of the global environment inside the function:
>
> foo <- function(o1, o2) {
> o1@att1 <- producesomething()
> o2@att2 <- producesomethingelse()
>
> assign("o1", o1, .GlobalEnv)
> assign("o2", o2, .GlobalEnv)
> }
>
> This is for users very practical, as the symbols used before refer now to 
> objects with changed attributes and can be used immediately. BUT: It is not 
> intended to be done like this.
>
> I spared any solution using one function for every single object type, as 
> this becomes even more cumbersome than choice 1 above, in my opinion.
>
> What is your opinion on the trade-off between user-friendly handling of 
> objects and R-intended programming style? Do I miss another choice, combining 
> both?
>
>

Another possibility is to create an environment component in your S4
class since those can be passed around as references:

OO <- setClass("OO", representation(env = "environment"))

setMethod("initialize", "OO", function(.Object) {
.Object@env <- new.env()
.Object
})

setMethod("show", "OO", function(object) show(object@env$a))

o1 <- OO()
o1@env$a <- 1

o2 <- OO()
o2@env$a <- 2

o1 # 1
o2 # 2

swap <- function(o1, o2) {
   tmp <- o1@env$a
   o1@env$a <- o2@env$a
   o2@env$a <- tmp
}

swap(o1, o2)
o1 # 2
o2 # 1

or if its feasible for you to change class systems Reference Classes
already use environments:

R <- setRefClass("R", fields = "a",
methods = list(
   swap = function(o2) {
  tmp <- o2$a
  o2$a <- a
  a <<- tmp
   },
   show = function() methods::show(a)
)
)
r1 <- R$new(a = 1)
r2 <- R$new(a = 2)

r1 # 1
r2 # 2
r1$swap(r2)

r1 # 2
r2 # 1

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] Modify objects in function

2013-01-31 Thread Barry Rowlingson
On Thu, Jan 31, 2013 at 3:00 PM, Simon Zehnder  wrote:
> Hi Barry,
>
> this actually a good idea, to put them together! Probably even creating an 
> object containing both of them. Haven't thought about it before.
>

 Hadley W asked for implementations of 'unstructuring assignments' the
other day, and I bashed this out to a gist:

https://gist.github.com/4543212

 it lets you do:

 (a~b~c) = foo()

and if foo() returns a list with three components it assigns them to
a, b, and c. Equivalent to:

tmp = foo()
a=tmp[[1]]
b=tmp[[2]]
c=tmp[[3]]

whether its any use to your use case or even works properly under all
circumstances or even just serves to obfuscate things is a point for
discussion...

Barry

__
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 objects in function

2013-01-31 Thread Barry Rowlingson
>  it lets you do:
>
>  (a~b~c) = foo()

Mistook. should be:

(a~b~c) %=% foo()

 because it defines the %=% operator.

Barry

__
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 objects in function

2013-01-31 Thread Barry Rowlingson
On Thu, Jan 31, 2013 at 11:52 AM, Simon Zehnder  wrote:
> Dear R community,
>
> I do know, that an R function is constructing a copy of any object passed as 
> argument into a function. I program on a larger S4 project for a package, and 
> I arrived at a point where I have to think a little harder on implementation 
> style (especially to spare users complex object handling).
>
> I have a function foo(), taking as input arguments two S4 objects of 
> different class type
>
> foo <- function(o1, o2) {
> o1@att1 <- producesomething()
> o2@att2 <- producesomethingelse()
>
> }
>
> Of course, this functions does not change the objects in the global 
> environment. Now I have two choices
>
> 1. Change the objects and return a list with both objects:
>
> foo <- function(o1, o2) {
> o1@att1 <- producesomething()
> o2@att2 <- producesomethingelse()
>
> l <- list(O1 = o1, O2 = o2)
> return(l)
> }
>
> This is cumbersome for users, as they have then to assign the objects inside 
> the returned list to the symbols used in the global environment. But it is 
> the way intended by R.

By cumbersome you mean the following (anti-?) pattern has to be used,
for example in a loop:

 o1 = something()
 o2 = somethingelse()
 o12 = foo(o1,o2)
 o1 = o12$o1
 o2 = o12$o2

so that at the end of it you have a modified o1 and o2?

 I suggest that if you have a function that modifies more than one of
its arguments, then there is a strong case for making those arguments
a single argument. So that you'd do:

 foo = function(o12){
o12$o1@att=bar()
o12$o2@att=baz()
return(o12)
  }

 o12 = list(something(), somethingelse())
 o12 = foo(o12)

and there you are, a modified o12 object. no packing/unpacking needed.

 I suspect that either your o1 and o2 are so closely related that you
should pack them in a list (or ideally, an object) or differently
related such that you should treat them separately and not tweak both
of them within the same function. That approach is binding behaviour
very tightly to two structures, and probably won't give you very
debuggable modular code.


B

__
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] Setting inline hook to a function identical to default in knitr turns of exponential formatting

2013-01-31 Thread mlell08
OK, i' look at this. 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.


Re: [R] Relative Risk in logistic regression

2013-01-31 Thread Frank Harrell
I am curious why one would want risk ratios.  Unlike odds ratios, they are
not interpretable without reference to the base risk.  For example a risk
ratio of 2 cannot possibly apply to anyone with a starting risk exceeding
1/2.

I think it is most helpful to use one of the existing nomograms to show
someone how the base risk and odds ratio translate to final risk, for a
range of base risk.

Frank

David Winsemius wrote
> On Jan 30, 2013, at 5:49 AM, aminreza Aamini wrote:
> 
>> Hi all,
>> I am very grateful to all those who write to me
>> 1) how i  can  obtain relative risk (risk ratio) in logistic  
>> regression in R.
>> 2) how to obtain  the predicted risk for a certain individual using
>> fitted regression model in R.
> 
> You obtain the predicted probabilities with something like:
> 
> predict(model, data.frame(x1="a", x2=30), type = "response")
> 
> See ?predict.glm
> 
> This would give the odds ratios (similar but larger than the risk  
> ratios):
> 
> exp(coef(model))
> 
> -- 
> David Winsemius, MD
> Alameda, CA, USA
> 
> __

> R-help@

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





-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/Relative-Risk-in-logistic-regression-tp4657040p4657163.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] Modify objects in function

2013-01-31 Thread Simon Zehnder
Dear R community,

I do know, that an R function is constructing a copy of any object passed as 
argument into a function. I program on a larger S4 project for a package, and I 
arrived at a point where I have to think a little harder on implementation 
style (especially to spare users complex object handling). 

I have a function foo(), taking as input arguments two S4 objects of different 
class type

foo <- function(o1, o2) {
o1@att1 <- producesomething()
o2@att2 <- producesomethingelse()
 
}

Of course, this functions does not change the objects in the global 
environment. Now I have two choices 

1. Change the objects and return a list with both objects:

foo <- function(o1, o2) {
o1@att1 <- producesomething()
o2@att2 <- producesomethingelse()

l <- list(O1 = o1, O2 = o2)
return(l)
}

This is cumbersome for users, as they have then to assign the objects inside 
the returned list to the symbols used in the global environment. But it is the 
way intended by R.

2. Change the objects of the global environment inside the function:

foo <- function(o1, o2) {
o1@att1 <- producesomething()
o2@att2 <- producesomethingelse()

assign("o1", o1, .GlobalEnv)
assign("o2", o2, .GlobalEnv)
}

This is for users very practical, as the symbols used before refer now to 
objects with changed attributes and can be used immediately. BUT: It is not 
intended to be done like this.

I spared any solution using one function for every single object type, as this 
becomes even more cumbersome than choice 1 above, in my opinion.

What is your opinion on the trade-off between user-friendly handling of objects 
and R-intended programming style? Do I miss another choice, combining both?


Best 
Simon
__
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 eigen() for extracting only few major eigenpairs

2013-01-31 Thread Mark Leeds
hi: the irlba package does what you're looking for.


On Thu, Jan 31, 2013 at 3:32 AM, Pierrick Bruneau wrote:

> Hi everyone,
>
> I am using eigen() to extract the 2 major eigenpairs from a large real
> square symmetric matrix. The procedure is already rather efficient, but
> becomes somehow slow for real time needs with moderately large matrices
> (few thousand lines).
>
> The R implementation statically extracts all eigenvalues (and optionally
> associated eigenvectors). I heard about optimizations of the eigen
> decomposition when only few eigenpairs are needed : did somebody already
> care about this problem (through a contributed package for example) ? Or do
> I have to directly try to mess around with the LAPACK library (and
> contribute the package myself afterwards) ?
>
> Thanks by advance for your help,
> Pierrick Bruneau
> CRP Gabriel Lippmann
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Please, problem using bcPower

2013-01-31 Thread John Fox
Dear Beatriz,

There are several problems that combine to make the computation unstable: the 
small size of the numbers, the small ratio of the largest to the smallest 
value, the extreme negative skew of the data, and the outliers at the low end. 
Because of the small ratio of max(x) to min(x), power transformations are 
ineffective and an extreme power is required:

> max(x)/min(x)
[1] 1.129898

> powerTransform(1e7*x)
Estimated transformation parameters 
1e+07 * x 
 31.77628 

You can use a negative start to produce a more sensible result:

> powerTransform(1e7*(x - .99*(min(x
Estimated transformation parameters 
1e+07 * (x - 0.99 * (min(x))) 
 2.774309 

I was slightly surprised that the magnitude of the numbers is an issue.

I hope this helps,
 John


John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

On Thu, 31 Jan 2013 00:38:23 -0500
 Beatriz González  wrote:
> Hello,
> 
> I would like to perform a Box-Cox (“bcPowerâ€?) transformation on my data. 
> For this, I am determining lambda using the “powerTransformâ€? function. 
> However, with one of my variables I get the following 
> 
> Warning Message:
> In estimateTransform(x, y, NULL, ...) :
>   Convergence failure: return code = 52 My variable is: 
> > x
>  [1] 0.0001031130 0.0001029480 0.0001040010 0.0001037940 0.0001046280 
> 0.927650 0.942960
>  [8] 0.950250 0.949780 0.988210 0.975860 0.962850 
> 0.0001015800 0.0001009190
> [15] 0.0001035350 0.0001033210 0.0001028420 0.0001023150 0.0001033000 
> 0.0001036910 0.0001026890
> [22] 0.0001032480 0.0001012160 0.0001031270 0.0001034390 0.0001028180 
> 0.0001034820 0.0001022700
> [29] 0.0001042640 0.0001046720 0.0001045860 0.0001045160 0.0001045850 
> 0.0001038040 0.0001037020
> [36] 0.0001034050 0.0001048150 0.0001017180 0.0001017920 0.0001032730 
> 0.0001029420 0.0001025220
> [43] 0.0001031490 0.0001036995 0.0001039735 0.0001014877 0.0001027960 And my 
> code is:dlambda <- powerTransform(x) #It is here where I get the warning 
> message
> x_BCx <- bcPower(x, lambda= dlambda$lambda, jacobian.adjusted= FALSE)
>  Does anyone know why I may be getting this Warning Message?  If you require 
> more details please get in touch.
> 
> Many thanks in advance!
> 
> Bea
>   [[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] Package name

2013-01-31 Thread Duncan Murdoch

On 13-01-31 1:26 AM, Ortiz, John wrote:


Dear list,

Can I use a character to set the name of a R package? like this (-)

for example (sdp-R)


I can't quite parse your question, but I think the answer is in the 
Writing R Extensions manual, section 1.1 "Package Structure".


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] Package name

2013-01-31 Thread Marcio Pupin Mello

I'm not sure, but would recommend not to.
--
Marcio
www.dsr.inpe.br/~mello


On 31/01/2013 04:26, Ortiz, John wrote:


Dear list,

Can I use a character to set the name of a R package? like this (-)

for example (sdp-R)

Thanks,

John



__
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] lower corner cumulative probability

2013-01-31 Thread Jose Iparraguirre
Have you looked in the package 'copula'?
Regards,
José

José Iparraguirre
Chief Economist
Age UK



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of eliza botto
Sent: 31 January 2013 11:13
To: r-help@r-project.org
Subject: [R] lower corner cumulative probability


Dear useRs,
With the following set of command i managed to create the copula density


 >library(MASS) >library(evd) >X<-matrix(sample(1:3000), ncol=2) 
 >>U=cbind(rank(X[,1])/(nrow(X)+1),rank(X[,2])/(nrow(X)+1))
> mat1=kde2d(U[,1],U[,2],n=150) image(mat1$x,mat1$y,mat1$z,col=
 rev(heat.colors(1500)),xlab="",ylab="")
 contour(mat1$x,mat1$y,mat1$z,add=
 TRUE,levels = pretty(c(0,4), 11))
=
Is there a way we can find the cumulative probability of lower corner of copula 
density???
i know a manual a manual way of doing it, but its taking too long...
thanks in advance
Eliza
  
[[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.

Wrap Up and Run 10k is back! 

Also, new for 2013 – 2km intergenerational walks at selected venues. So recruit 
a buddy, dust off the trainers and beat the winter blues by 
signing up now:

http://www.ageuk.org.uk/10k

 Milton Keynes | Oxford | Sheffield | Crystal Palace | Exeter | 
Harewood House, Leeds | 
 Tatton Park, Cheshire | Southampton | Coventry



Age UK Improving later life

http://www.ageuk.org.uk


 

---
Age UK is a registered charity and company limited by guarantee, (registered 
charity number 1128267, registered company number 6825798). 
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

For the purposes of promoting Age UK Insurance, Age UK is an Appointed 
Representative of Age UK Enterprises Limited, Age UK is an Introducer 
Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth 
Access for the purposes of introducing potential annuity and health 
cash plans customers respectively.  Age UK Enterprises Limited, JLT Benefit 
Solutions Limited and Simplyhealth Access are all authorised and 
regulated by the Financial Services Authority. 
--

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are 
addressed. If you receive a message in error, please advise the sender and 
delete immediately.

Except where this email is sent in the usual course of our business, any 
opinions expressed in this email are those of the author and do not 
necessarily reflect the opinions of Age UK or its subsidiaries and associated 
companies. Age UK monitors all e-mail transmissions passing 
through its network and may block or modify mails which are deemed to be 
unsuitable.

Age Concern England (charity number 261794) and Help the Aged (charity number 
272786) and their trading and other associated companies merged 
on 1st April 2009.  Together they have formed the Age UK Group, dedicated to 
improving the lives of people in later life.  The three national 
Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help 
the Aged in these nations to form three registered charities: 
Age Scotland, Age NI, Age Cymru.










__
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] XBRL data into R?

2013-01-31 Thread Ista Zahn
Hi Anika,

Have you looked at or tried the XML package? I've not used it for XBRL
in particular, but have used it very successfully to parse other kinds
of xml data.

Best,
Ista

On Wed, Jan 30, 2013 at 7:19 PM, Anika Masters  wrote:
> Has anyone explored pulling XBRL formatted data into R?
>
> [[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.


[R] lower corner cumulative probability

2013-01-31 Thread eliza botto

Dear useRs,
With the following set of command i managed to create the copula density


 >library(MASS) >library(evd) >X<-matrix(sample(1:3000), ncol=2) 
 >>U=cbind(rank(X[,1])/(nrow(X)+1),rank(X[,2])/(nrow(X)+1))
> mat1=kde2d(U[,1],U[,2],n=150) image(mat1$x,mat1$y,mat1$z,col=
 rev(heat.colors(1500)),xlab="",ylab="")
 contour(mat1$x,mat1$y,mat1$z,add=
 TRUE,levels = pretty(c(0,4), 11))
=
Is there a way we can find the cumulative probability of lower corner of copula 
density???
i know a manual a manual way of doing it, but its taking too long...
thanks in advance
Eliza
  
[[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] facet plot

2013-01-31 Thread Jose Iparraguirre
Hi Robin,

You didn't provide the list with a clear structure of your data, but I hope I 
understood it properly. If not, it'd be easy for you to adapt what follows.

I guess your data looks like this:

   Gene  T0h T0.25h T0.5h  T1h  T2h  T3h  T6h T12h T24h T48h
1  NM_001001130   68 9556   43   66   62   68   90   63   89
2  NM_0010011440  1 40111412
3  NM_001001152   7912952   50   24   45  130  154  112  147
4  NM_0010011601  1 20010001
5  NM_0010011760  0 00000000
...

If this is the case, first reshape your data (say, gene.df) to a long format:

Gene Time
1   NM_001001130   68
2   NM_0010011440
3   NM_001001152   79
4   NM_0010011601
5   NM_0010011760
6   NM_0010011771
7   NM_0010011780
8   NM_0010011790
9   NM_001001182 4691
...

Then, you create the ggplot:

> sp <- ggplot(gene.df, aes(x=Gene, y=Time)) + geom_point(shape=1)

And use the function facet_wrap():

> sp + facet_wrap( ~ Gene,ncol=3)

You can set a different number of columns and a different shape for the 
markers, of course.

Hope this helps.

Regards,

José


José Iparraguirre
Chief Economist
Age UK


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Robin Mjelle
Sent: 31 January 2013 09:06
To: r-help@r-project.org
Subject: [R] facet plot

Hi all,

I want to plot a facet plot with column names as x and column values as y.
One plot for each row. here is part of my dataset:

Gene T0h T0.25h T0.5h T1h T2h T3h T6h T12h T24h T48h  NM_001001130 68 95
56 43 66 62 68 90 63 89  NM_001001144 0 1 4 0 1 1 1 4 1 2  NM_001001152 79
129 52 50 24 45 130 154 112 147  NM_001001160 1 1 2 0 0 1 0 0 0 1
NM_001001176 0 0 0 0 0 0 0 0 0 0  NM_001001177 1 3 2 3 0 1 1 0 2 0
NM_001001178 0 0 0 0 0 0 0 0 0 0  NM_001001179 0 0 0 0 0 0 0 0 0 0
NM_001001180 1 0 0 1 0 0 0 0 0 0  NM_001001181 350 539 424 470 441 451 554
553 419 548  NM_001001182 4691 6458 5686 6761 5944 4486 6030 5883 6009 7552
NM_001001183 22 23 12 21 25 17 34 40 33 32  NM_001001184 138 147 111 100 54
61 61 77 57 99  NM_001001185 2 3 4 3 4 5 9 2 4 4  NM_001001186 231 337 187
168 148 178 275 319 181 279

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

Wrap Up and Run 10k is back! 

Also, new for 2013 – 2km intergenerational walks at selected venues. So recruit 
a buddy, dust off the trainers and beat the winter blues by 
signing up now:

http://www.ageuk.org.uk/10k

 Milton Keynes | Oxford | Sheffield | Crystal Palace | Exeter | 
Harewood House, Leeds | 
 Tatton Park, Cheshire | Southampton | Coventry



Age UK Improving later life

http://www.ageuk.org.uk


 

---
Age UK is a registered charity and company limited by guarantee, (registered 
charity number 1128267, registered company number 6825798). 
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

For the purposes of promoting Age UK Insurance, Age UK is an Appointed 
Representative of Age UK Enterprises Limited, Age UK is an Introducer 
Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth 
Access for the purposes of introducing potential annuity and health 
cash plans customers respectively.  Age UK Enterprises Limited, JLT Benefit 
Solutions Limited and Simplyhealth Access are all authorised and 
regulated by the Financial Services Authority. 
--

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are 
addressed. If you receive a message in error, please advise the sender and 
delete immediately.

Except where this email is sent in the usual course of our business, any 
opinions expressed in this email are those of the author and do not 
necessarily reflect the opinions of Age UK or its subsidiaries and associated 
companies. Age UK monitors all e-mail transmissions passing 
through its network and may block or modify mails which are deemed to be 
unsuitable.

Age Concern England (charity number 261794) and Help the Aged (charity number 
272786) and their trading and other associated companies merged 
on 1st April 2009.  Together they have formed the Age UK Group, dedicated to 
improving the lives of people in later life.  The three national 
Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help 
the Aged in these nations to form three registered charities: 
Age Scotland, Age NI, Age Cymru.










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

Re: [R] converting XML document to table or dataframe

2013-01-31 Thread Franzini, Gabriele [Nervianoms]
Hello,

R is good at handling XML, but in this case I would rather do the first
step with an XSLT transformation, e.g. with Saxon, possibly to a CSV
file.

HTH,
Gabriele


-Original Message-
From: Anika Masters [mailto:anika.mast...@gmail.com] 
Sent: Tuesday, January 29, 2013 3:01 AM
To: r-help@r-project.org
Subject: [R] converting XML document to table or dataframe

I am a relatively new user to R, and I am trying to learn more about
converting data in an XML document into "2-dimensional format" such as a
table or array.  I might eventually wish to export this data into a
relational database such as SQL, and/or to work with this data within
the R package.

My sample XML document is located at "
http://www.sec.gov/Archives/edgar/data/743988/000124636013000561/form.xm
l"

I have successfully import the XML document and then converted the XML
document to a list.

I am "stuck" trying to convert the document into a "2-dimenional" table
or dataframe.

What is a "good" way to convert the XML document to a 2-dimensional
table or data.frame?  Ideally, I'd like a table with 1 row for each XML
document, and unique fieldnames.  If fieldnames repeat, I'd like the
names to be numbered sequentially

e.g.
$nonDerivativeTable$nonDerivativeTransaction$transactionAmounts$transact
ionPricePerShare$value_1
$nonDerivativeTable$nonDerivativeTransaction$transactionAmounts$transact
ionPricePerShare$value_2
$nonDerivativeTable$nonDerivativeTransaction$transactionAmounts$transact
ionPricePerShare$value_3

etc




myxml = xmlParse("
http://www.sec.gov/Archives/edgar/data/743988/000124636013000561/form.xm
l")
mylist <- xmlToList(mydoc)
mydf <- xmlToDataFrame(mydoc)
mydf2 <- data.frame(mylist)
mytable <- as.table(mylist)
mydf2 <- data.frame(mydoc)
mytable <- as.table(mydoc)

[[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] I want to download "garchOxFit" function.

2013-01-31 Thread amarjit chandhial
 
See
 
Dean
Fantazzini (2011) Fractionally Integrated Models for Volatility: A Review -
Empirical Appendix: Some Examples with R Interfaced with the Ox Package G@RCH, 
Moscow
School of Economics; National Research University Higher School of Economics
http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1752095

   


 From: 박소영 
To: R-HELP@r-project.org 
Sent: Thursday, 31 January 2013, 7:28
Subject: [R] I want to download "garchOxFit" function.
  
Dear R help.

Hello.

I want to fit the model of "FIGARCH" on TimeSeries data.
So I need to use the code of "garchOxFit".
I don't know how to estimate FIGARCH model.

Please let me know which package I need and 
what is procedure of estimating FIGARCH by R.

I think I need this code!


> garchOxFit(formula.mean = arma(0, 0), formula.var = garch(1,1), series
= x, cond.dist = c("gaussian", "t", "ged", "skewed-t"), include.mean =
TRUE, truncation = 100, trace = TRUE, title = NULL, description = NULL,
arch.in.mean=0, include.var=TRUE)

Thank you for reading email.
I am waiting for your kind reply.

Best,
Soyoung Park.


    [[alternative HTML version deleted]]

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

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


Re: [R] Percentages in bar plot

2013-01-31 Thread PIKAL Petr
Hi

or use prop.table

barplot(prop.table(table(stop)))

Regards
Petr



> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Rui Barradas
> Sent: Wednesday, January 30, 2013 4:01 PM
> To: Naser Jamil
> Cc: R help
> Subject: Re: [R] Percentages in bar plot
> 
> Hello,
> 
> Try
> 
> barplot(table(stop)/sum(table(stop)))
> 
> 
> Hope this helps,
> 
> Rui Barradas
> 
> Em 30-01-2013 11:34, Naser Jamil escreveu:
> > Dear R-users,
> > Though it's a silly thing to ask, but I'm not getting a way out. I
> > wish to find the percentage distribution for a data vector 'stop'.
> The
> > coomand below is giving the frequency distribution.  May I know the
> > option to see the percentages instead of frequencies.  Similarly,
> what
> > option I should put in a histogram plot to see the percentages
> instead of frequencies?
> >
> > -
> > stop<-c(8,6,6,6,8,6,6,8,8,6,6,6,8,8,8)
> > barplot(table(stop))
> >
> > 
> >
> > Many thanks for your time.
> >
> >
> > Regards,
> > Jamil.
> >
> > [[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.

__
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] Writing audio files (.wav) in a different directory

2013-01-31 Thread Prof Brian Ripley

On 31/01/2013 06:50, Jeff Newmiller wrote:

Put the directory name into the filename string. The syntax for doing that is somewhat OS dependent, but for most cases 
you can use "/" as the separator. You really should Google "file path" and your OS and learn how to 
do this, because it is broadly applicable outside of R (not an R-help question). Look for info on "absolute 
path" and "relative path".


Or see ?file.path in R, which is OS-independent.



---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

Humberto Mohr  wrote:


Hi.

I'm trying to export a .wav file using the writeWave function from
tuneR
package in a different folder than the default getwd().
After reading through the manuals of some audio packages I couldn't
figure
it out.

I'm picking one 3-hour .wav file and asking the function to take a
sample
of 1 minute (from minute 100 to minute 101 of the 3-hour file) and
saving
it in an object "rec".

Here is what I'm doing:

filename<-"QUm0B24x_SMS05_20100831_052100.wav"
min.ini<-100
min.fin<-101

library(tuneR)
rec<-readWave(filename,min.ini,min.fin,"minutes")
writeWave(rec,"cut1.wav")

It is writing the file in the same directory of the "filename" object.
What
I want to do is to write the "cut1.wav" file in a different folder.

Any suggestions?

Thanks in advance!


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




--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] fSeries not found in R

2013-01-31 Thread Prof Brian Ripley

On 30/01/2013 21:23, Yuan, Rebecca wrote:

Hello all,

When I tried to install fSeries in R, I got the following error messages:

install.packages("fSeries",dependencies=T)
Warning message:
package 'fSeries' is not available (for R version 2.15.2)

Is this package changing/merging to another package?


Yes, a long time ago.  See timeSeries.


Thanks,

Rebecca



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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

2013-01-31 Thread Robin Mjelle
Hi all,

I want to plot a facet plot with column names as x and column values as y.
One plot for each row. here is part of my dataset:

Gene T0h T0.25h T0.5h T1h T2h T3h T6h T12h T24h T48h  NM_001001130 68 95
56 43 66 62 68 90 63 89  NM_001001144 0 1 4 0 1 1 1 4 1 2  NM_001001152 79
129 52 50 24 45 130 154 112 147  NM_001001160 1 1 2 0 0 1 0 0 0 1
NM_001001176 0 0 0 0 0 0 0 0 0 0  NM_001001177 1 3 2 3 0 1 1 0 2 0
NM_001001178 0 0 0 0 0 0 0 0 0 0  NM_001001179 0 0 0 0 0 0 0 0 0 0
NM_001001180 1 0 0 1 0 0 0 0 0 0  NM_001001181 350 539 424 470 441 451 554
553 419 548  NM_001001182 4691 6458 5686 6761 5944 4486 6030 5883 6009 7552
NM_001001183 22 23 12 21 25 17 34 40 33 32  NM_001001184 138 147 111 100 54
61 61 77 57 99  NM_001001185 2 3 4 3 4 5 9 2 4 4  NM_001001186 231 337 187
168 148 178 275 319 181 279

[[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] I want to download "garchOxFit" function.

2013-01-31 Thread 박소영
Dear R help.
 
Hello.
 
I want to fit the model of "FIGARCH" on TimeSeries data.
So I need to use the code of "garchOxFit".
I don't know how to estimate FIGARCH model.
 
Please let me know which package I need and 
what is procedure of estimating FIGARCH by R.
 
I think I need this code!
 
 
> garchOxFit(formula.mean = arma(0, 0), formula.var = garch(1,1), series
= x, cond.dist = c("gaussian", "t", "ged", "skewed-t"), include.mean =
TRUE, truncation = 100, trace = TRUE, title = NULL, description = NULL,
arch.in.mean=0, include.var=TRUE)
 
Thank you for reading email.
I am waiting for your kind reply.
 
Best,
Soyoung Park.
 

[[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] Addressing results of modFit() of the FME package

2013-01-31 Thread Bachelor student
Hello,

I don´t manage to address the results I get from modFit(). Would be really
nice if you could help me to do so.

This is my loop:

for (i in 1:10) {

CO2 <- CO2.list[[i]]

#Beobachtungen

Obs <- data.frame("x=t"=numeric(),"y=Respi"=numeric())
Obs <- cbind(CO2[,1],CO2[,3])
colnames(Obs) <- c("x","y")

Corg.mg <- CO2$Corg.mg

Model<-function(p,x) return(data.frame(x=x,
y=(p[1]*p[2]*exp((-p[2])*x))+((Corg.mg-p[1])*p[3]*exp((-p[3]*x)
Residuals<-function(p)(Obs[,2]-Model(p, Obs[,1])$y)

print(system.time(P <- modFit(f=Residuals, p=c(300, 0.1, 0.002),
lower=c(0,0,0), upper=c(500, 5, 1
sP<-summary(P)
sP

}

#sP, gives me the following output. I can address the estimates with P$par
but I cannot address Std. Error and Pr(>t). That´s what I would like to do!

Parameters:
Estimate Std. Error t value Pr(>|t|)
[1,] 4.005e+00 2.510e+00 1.595 0.131469
[2,] 1.603e-01 9.442e-02 1.698 0.110100
[3,] 3.647e-04 8.581e-05 4.251 0.000698 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.2427 on 15 degrees of freedom

Parameter correlation:
[,1] [,2] [,3]
[1,] 1. -0.9164 -0.7697
[2,] -0.9164 1. 0.5599
[3,] -0.7697 0.5599 1.

Thanks in advance!!




--
View this message in context: 
http://r.789695.n4.nabble.com/Addressing-results-of-modFit-of-the-FME-package-tp4657140.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] Using eigen() for extracting only few major eigenpairs

2013-01-31 Thread Pierrick Bruneau
Hi everyone,

I am using eigen() to extract the 2 major eigenpairs from a large real
square symmetric matrix. The procedure is already rather efficient, but
becomes somehow slow for real time needs with moderately large matrices
(few thousand lines).

The R implementation statically extracts all eigenvalues (and optionally
associated eigenvectors). I heard about optimizations of the eigen
decomposition when only few eigenpairs are needed : did somebody already
care about this problem (through a contributed package for example) ? Or do
I have to directly try to mess around with the LAPACK library (and
contribute the package myself afterwards) ?

Thanks by advance for your help,
Pierrick Bruneau
CRP Gabriel Lippmann

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