Re: [R] User input(unknown name and number of files)

2011-07-23 Thread Bansal, Vikas
can you please suggest me any book or paper or website which explains this 
problem because I have started using R before 3 weeks only and i will not be 
able to understand your whole code.so if i will study about this problem it 
will be very good for me.I have tried in some books and also on internet but 
did not find anything related to this.I will be very thankful to you.


Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London

From: Joshua Wiley [jwiley.ps...@gmail.com]
Sent: Friday, July 22, 2011 9:48 PM
To: Bansal, Vikas
Cc: r-help@r-project.org
Subject: Re: [R] User input(unknown name and number of files)

On Fri, Jul 22, 2011 at 12:30 PM, Bansal, Vikas  wrote:
> Thanks for your reply.That is why I wrote in the message that I have sent 
> this message before but did not get any help (first line of my message).
> can you please tell me that if user will input 50 files or 100 how my code 
> will work.Do I need to write file1,file2 till file 100 in this code?

No, the user will have to write out all 100 of their file names.


## Inner function
reader <- function(x) {
  paste(letters[x], collapse = "")
}

## Outer function
outerfoo <- function(name) {
  int <- lapply(name, function(n) {
grep(strsplit(tolower(n), "")[[1]][1], letters)
  })

  stuff <- lapply(int, function(i) {
lapply(list(c(35, 47), c(38, 37, 31, 36, 42), c(31, 41),
c(42, 30, 23, 42), c(32, 43, 41, 42), c(24, 27, 25, 23, 43, 41, 27),
c(47, 37, 43), c(42, 37, 34, 26), c(35, 27), c(47, 37, 43),
c(45, 27, 40, 27), c(41, 38, 23, 35, 35, 31, 36, 29), c(35, 47),
c(35, 23, 31, 34, 24, 37, 46), c(26, 37, 27, 41), c(36, 37, 42),
c(35, 23, 33, 27), c(31, 42), c(37, 33, 23, 47)), `-`, i)})

  output <- lapply(stuff, function(x) {
paste(unlist(lapply(x, reader)), collapse = " ")
  })
  return(output)
}

## Example (here is what the user will write)
## My example function is designed to work with names
outerfoo(c("Joshua", "Wiley"))

>
> lapply(c("file1", "file2", etc.), yourfunction)
> 
> From: Joshua Wiley [jwiley.ps...@gmail.com]
> Sent: Friday, July 22, 2011 8:26 PM
> To: Bansal, Vikas
> Cc: r-help@r-project.org
> Subject: Re: [R] User input(unknown name and number of files)
>
> On Fri, Jul 22, 2011 at 12:15 PM, Bansal, Vikas  
> wrote:
>> Dear all,
>>
>> I need your help as I was not able to find out the solution.I sent this 
>> message before but did not get any help.Please help me.
>
> You only sent the message yesterday!!! (then again a few hours ago,
> and *again* just now)
>
> rather than hard code what you are doing, create a function that takes
> a data file and outputs the type of data you want.  Then just:
>
> lapply(c("file1", "file2", etc.), yourfunction)
>
> will create a list of all the output.
>
> Josh
>
>>
>> The thing is-
>> I am having a code which is reading file with this code-
>>
>> df=read.table("Case2.pileup",fill=T,sep="\t",colClasses="character")
>>  but as am making a tool so that user can use it and can do analysis on his 
>> file.But the name of the file will not be Case2.pileup and I want to use 
>> this code so that user can input as many files as he want.My code is like 
>> this-
>>
>> df=read.table("Case2.pileup",fill=T,sep="\t",colClasses="character")
>> df$V9 <-  apply(df, 1, function(x) 
>> gsub("\\:|\\$|\\^|!|\\-|1|2|3|4|5|6|7|8|10", "",x[9]))
>> df$V10 <- sapply(df$V10, function(a)
>>  paste(as.integer(charToRaw(a)), collapse = ' '))
>> capture.output(print.data.frame(df,row.names=F), file = "end.txt", append = 
>> FALSE)
>>
>> I know it should do it with for loop and an array.I want that if user input 
>> 12 files,the dataframe name df should be different for all the 12 files.
>>
>> Can you please tell me how can I do this.
>>
>>
>> Thanking you,
>> Warm Regards
>> Vikas Bansal
>> Msc Bioinformatics
>> Kings College London
>> __
>> 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.
>>
>
>
>
> --
> Joshua Wiley
> Ph.D. Student, Health Psychology
> University of California, Los Angeles
> https://joshuawiley.com/
>



--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.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] convert TS dataframe to evenly spaced intervals?

2011-07-23 Thread Derrick Lin
Hi R-help,

I have a dataframe consisting of a time-series [t, v]. The timestamps aren't
at all evenly spaced. The values are continuous. I've been able to graph
this as a step function (which is what it should be) in ggplot2, using the
'step' geom. Now I would like to take the integral of the step function.

For this and other reasons, is there a way to convert this into an evenly
time-interval-ed array?


example current dataframe:

t(currently as.POSIXct-ed) value
5/31/11 0:00  7.56
5/31/11 0:01  7.78
5/31/11 1:05  3.00
5/31/11 1:17  8.32


desired (something like this, anyway):
t  value
5/31/11 0:00 7.56
5/31/11 0:05 7.78
5/31/11 0:10 7.78
......
5/31/11 1:00 7.78
5/31/11 1:05 3.00
5/31/11 1:10 3.00
5/31/11 1:15 3.00
5/31/11 1:20 8.32

It could also be factors like: 0:00 - 0:05, 7.56. However I don't think my
grasp of this is very good. It'd also be great if the solution were general
purpose so that I can change the parameters as needed (like interval size).

I've been banging my head on #R and begun reading plyr/reshape
documentation, so I would really appreciate any help!

-Derrick

[[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] R on Multicore for Linux

2011-07-23 Thread Lei Jiang
Madana,

The code below may work (untested though):

#above is the same as you wrote
require(multicore)

read.data.exmple <- function(f)
{
   dat <- read.csv(f, header=FALSE, sep="\t", na.strings="",dec=".",
strip.white=TRUE, fill=TRUE)
   data_1 <- sqldf("SELECT V2, V14, MIN(V16) FROM dat WHERE V6=104 GROUP
BY
V2, V14")
   data_1
}

DF <- mclapply(a, read.data.example)

#you can check the components of DF by DF[[1]], DF[[2]] ..., which is a bit
different from rbind
#feel free to add more arguments to function read.data.example and add those
to mclapply accordingly

Hope this helps.

Regards,
Lei

On Fri, Jul 22, 2011 at 11:35 AM, Madana_Babu wrote:

> Hi,
>
> Can you please explain me that how can i perform this on a multicore
> processor? since i have a machine with 16-cores. I can do this much faster
> if i use all cores.
>
> Thanks in advance...
>
> Regards,
> Madana
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/R-on-Multicore-for-Linux-tp3682318p3687483.html
> Sent from the R help mailing list archive at Nabble.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.
>



-- 
Lei Jiang

Center for Computation and Technology/
Department of Computer Science
Louisiana State University

E-mail: lji...@cct.lsu.edu

[[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] elimination duplicate elements sampling!

2011-07-23 Thread elephann
Great! The second way really helped me! Thank you so much!

--
View this message in context: 
http://r.789695.n4.nabble.com/elimination-duplicate-elements-sampling-tp3652791p3687613.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] Picking returns from particular days of the month from a zoo object

2011-07-23 Thread john nicholas

 Hello,

I would like to implement a "turn-of-the-month' trading strategy in R.

Given a daily series of stock market return data as a zoo object, the strategy 
would go long (buy) four trading days before the end of the month, and sell the 
third trading day of the following month.

How can I select these days, particularly the fourth day before and the third 
day after the turn of the month, from a zoo object?

Thanks in advance,



John B. Nicholas, Ph.D
650-315-9895

[[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] summarized data set - how to use an "occurs" field

2011-07-23 Thread mloxton


David, thanks, I think that should work perfectly
Much obliged

>
>  > dfrm <- expand.grid(A=1:3, B=1:3)
>  > dfrm$counts <- 1:9
>  > xtabs(counts~A, data=dfrm)
> A
>   1  2  3
> 12 15 18
>
>  >barplot(xtabs(counts~A, data=dfrm), xlab="Counts by A level")
>
> --
>
> David Winsemius, MD
> West Hartford, CT
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://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] averaging rows based on string¿?

2011-07-23 Thread alfredo
Hi Folks,

Ran into something I'd really like to do in R simply/elegantly, but my R -
coding skills seem surpassed. This is the thing. Imagine the following data:

labs<-c("abcdef","abcgg","tgthefdk","tgtijuel","tgtnjmoi","gbnt","dlift")
dat<-c(0.5,0.25,1,2,16,0.250,4)
dframe<-data.frame(labs,dat)

I would like to average the values in "dat" according to specific
string/text in the name of their row names described by "labs". For example,
average the values in "dat" if the first three (or more) letters in their
corresponding "labs" are the same. This would give the following vector:

0.375000 6.33 0.25 4.00 # in which 0.375 is the average of
"abcdef" and "abcgg", etc.

I hope I've made myself (kind'a) clear and apologise otherwise. Any ideas?

Thanks for your help! 

A

--
View this message in context: 
http://r.789695.n4.nabble.com/averaging-rows-based-on-string-tp3687689p3687689.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] matched pairs

2011-07-23 Thread Ellen S.
Thanks everyone! I finally got some code to work (thanks to William Dunlap).

--
View this message in context: 
http://r.789695.n4.nabble.com/matched-pairs-tp3687506p3687864.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] Plotting compound functions--help with defining x-axis as f(x)

2011-07-23 Thread Aimee Jones
Hi all,
I'm having trouble locating a script that will allow to me to create graphs
that show compound functions as a function of the simple function, rather
than just x (or time as it is in my case).

Currently I have the following functions defined in my script:

>
>
> T1<-function(t) {27.5-12.5*cos(2*pi*t/365)**}
> and
>
> B1<-function(T1,t) {dnorm(T1(t),mean=22.5,sd=**3.3)}
>



plot(function(t) {B1(T1,t)}, 0, 365) plots B1 as a function of time, whereas
I am looking for a code that allows me to plot B1 as a function of T1. I
tried plot(function(T1(t) {B1(T1,t)}, 0, 365) and also plot(function(T1,t)
{B1(T1,t)}, 0, 365), neither of which worked. My coding skills are very
limited, and I'm somewhat out of ideas..


Thank you for any assistance you are able to give,
yours sincerely,
Aimee

ps: If it's relevant I'm using R64 (R 2.11.1) on a Mac

[[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] library 'ts' not available?

2011-07-23 Thread cplusplus programmer
hi,
When I type library(ts) (I am working on an ubuntu machine), I get the
following error:

> library(ts)
Error in library(ts) : there is no package called 'ts'

I did a few google searches and it seems like ts is no longer
availableis that correct?
It seemed to me that I would need to download Rmetrics insteadis that
the replacement for ts.

Please let me know how I can get access to the ts libraries

thanks!

[[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] Lattice: place ticks only on y-axis

2011-07-23 Thread marcel
Working! Many thanks, good solutions


--
View this message in context: 
http://r.789695.n4.nabble.com/Lattice-place-ticks-only-on-y-axis-tp3684094p3688167.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] help on panel.superpose

2011-07-23 Thread Bharath Kumar
Dear users,

I am new to R and have couple of problems with xyplot.

A) I am trying to use the xyplot to plot mean concentration vs time across 5
dose groups.

When i use the following script
xyplot(mean~time,groups=dose,type="b",panel=panel.superpose). R generates
the plot, but i have no control over pch or color for the line. It displays
whatever color and pch it wants to generate. How do i fix this. 

B) I am trying to use the same function to plot individual data across dose
groups

xyplot(conc~time|dose,groups=subject,type="l") works. But it would be great
if anyone can shed light on how to superimpose the mean profile for each
dose group within that panel

Any help will be appreciated
Thanks
Kumar


--
View this message in context: 
http://r.789695.n4.nabble.com/help-on-panel-superpose-tp3687965p3687965.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Lattice: distance of Y-axis label from plot

2011-07-23 Thread marcel
 Got it working using "layout.widths = list(ylab.axis.padding = 0.5)))" and
adjusting the print position in "print(plot1,
position=c(-0.018,0.221,0.741,0.466))". Thx



--
View this message in context: 
http://r.789695.n4.nabble.com/Lattice-distance-of-Y-axis-label-from-plot-tp3686855p3688172.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] Trouble getting plot to appear

2011-07-23 Thread cherron
Hello,

>I am currently working on a script and I output plots to pdf using
 
pdf(...)
plot(...)
dev.off()

>then later I was trying to plot something and when I run just

plot(...)

>nothing appears. Is there something about using plot(..) after dev.off()
that does not allow the window to pop up? In other words I would like to be
able to see the plot display when just using the plot function. I am using R
in UNIX if this is at all relevant.

Many thanks,

Casey

--
View this message in context: 
http://r.789695.n4.nabble.com/Trouble-getting-plot-to-appear-tp3688078p3688078.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] Store elements in a list in a triple for loop

2011-07-23 Thread katarv
Hi, 

I have a triple loop that goes through all elements of a list 
Lst[[k]][[i,j]] and I want to pick only elements of  Lst[[k]][[i,j]]  > 0.4
or any value. Then I want to store the values of Lst[[k]][[i,j]] together
with their i,j,k values in another list. Say I have Lst[[2]][[4,7]] = 0.6, I
want to store it as a row 

 [,1] [,2] [,3], [,4]
 2   4   7  0.6

 
I tried using  VoxCorr <- list()  and then inside the loop
VoxCorr[i,i,k] <- list(matrix = matrix (c(k,i ,j,
Lst[[k]][[i,j]]),  nrow = 1, ncol = 4))

Which gives an error. It should be something pretty simple but I don't know
en exact syntax I could use to do it. 
Thanks,

Here is the full loop code: 


VoxCorr <- list()
 
   for (i in 1:ncol(aaN))
  {
   for (j in 1:ncol(bbN))
{
  for (k in 1:Nlags)


{
 if ( Lst[[k]][[i,j]] >=CorrMin ||  Lst[[k]][[i,j]] 
<=CorrMin )
   {
   VoxCorr[i,i,k] <- list(matrix = matrix (c(k,i ,j,
   Lst[[k]][[i,j]]),  nrow = 1, ncol = 4))  
   
 }
   }
}

}
   
return (VoxCorr)




--
View this message in context: 
http://r.789695.n4.nabble.com/Store-elements-in-a-list-in-a-triple-for-loop-tp3688210p3688210.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] xml2-config issues

2011-07-23 Thread Abraham Mathew
I'm trying to install the XML package on Ubuntu 10.10, and I keep getting
a warning message the XML could not be found and had non-zero exit
status. How can I fix this problem?

> install.packages()
Loading Tcl/Tk interface ... done
--- Please select a CRAN mirror for use in this session ---
Installing package(s) into ‘/home/amathew/R/i686-pc-linux-gnu-library/2.13’
(as ‘lib’ is unspecified)
trying URL '
http://streaming.stat.iastate.edu/CRAN/src/contrib/XML_3.4-0.tar.gz'
Content type 'application/x-gzip' length 896195 bytes (875 Kb)
opened URL
==
downloaded 875 Kb

* installing *source* package ‘XML’ ...
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
No ability to remove finalizers on externalptr objects in this verison of R
checking for sed... /bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking for xml2-config... no
Cannot find xml2-config
ERROR: configuration failed for package ‘XML’
* removing ‘/home/amathew/R/i686-pc-linux-gnu-library/2.13/XML’

The downloaded packages are in
‘/tmp/Rtmp2V4huR/downloaded_packages’
Warning message:
In install.packages() :
  installation of package 'XML' had non-zero exit status


Thank You,
Abraham

[[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] Fit elipse to xy scatter

2011-07-23 Thread DrCJones
Hi,

I know there is a package 'elipse' available but I'm not sure how to use it
for my specific implementation. 


What I would like to do is fit an elipse to two lines of identity (at right
angles to each other), as indicated in the following figure:
http://imageshack.us/photo/my-images/30/poincareplotwip.png/

Conceptually, I'm really struggling to even come up with a way of doing
this, let alone an implementation. 

Would really appreciate some pointers :) 


--
View this message in context: 
http://r.789695.n4.nabble.com/Fit-elipse-to-xy-scatter-tp3688117p3688117.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] glmnet with binary logistic regression

2011-07-23 Thread fongchun
Hi all,

I am using the glmnet R package to run LASSO with binary logistic
regression.  I have over 290 samples with outcome data (0 for alive, 1 for
dead) and over 230 predictor variables.  I currently using LASSO to reduce
the number of predictor variables.

I am using the cv.glmnet function to do 10-fold cross validation on a
sequence of lambda values which I let glmnet determine.  I then take the
optimal lambda value (lambda.1se) which I then use to predict on an
independent cohort.  

What I am finding is that this optimal lambda value fluctuates everytime I
run glmnet with LASSO.  It deviates quite a bit such that each time I
generate an ROC curve for my validation cohort, I get AUC values which
deviate a bit.  Does anyone know why there is such a fluctuation in the
generation of an optimal lambda?  I am thinking it might be due to the 10
fold cross validation step the training set is not being split well know to
have enough alive and dead cases?  Thoughts?

--
View this message in context: 
http://r.789695.n4.nabble.com/glmnet-with-binary-logistic-regression-tp3688126p3688126.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] An infinite recursion error please explain!

2011-07-23 Thread mousy0815
Probability <- function(N, f, w, b, y, t, q) {
#N is the number of lymph nodes
#f is the fraction of Dendritic cells (in the correct node) that have 
the
antigen
#w is time in terms of hours
#b is the starting position (somewhere in the node or somewhere in the 
gap
between nodes. It is a number between 1 and (x+t))
#y is the number of time steps it takes to traverse the gap (8hr/y)
#t is the number of time steps it takes to traverse a node. (24hours 
total
-- so 24hr/t)
#q is the length of the time step

m <- ceiling(w/q)
A <- 1/N
B <- 1-A
C <- 1-f
D <- (((m+b-1)%%(y+t))+1)



if (b<=t) {starts inside node
if (m<=(t-b)){return(B + A*(C^m))} # start & end in first node  

if (D<=t) { # we finish in a node
a <- (B + A*(C^(t-b))) #first node
b <- ((B + A*(C^t))^(floor((m+b)/(y+t))-1))  # 
intermediate nodes (if
any)
c <- (B + A*(C^D))  # last node  
return(a*b*c)
} else {return(Probability(N, f, ((m*q)-q), b, y, t, 
q))} ## finish in a
gap 
} else {## starts outside node
if (m<=(y+t-b)) {return(1)} #also end in the gap
if (D<=t) { #end in a node
b <- ((B + A*(C^t))^(floor((m/(y+t)
c <- (B + (A*(C^D)))
return(b*c)
} else {return(Probability(N, f, ((m*q)-q), b, 
y, t, q))} #outside node
}
}   


This works for most values of 'w' (time):

> Probability(100, 0.001, 1, 1, 20, 20, (10/60))
[1] 0.401
> Probability(100, 0.001, 2, 1, 20, 20, (10/60))
[1] 0.9998807
> Probability(100, 0.001, 3, 1, 20, 20, (10/60))
[1] 0.9998215
> Probability(100, 0.001, 4, 1, 20, 20, (10/60))
Error: evaluation nested too deeply: infinite recursion /
options(expressions=)?

But once I get to w=4 I get an infinite recursion. I get that there is a
recursion in my function but I'm not sure why it wouldn't work. After a
certain point (D<=t) would be true. 
Any help, please?

--
View this message in context: 
http://r.789695.n4.nabble.com/An-infinite-recursion-error-please-explain-tp3688260p3688260.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] Question about output from twitteR package

2011-07-23 Thread Doug Luke
Dear R-List,

I am trying to develop a tutorial on how to analyze network data from Twitter 
conversations for a network analysis class that I teach. I came across the 
twitteR package, and saw some examples of it in action on various websites. It 
is easy to use, and almost as easy to understand. I was able to pull sets of 
Twitter messages into a dataframe using various criteria (hashtags, etc.). To 
build a network, I would like to follow which messages are responses to earlier 
messages. According to the twitteR package documentation, this is stored in a 
'replyToSN' field (reply to Screenname). However, when I do searches this field 
is always blank (NA). (The similar field replyToSID is also always blank.) The 
Twitter messages themselves suggest that there are some replies in the sets 
that I'm obtaining, so I now in theory that these fields should not be blank 
for every message.

Here is some code and output to make this clearer:

library(twitteR)
library(plyr)
tweets = searchTwitter("#Rstats", n=200)
tweets[[4]]$getText()

[1] "RT @kdnuggets: Great post on using parallel processing with R and HHP $3M 
competition http://bit.ly/rcfztQ #rstats #hhp #datamining"

tweets[[4]]$getScreenName()

[1] "dichika"

tweets[[4]]$getReplyToSN()
character(0)

tweets.df = ldply(tweets, function(t) t$toDataFrame())
head(tweets.df[,c(3,4,6,10)])


  replyToSN created replyToSIDscreenName
1NA 2011-07-23 01:56:46 NAcmprsk
2NA 2011-07-23 01:38:58 NA  muteokie
3NA 2011-07-23 00:27:32 NA floss4science
4NA 2011-07-23 00:16:06 NA   dichika
5NA 2011-07-22 22:20:55 NAcmprsk
6NA 2011-07-22 21:50:43 NA  siah

I hope I'm missing something simple, but my gut tells me that I need to do some 
type of authentification before this information will be returned. I couldn't 
find any useful examples of this issue or how to get around it after looking 
for a while.

Thanks,

Douglas Luke

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


[R] How to solve ergodic density/distribution using R

2011-07-23 Thread Hong Yu

May I have a question on how to solve the following problem by R code?

Mainly we want to solve the equation show in the attached image.  The equation 
is a continuous version of Markov process.  

In the equation, we have been able to achieve two things using R code:
[1]  From year-2009 sample data, we can estimate the marginal density ‘f(x ; 
2009)’ by using R function ‘density()’
[2]  From appropriately grouped all sample data, we can estimate the 
conditional density ‘g(z|x ; 1)’ by using R function ‘cde()’ from hdrcde package

Now we are searching and reading reference docs on how to solve for the 
long-run (ergodic) distribution ‘f(x)’.  Much appreciated if any suggestions on 
solution steps using R; and we will be happy to provide additional references.  
Thanks a lot!

Regards,

Hong Yu

__
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 on panel.superpose

2011-07-23 Thread Duncan Mackay

I too am unsure what is required, perhaps

xyplot(y~x,data,col=c(3,4),groups=id,pch=c(12,13), type= c("p","r"))

a toy dataset would have helped

Perhaps a perusal of
http://lmdvr.r-forge.r-project.org/figures/figures.html
is required


Regards

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



At 11:30 23/07/2011, you wrote:

For the first part, use the col and pch arguments:

id<-rep(c(0,2),each=50)
e<-rnorm(100)
x<-rnorm(100)
y<-id+x+e
xyplot(y~x,groups=id,col=c(3,4),pch=c(12,13))

For the second part, I do not know what exactly mean by superimpose the mean
level? Should the mean for each group be displayed as a horizontal line?

Best,
Daniel



Bharath Kumar wrote:
>
> Dear users,
>
> I am new to R and have couple of problems with xyplot.
>
> A) I am trying to use the xyplot to plot mean concentration vs time across
> 5 dose groups.
>
> When i use the following script
> xyplot(mean~time,groups=dose,type="b",panel=panel.superpose). R generates
> the plot, but i have no control over pch or color for the line. It
> displays whatever color and pch it wants to generate. How do i fix this.
>
> B) I am trying to use the same function to plot individual data across
> dose groups
>
> xyplot(conc~time|dose,groups=subject,type="l") works. But it would be
> great if anyone can shed light on how to superimpose the mean profile for
> each dose group within that panel
>
> Any help will be appreciated
> Thanks
> Kumar
>

--
View this message in context: 
http://r.789695.n4.nabble.com/help-on-panel-superpose-tp3687965p3688225.html

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

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


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


[R] Use ks.test() or an alternative in C/C++ application

2011-07-23 Thread Jochen1980
Hi, 

I am looking for an opportunity to make a KS-Test in my C/C++-app.
Unfortunately I am not able to find a lib or function in C or C++ which does
the job. For my other numerical stuff Gnu Scientific Library was recommended
to me. What to do now?

I read that there are options to call R in C++-Code. How does that work and
is this a good option if the test will be called very often and the program
should be running on a computer cluster?

Thanks in advance!

--
View this message in context: 
http://r.789695.n4.nabble.com/Use-ks-test-or-an-alternative-in-C-C-application-tp3688640p3688640.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Picking returns from particular days of the month from a zoo object

2011-07-23 Thread Joshua Ulrich
On Fri, Jul 22, 2011 at 2:37 PM, john nicholas  wrote:
>  Hello,
>
> I would like to implement a "turn-of-the-month' trading strategy in R.
>
> Given a daily series of stock market return data as a zoo object, the strategy
> would go long (buy) four trading days before the end of the month, and sell 
> the
> third trading day of the following month.
>
> How can I select these days, particularly the fourth day before and the third
> day after the turn of the month, from a zoo object?
>
Here are two ways to do this using xts.  The first approach creates a
list of xts objects where each list element contains one month of
data.  Then it uses first() and last() to extract the 4th trading day
prior to the end of the month.

require(quantmod)
getSymbols(SPY)
x1 <- do.call(rbind, lapply(split(SPY, "months"), function(x) first(last(x,4

The second approach uses apply.monthly(), but that function always
returns an object with index values that correspond to the last
observation in the month.  So we have to manually update the index to
be 3 days prior.

x2 <- apply.monthly(SPY, function(x) first(last(x,4)))
index(x2) <- index(SPY)[endpoints(SPY, "months")[-1]-3]

> Thanks in advance,
>
> John B. Nicholas, Ph.D
> 650-315-9895
>

HTH,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.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] glmnet with binary logistic regression

2011-07-23 Thread Patrick Breheny

On 07/22/2011 07:51 PM, fongchun wrote:

I am using the glmnet R package to run LASSO with binary logistic
regression.
...
What I am finding is that this optimal lambda value fluctuates
everytime I run glmnet with LASSO.

> ...

Does anyone know why there is such a fluctuation  in the
generation of an optimal lambda?


Cross-validation is a random procedure, and the results will vary every 
time.  This reflects the underlying uncertainty regarding the optimal 
lambda.


Or are you saying that you've used glmnet many times, but this time, the 
fluctuations in lambda are much larger than usual?  If so, and you 
suspect a problem with the way that glmnet is partitioning the data set 
into cross-validation folds, you can specify that with the 'foldid' option.


--
Patrick Breheny
Assistant Professor
Department of Biostatistics
Department of Statistics
University of Kentucky

__
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] Problem with read.shape in maptools

2011-07-23 Thread Axel Urbiz
Hi,

I'd like to read a shapefile into a Map object. This is exactly what
read.shape{maptools} is suppoed to do, according to the documentation I
found in the link below.

However, this doesn't seem to work


library(maptools)x <- read.shape(system.file("shapes/sids.shp",
package="maptools")[1])Error: could not find function "read.shape"



I haven't found this function on the documentation from the latest
release of the package, so I assume is no longer supported. Is there
an alternative way of doing this?



http://rss.acs.unt.edu/Rdoc/library/maptools/html/read.shape.html

Thanks,

Axel.

[[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] sum part of a vector

2011-07-23 Thread Simon Kiss
Dear colleagues, I have a data set that looks roughly like this;
mydat<-data.frame(state=c(rep("Alabama", 5), rep("Delaware", 5), 
rep("California", 5)), news=runif(15, min=0, max=8), cum.news=rep(0, 15))

For each state, I'd like to cumulatively sum the value of "news" and make that 
put that value in cum.news.

I'm trying as follows but I get really weird results. One thing is that it 
keeps counting 0's as 1. 

for (i in levels(mydat$state)) {
mydat[mydat$state==i, ]$cum.news<-sapply(mydat[mydat$state==i, ]$news, 
function(x) sum(1:x))
}

I can sort of get the same sapply function to do what I want when working on a 
test string
test<-1:10
sapply(test, function(x) sum(1:x))

Any thoughts?
Simon Kiss
*
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9
Cell: +1 905 746 7606

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


Re: [R] [R-sig-Geo] Problem with read.shape in maptools

2011-07-23 Thread Roger Bivand

On Sat, 23 Jul 2011, Axel Urbiz wrote:


Hi,

I'd like to read a shapefile into a Map object. This is exactly what
read.shape{maptools} is suppoed to do, according to the documentation I
found in the link below.


Do search the archives properly; the second hit on googling 
"list:R-sig-geo read.shape" is relevant. Summarize to the list when you've 
resolved your problem. In addition, R is case specific, so an S3 Map 
object is not an S3 map object.


Your previous mail refers to a function in the maps package, which does
things that may be supported elsewhere. The only function that seems to
convert SpatialPolygonsDataFrame to a list like the map class is
fortify.SpatialPolygonsDataFrame() in ggplot2, but I don't know if this
does what you need. To be honest, you havent't explained what you want to
do with smooth.map that you cannot do with sp objects - please do read the
available documentation before cross-posting (first post).

Roger



However, this doesn't seem to work


library(maptools)x <- read.shape(system.file("shapes/sids.shp",
package="maptools")[1])Error: could not find function "read.shape"



I haven't found this function on the documentation from the latest
release of the package, so I assume is no longer supported. Is there
an alternative way of doing this?



http://rss.acs.unt.edu/Rdoc/library/maptools/html/read.shape.html

Thanks,

Axel.

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
r-sig-...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: roger.biv...@nhh.no

__
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] xml2-config issues

2011-07-23 Thread Mike Marchywka














Date: Fri, 22 Jul 2011 20:06:34 -0600
From: abmathe...@gmail.com
To: r-help@r-project.org
Subject: [R] xml2-config issues


I'm trying to install the XML package on Ubuntu 10.10, and I keep getting
a warning message the XML could not be found and had non-zero exit
status. How can I fix this problem?

> install.packages()
Loading Tcl/Tk interface ... done
--- Please select a CRAN mirror for use in this session ---
Installing package(s) into ‘/home/amathew/R/i686-pc-linux-gnu-library/2.13’
(as ‘lib’ is unspecified)
trying URL '
http://streaming.stat.iastate.edu/CRAN/src/contrib/XML_3.4-0.tar.gz'
Content type 'application/x-gzip' length 896195 bytes (875 Kb)
opened URL
==
downloaded 875 Kb

* installing *source* package ‘XML’ ...
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
No ability to remove finalizers on externalptr objects in this verison of R
checking for sed... /bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking for xml2-config... no
Cannot find xml2-config
ERROR: configuration failed for package ‘XML’
* removing ‘/home/amathew/R/i686-pc-linux-gnu-library/2.13/XML’

[ my text, hotmail won't highlight original  ]

you probably need to get libxml2 and then you should be able to run 
xml2-config from command line to verfiy it is there. This is a specific
pkg-config ( man pkg-config for details ). For some non-R things
yum or apt-get has not gotten the most recent versions but generally
your package manager should be just fine. 




The downloaded packages are in
‘/tmp/Rtmp2V4huR/downloaded_packages’
Warning message:
In install.packages() :
  installation of package 'XML' had non-zero exit status


Thank You,
Abraham

[[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] sum part of a vector

2011-07-23 Thread Weidong Gu
Hi Simon,

Is this what you want?

mydat$cum.news<-unlist(tapply(mydat$news,mydat$state,FUN=cumsum))

Weidong Gu

On Sat, Jul 23, 2011 at 7:11 AM, Simon Kiss  wrote:
> Dear colleagues, I have a data set that looks roughly like this;
> mydat<-data.frame(state=c(rep("Alabama", 5), rep("Delaware", 5), 
> rep("California", 5)), news=runif(15, min=0, max=8), cum.news=rep(0, 15))
>
> For each state, I'd like to cumulatively sum the value of "news" and make 
> that put that value in cum.news.
>
> I'm trying as follows but I get really weird results. One thing is that it 
> keeps counting 0's as 1.
>
> for (i in levels(mydat$state)) {
> mydat[mydat$state==i, ]$cum.news<-sapply(mydat[mydat$state==i, ]$news, 
> function(x) sum(1:x))
> }
>
> I can sort of get the same sapply function to do what I want when working on 
> a test string
> test<-1:10
> sapply(test, function(x) sum(1:x))
>
> Any thoughts?
> Simon Kiss
> *
> Simon J. Kiss, PhD
> Assistant Professor, Wilfrid Laurier University
> 73 George Street
> Brantford, Ontario, Canada
> N3T 2C9
> Cell: +1 905 746 7606
>
> __
> 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] xml2-config issues

2011-07-23 Thread Prof Brian Ripley

On Fri, 22 Jul 2011, Abraham Mathew wrote:


I'm trying to install the XML package on Ubuntu 10.10, and I keep getting
a warning message the XML could not be found


No, that is not the *error* message you quote below.


and had non-zero exit status. How can I fix this problem?


Install libxml2 ... including the development version.  (The 
difference is described in the R-admin manual which you should have 
read by now.)





install.packages()

Loading Tcl/Tk interface ... done
--- Please select a CRAN mirror for use in this session ---
Installing package(s) into ?/home/amathew/R/i686-pc-linux-gnu-library/2.13?
(as ?lib? is unspecified)
trying URL '
http://streaming.stat.iastate.edu/CRAN/src/contrib/XML_3.4-0.tar.gz'
Content type 'application/x-gzip' length 896195 bytes (875 Kb)
opened URL
==
downloaded 875 Kb

* installing *source* package ?XML? ...
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
No ability to remove finalizers on externalptr objects in this verison of R
checking for sed... /bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking for xml2-config... no
Cannot find xml2-config
ERROR: configuration failed for package ?XML?
* removing ?/home/amathew/R/i686-pc-linux-gnu-library/2.13/XML?

The downloaded packages are in
?/tmp/Rtmp2V4huR/downloaded_packages?
Warning message:
In install.packages() :
 installation of package 'XML' had non-zero exit status


Thank You,
Abraham

[[alternative HTML version deleted]]




--
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] sum part of a vector

2011-07-23 Thread peter dalgaard

On Jul 23, 2011, at 13:11 , Simon Kiss wrote:

> Dear colleagues, I have a data set that looks roughly like this;
> mydat<-data.frame(state=c(rep("Alabama", 5), rep("Delaware", 5), 
> rep("California", 5)), news=runif(15, min=0, max=8), cum.news=rep(0, 15))
> 
> For each state, I'd like to cumulatively sum the value of "news" and make 
> that put that value in cum.news.

Like this?

> mydat <- within(mydat, cum.news <- ave(news, state, FUN=cumsum))
> mydat
state  news  cum.news
1 Alabama 7.9914863  7.991486
2 Alabama 7.3751514 15.366638
3 Alabama 3.4894295 18.856067
4 Alabama 3.1543811 22.010448
5 Alabama 7.9720879 29.982536
6Delaware 2.3904745  2.390475
7Delaware 5.5532841  7.943759
8Delaware 5.4182249 13.361984
9Delaware 4.6554645 18.017448
10   Delaware 3.1289714 21.146419
11 California 7.9450424  7.945042
12 California 2.0142029  9.959245
13 California 7.9735398 17.932785
14 California 1.0972878 19.030073
15 California 0.7215365 19.751609


-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com
"Døden skal tape!" --- Nordahl Grieg

__
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] Picking returns from particular days of the month from a zoo object

2011-07-23 Thread Gabor Grothendieck
On Fri, Jul 22, 2011 at 3:37 PM, john nicholas  wrote:
>
>  Hello,
>
> I would like to implement a "turn-of-the-month' trading strategy in R.
>
> Given a daily series of stock market return data as a zoo object, the strategy
> would go long (buy) four trading days before the end of the month, and sell 
> the
> third trading day of the following month.
>
> How can I select these days, particularly the fourth day before and the third
> day after the turn of the month, from a zoo object?
>


library(quantmod) # also brings in zoo

# set up some test data
getSymbols("IBM", return.class = "zoo")

# get index in ibm to 3rd trading day in month
# and 4th last trading day in month
ym <- as.yearmon(time(IBM))
ithird <- c(tapply(seq_along(tt), ym, "[", 3))
ilast4 <- c(tapply(seq_along(tt), ym, function(x) x[length(x)-3]))

Now IBM[ithird, ] and IBM[ilast4, ] give the subseries at the third and
fourth last days of each month, respectively.

time(IBM)[ithird] and time(IBM)[ilast4] are just the dates.

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


[R] graphic problem: transparent window when starting mtrace() from package debug

2011-07-23 Thread Jannis

Deal R
,


when I use the package debug, mark a function with mtrace() and enter 
into the browser like mechanism of debug a window displaying the code of 
the marked function with the current line highlighted usually appears. 
When I use GUIs other than ess or the standard R console sometimes this 
window is totally transparent so it is not possible to see any code in 
it. After closing/resizing the window this error sometimes dissapears 
but I could not find any systematic behaviour here. The problem occours 
when I use Eclipse/Statet or Notepad++ as a GUI.


Does anybody have any ideas about the possible cause of the problem?


Thanks for your help
Jannis


P.S. Posting to the Statet mailing list did not yield any helpful advice.


My system settings are:

WinXP

R version 2.12.0 (2010-10-15)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] debug_1.2.4  mvbutils_2.5.4
[4] RNetCDF_1.5.2-2  rj_0.5.2-1

loaded via a namespace (and not attached):
[1] rJava_0.8-8

__
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] determining system time for sequence of commands

2011-07-23 Thread Jannis

Dear list members,


I am trying to figure out how much CPU time individual commands inside 
one of my functions consume. Is it possible to obtain the CPU times of a 
whole sequence of commands inside a function? I know how to use 
system.time() but this would only give me the time consumed by the whole 
function. The only (cumbersome) way I figured out would be to run 
system.time for each individual command. Does anybody have a hint on a 
function/package that allows to do this automatically?



Thanks a lot
Jannis

__
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] averaging rows based on string¿?

2011-07-23 Thread Dennis Murphy
Hi:

Try this:

labs <- c("abcdef","abcgg","tgthefdk","tgtijuel","tgtnjmoi","gbnt","dlift")
dat <- c(0.5,0.25,1,2,16,0.250,4)
dframe <- data.frame(labs, dat, stringsAsFactors = FALSE)
dframe$lab2 <- factor(substr(dframe$lab, 1, 3))
aggregate(dat ~ lab2, data = dframe, FUN = mean)
  lab2  dat
1  abc 0.375000
2  dli 4.00
3  gbn 0.25
4  tgt 6.33

HTH,
Dennis


On Fri, Jul 22, 2011 at 1:00 PM, alfredo  wrote:
> Hi Folks,
>
> Ran into something I'd really like to do in R simply/elegantly, but my R -
> coding skills seem surpassed. This is the thing. Imagine the following data:
>
> labs<-c("abcdef","abcgg","tgthefdk","tgtijuel","tgtnjmoi","gbnt","dlift")
> dat<-c(0.5,0.25,1,2,16,0.250,4)
> dframe<-data.frame(labs,dat)
>
> I would like to average the values in "dat" according to specific
> string/text in the name of their row names described by "labs". For example,
> average the values in "dat" if the first three (or more) letters in their
> corresponding "labs" are the same. This would give the following vector:
>
> 0.375000 6.33 0.25 4.00 # in which 0.375 is the average of
> "abcdef" and "abcgg", etc.
>
> I hope I've made myself (kind'a) clear and apologise otherwise. Any ideas?
>
> Thanks for your help!
>
> A
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/averaging-rows-based-on-string-tp3687689p3687689.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


[R] Achieving 'reverse-Vech' of a matrix

2011-07-23 Thread Megh Dal
Let say i have a square matrix and applied the 'vech' operator to stack the 
lower triangular elements into a vector:

> Mat <- matrix(1:25, 5)
> Mat
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    6   11   16   21
[2,]    2    7   12   17   22
[3,]    3    8   13   18   23
[4,]    4    9   14   19   24
[5,]    5   10   15   20   25
> Mat[lower.tri(Mat)]
 [1]  2  3  4  5  8  9 10 14 15 20


Now, I want to reverse-work with the resulting matrix. Means, given a "correct" 
vector, I want to place the elements of this vector into the lower-triangular 
portion of some "correct" square matrix.

Would somebody help me to implement that?

Thanks,

__
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] inside p value 'e'

2011-07-23 Thread Dieter Menne

xy wrote:
> 
> I have like 5.075e-12 , 3.207e-05, 7.438e-07 and 9.393e-08 *** , i dont
> know what number they are 

http://en.wikipedia.org/wiki/Floating_point



--
View this message in context: 
http://r.789695.n4.nabble.com/inside-p-value-e-tp3688961p3689167.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] determining system time for sequence of commands

2011-07-23 Thread Dieter Menne

jannis-2 wrote:
> 
> I am trying to figure out how much CPU time individual commands inside 
> one of my functions consume. Is it possible to obtain the CPU times of a 
> whole sequence of commands inside a function? 
> 

See the example under proc.time()

Dieter


--
View this message in context: 
http://r.789695.n4.nabble.com/determining-system-time-for-sequence-of-commands-tp3688944p3689172.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] R on Android, at least on DOS

2011-07-23 Thread Dieter Menne

zcatav wrote:
> 
> If this isn't, a DOS version may be helpfull to run on Android under
> dosbox.
> 

Wow, a mind boggling bummer!

Dieter



--
View this message in context: 
http://r.789695.n4.nabble.com/R-on-Android-at-least-on-DOS-tp3688847p3689176.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Use ks.test() or an alternative in C/C++ application

2011-07-23 Thread Dieter Menne

Jochen1980 wrote:
> 
> 
> I am looking for an opportunity to make a KS-Test in my C/C++-app.
> Unfortunately I am not able to find a lib or function in C or C++ which
> does the job. For my other numerical stuff Gnu Scientific Library was
> recommended to me. What to do now?
> 
> I read that there are options to call R in C++-Code. How does that work
> and is this a good option if the test will be called very often and the
> program should be running on a computer cluster?
> 

Have a look at the section on the subject in the "Writing R-extension"
documentation. Much more fancy is Rcpp, for example:

http://r-project.markmail.org/thread/vgedk4gdanjbrlpe

The Rcpp-way is probably the easiest when you have few functions only.

With a computer cluster and, my favorite RServe for maximal flexibility. You
could install RServe on one computer only, and access it from everyhwere.

Dieter





--
View this message in context: 
http://r.789695.n4.nabble.com/Use-ks-test-or-an-alternative-in-C-C-application-tp3688640p3689196.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Achieving 'reverse-Vech' of a matrix

2011-07-23 Thread Ted Harding
On 23-Jul-11 17:12:09, Megh Dal wrote:
> Let say i have a square matrix and applied the 'vech' operator to stack
> the lower triangular elements into a vector:
> 
>> Mat <- matrix(1:25, 5)
>> Mat
> _ _ _[,1] [,2] [,3] [,4] [,5]
> [1,] _ _1 _ _6 _ 11 _ 16 _ 21
> [2,] _ _2 _ _7 _ 12 _ 17 _ 22
> [3,] _ _3 _ _8 _ 13 _ 18 _ 23
> [4,] _ _4 _ _9 _ 14 _ 19 _ 24
> [5,] _ _5 _ 10 _ 15 _ 20 _ 25
>> Mat[lower.tri(Mat)]
> _[1] _2 _3 _4 _5 _8 _9 10 14 15 20
> 
> 
> Now, I want to reverse-work with the resulting matrix. Means, given a
> "correct" vector, I want to place the elements of this vector into the
> lower-triangular portion of some "correct" square matrix.
> 
> Would somebody help me to implement that?
> Thanks,

If you are already using 'vech()' in the MCMCpack package to extract
the lower-triangular vector, then that package contains also the
function 'xpnd()' which reconstructs a symmetric matric from the
Vech.

Thus, is you have a matrix A whose lower triangular part you
want to replace as you describe, and a vector X which is the Vech
of some matrix, then

  B <- xpnd(X)
  A[lower.tri(A)] <- B[lower.tri(B)]

should do it (not tested by me, however ... ).

Hoping this helps,
Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 23-Jul-11   Time: 18:43:05
-- XFMail --

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


[R] Testing two independent samples for null of same skewness and kurtosis?

2011-07-23 Thread Eduardo M. A. M.Mendes
Hello

 

I wonder whether there is an r tool or package available for testing for the
null of same skewness or kurtosis of two independent samples.

 

It semes that nsRFA package uses L-moments for soothing similar but I could
not get how to use the package for the above test.

 

Any pointers, help, example and etc.  will be most welcome.

 

Many thanks

 

Ed

 

 

 


[[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] analizing .txt file with R or an other program

2011-07-23 Thread Daniel Malter
Hi,

The blunt answer is: by learning R. In particular, you will need pattern
matching techniques as in ?grep and (somewhat advanced, some would call it
basic) knowledge of R. So if you aren't familiar with either, I would
suggest an introductory manual or one of the many websites you find online
and then to dig deeper into the pattern matching stuff.

Generally, please adhere to the posting guide (provide a self-contained,
i.e., copy/paste-able, example of code/data for people to work with). Also,
you will be much more likely to receive a response if you have demonstrated
own coding effort (contributors are willing to solve problems but unwilling
to do other people's work).

Best,
Daniel



aRe wrote:
> 
> Hello together
> 
> I have a .txt file with about 1Mio! rows.
> 
> Sometimes the rows are in the following order (whereas the number of rows
> between the rows marked with an x differ):
> 
> ...
> *SBLINK R 5261507*x
> 5261439 516.4   364.3  9148.0 ...   816.0 -1133.048.4 
> MA.C.TB...BL.
> 5261441 516.4   364.0  9145.0 ...   799.0 -1135.048.7 
> MA.C.TB...B..
> 5261443 516.4   363.9  9140.0 ...   817.0 -1171.049.3 
> MA.C.TB.R
> *MSG  5261445 Prime 11_fe_ha*x
> 5261445 516.7   363.8  9133.0 ...   813.0 -1097.049.3 
> MA.C.TB..
> 5261447 517.0   363.8  9127.0 ...   818.0 -1144.049.9 
> MA.C.T.LRTB..
> *EBLINK R 5261507 5261645 140*x
> 5261509  .   .0.0 ....   .   . 
> .
> 5261511  .   .0.0 ....   .   . 
> .
> *MSG  5261512 Mask 8_ma_ma*x
> 5261513  .   .0.0 ....   .   . 
> .
> 5261515  .   .0.0 ....   .   . 
> .
> ...
> 
> Here I would like to generate an output, that gives me the two parts
> "...Prime 11_fe_ha" and "...Mask 8_ma_ma" if and only if "...Prime
> 11_fe_ha" is situated between "SBLINK..." and "EBLINK...".
> 
> 
> 
> 
> Sometimes the rows are in the following order (whereas the number of rows
> between the rows marked with an x differ):
> 
> ...
> *MSG  5261445 Prime 11_fe_ha*x
> 5261439 516.4   364.3  9148.0 ...   816.0 -1133.048.4 
> MA.C.TB...BL.
> 5261441 516.4   364.0  9145.0 ...   799.0 -1135.048.7 
> MA.C.TB...B..
> 5261443 516.4   363.9  9140.0 ...   817.0 -1171.049.3 
> MA.C.TB.R
> *SBLINK R 5261507*x5261445  516.7   363.8  9133.0 ...   813.0 -1097.0 
>   
> 49.3 MA.C.TB..
> 5261447 517.0   363.8  9127.0 ...   818.0 -1144.049.9 
> MA.C.T.LRTB..
> *EBLINK R 5261507 5261645 140*x
> 5261509  .   .0.0 ....   .   . 
> .
> 5261511  .   .0.0 ....   .   . 
> .
> *MSG  5261512 Mask 8_ma_ma*x
> 5261513  .   .0.0 ....   .   . 
> .
> 5261515  .   .0.0 ....   .   . 
> .
> ...
> 
> Here I would like to generate an output, that consists of the two parts
> "...Prime 11_fe_ha" and "...Mask 8_ma_ma" if and only if "SBLINK..." is
> situated between "... Prime 11_fe_ha" and "...Mask 8_ma_ma". The place of
> the "EBLINK..." is not important. that means also the following structure
> should lead to the same output:
> 
> ...
> *MSG  5261445 Prime 11_fe_ha*x
> 5261439 516.4   364.3  9148.0 ...   816.0 -1133.048.4 
> MA.C.TB...BL.
> 5261441 516.4   364.0  9145.0 ...   799.0 -1135.048.7 
> MA.C.TB...B..
> 5261443 516.4   363.9  9140.0 ...   817.0 -1171.049.3 
> MA.C.TB.R
> *SBLINK R 5261507*x5261445  516.7   363.8  9133.0 ...   813.0 -1097.0 
>
> 5261447 517.0   363.8  9127.0 ...   818.0 -1144.049.9 
> MA.C.T.LRTB..
> 5261509  .   .0.0 ....   .   . 
> .
> 5261511  .   .0.0 ....   .   . 
> .
> *MSG  5261512 Mask 8_ma_ma*x
> 5261513  .   .0.0 ....   .   . 
> .
> 5261515  .   .0.0 ....   .   . 
> .
> *EBLINK R 5261507 5261645 140*x
> ...
> 
> 
> can someone give me a advice how I could manage this task?
> 
> thanks
> 
> best
> 

--
View this message in context: 
http://r.789695.n4.nabble.com/analizing-txt-file-with-R-or-an-other-program-tp3689025p3689393.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] An infinite recursion error please explain!

2011-07-23 Thread Carl Witthoft
Not sure, but I played a little with the progression of w and m, and it 
appears that it doesn't take long for their values to converge (i.e. 
they don't change any more).  Once that happens,  D is not going to change.


Further,  unless I'm misreading the if {...} indents,  you appear to be 
checking for D<=t at a point where it can't happen, i.e. after your 
comment "starts outside node."   Please correct me if I'm wrong about that.



Carl




From: mousy0815 
Date: Fri, 22 Jul 2011 19:29:46 -0700 (PDT)

Probability <- function(N, f, w, b, y, t, q) {

#N is the number of lymph nodes
#f is the fraction of Dendritic cells (in the correct node) that have 
the
antigen
#w is time in terms of hours
#b is the starting position (somewhere in the node or somewhere in the 
gap
between nodes. It is a number between 1 and (x+t))
#y is the number of time steps it takes to traverse the gap (8hr/y)
#t is the number of time steps it takes to traverse a node. (24hours 
total
-- so 24hr/t)
#q is the length of the time step

m <- ceiling(w/q)
A <- 1/N
B <- 1-A
C <- 1-f
D <- (((m+b-1)%%(y+t))+1)



if (b<=t) {starts inside node
if (m<=(t-b)){return(B + A*(C^m))} # start & end in 
first node   
if (D<=t) { # we finish in a node
a <- (B + A*(C^(t-b))) #first node
b <- ((B + A*(C^t))^(floor((m+b)/(y+t))-1))  # 
intermediate nodes (if
any)
c <- (B + A*(C^D))  # last node
return(a*b*c)
} else {return(Probability(N, f, ((m*q)-q), b, 
y, t, q))} ## finish in a
gap 
} else {## starts outside node
if (m<=(y+t-b)) {return(1)} #also end in the gap
if (D<=t) { #end in a node
b <- ((B + A*(C^t))^(floor((m/(y+t)
c <- (B + (A*(C^D)))
return(b*c)
} else {return(Probability(N, f, ((m*q)-q), b, 
y, t, q))} #outside node
}
}   


This works for most values of 'w' (time):

> Probability(100, 0.001, 1, 1, 20, 20, (10/60))
[1] 0.401
> Probability(100, 0.001, 2, 1, 20, 20, (10/60))
[1] 0.9998807
> Probability(100, 0.001, 3, 1, 20, 20, (10/60))
[1] 0.9998215
> Probability(100, 0.001, 4, 1, 20, 20, (10/60))
Error: evaluation nested too deeply: infinite recursion / 
options(expressions=)?


But once I get to w=4 I get an infinite recursion. I get that there is a 
recursion in my function but I'm not sure why it wouldn't work. After a 
certain point (D<=t) would be true.

Any help, please?
--
-
Sent from my Cray XK6

__
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] Extend my code to run several data at once.

2011-07-23 Thread Daniel Malter
If you just want to apply the function over successive columns of a data
frame use

apply(name.of.data.frame, 2 , llik)

Daniel


EdBo wrote:
> 
> Hi
> 
> I have a code that calculate maximisation using optimx and it is working
> just fine. I want to extend the code to run several colomns of R_j where j
> runs from 1 to 200. If I am to run the code in its current state, it means
> I will have to run it 200 times manually. May you help me adjust it to
> accomodate several rows of R_j and print the 200 results.
> 
> ***Please do not get intimidated by the maths in the code.***
> 
> my code
> ##
> afull=read.table("D:/hope.txt",header=T)
> library(optimx) 
> llik = function(x) 
>{ 
> al_j=x[1]; au_j=x[2]; sigma_j=x[3];  b_j=x[4]
> sum(na.rm=T,
> ifelse(a$R_j< 0, log(1 / ( sqrt(2*pi) * sigma_j) )-
>(1/( 2*sigma_j^2 ) ) * ( 
> (a$R_j+al_j-b_j*a$R_m)^2 ) , 
> 
>  ifelse(a$R_j>0 , log(1 / ( sqrt(2*pi) * sigma_j) )-
>(1/( 2*sigma_j^2 ) ) * ( 
> (a$R_j+al_j-b_j*a$R_m)^2 ) ,
> 
>   log(ifelse (( pnorm (au_j, mean=b_j * a$R_m, 
> sd= sqrt(sigma_j^2))-
>pnorm(al_j, mean=b_j * a$R_m, sd=sqrt
> (sigma_j^2)) ) > 0,
> 
>   (pnorm (au_j,mean=b_j * a$R_m, sd= 
> sqrt(sigma_j^2))-
>pnorm(al_j, mean=b_j * a$R_m, sd=
> sqrt(sigma_j^2) )),
>   1) ) ) )
>   )
>} 
> start.par = c(-0.01,0.01,0.1,1) 
> 
> #looping now
> runs=133/20+1
> 
> 
> out <- matrix(NA, nrow = runs, ncol = 4,
> 
> dimnames = list(paste("Qtr:", 1:runs , sep = ''),
> 
> c("al_j", "au_j", "sigma_j", "b_j"))) 
> 
>   
> ## Estimate parameters based on rows 0-20, 21-40, 41-60 of afull
> for (i in 1:runs) {
>   index_start=20*(i-1)+1
>   index_end= 20*i
>   a=afull[index_start:index_end,]
>   out[i, ] <- optimx(llik,par = start.par,method = "Nelder-Mead",
> control=list(maximize=TRUE) )[[1]][[1]]
>   } 
> 
> ## Yields 
>> out
>al_jau_j sigma_jb_j
> Qtr:1  0.0012402032 0.001082986 0.012889809 1.14095125
> Qtr:2  0.0011302178 0.582718275 0.009376083 0.06615565
> Qtr:3  0.0013349347 0.417495301 0.013286103 0.60548903
> Qtr:4 -0.0016659441 0.162250321 0.015088915 0.67395511
> Qtr:5  0.0043159984 0.004315976 0.013153039 1.17341907
> Qtr:6  0.0027333033 0.527280348 0.018423347 0.53905153
> Qtr:7 -0.0009214064 0.749695104 0.008730072 0.02108032
>>
> 

--
View this message in context: 
http://r.789695.n4.nabble.com/Extend-my-code-to-run-several-data-at-once-tp3688823p3689534.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] score test for logistic regression

2011-07-23 Thread Thomas Lumley
On Fri, Jul 22, 2011 at 8:00 PM, peter dalgaard  wrote:
>
> On Jul 21, 2011, at 23:11 , David Winsemius wrote:
>
>>
>> On Jul 21, 2011, at 3:38 PM, zlu wrote:
>>
>>> Hi Peter,
>>
>> I'm not sure how many people still have 9 month old postings on their mail 
>> client and will know that Peter Dalgaard is the intended recipient.
>>
>>> Do you have any idea or codes of construct a score test based confidence
>>> interval for coefficients in logistic regression?
>>
>> I realize that Peter knows more than I about this, so take this as working 
>> hypothesis and believe anything he says more than what I say. My idea: set 
>> the glm control ..., maxit=1, so you only get one iteration and then use the 
>> deviance results with the usual chi-square assuptions. I fear this could be 
>> too easy or else Peter would have already thought of this dodge.
>>
>
> I did think along those lines but couldn't convince myself that it would 
> work. Rather, what you need is the deviance (SSD) of the approximating 
> weighted regression analysis. Anyways, anova(..., test="Rao") has been 
> implemented in R-devel for a while.
>
> This doesn't do confidence intervals, though.  That is a somewhat harder 
> problem -- you'd basically need to redo the likelihood profiling code with a 
> different criterion.
>
> For a slow and dirty technique, you could see if a parameter value beta0 is 
> in the CI by including an offset of beta0*x and computing the score test for 
> whether the shifted parameter (beta-beta0) is zero. Then use uniroot().
>

I think you basically have to do this computation.  The problem is
that you may not find exactly two endpoints.  For the deviance-based
intervals, a unimodal likelihood is sufficient to guarantee there are
exactly two places where the deviance differs from the maximum by the
desired amount.Things can be much messier when you are trying to
get the score divided by its estimated standard error to be 1.96.


-thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

__
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] score test for logistic regression

2011-07-23 Thread peter dalgaard

On Jul 24, 2011, at 00:20 , Thomas Lumley wrote:

> On Fri, Jul 22, 2011 at 8:00 PM, peter dalgaard  wrote:
>> 
>> On Jul 21, 2011, at 23:11 , David Winsemius wrote:
>> 
>>> 
>>> On Jul 21, 2011, at 3:38 PM, zlu wrote:
>>> 
 Hi Peter,
>>> 
>>> I'm not sure how many people still have 9 month old postings on their mail 
>>> client and will know that Peter Dalgaard is the intended recipient.
>>> 
 Do you have any idea or codes of construct a score test based confidence
 interval for coefficients in logistic regression?
>>> 
>>> I realize that Peter knows more than I about this, so take this as working 
>>> hypothesis and believe anything he says more than what I say. My idea: set 
>>> the glm control ..., maxit=1, so you only get one iteration and then use 
>>> the deviance results with the usual chi-square assuptions. I fear this 
>>> could be too easy or else Peter would have already thought of this dodge.
>>> 
>> 
>> I did think along those lines but couldn't convince myself that it would 
>> work. Rather, what you need is the deviance (SSD) of the approximating 
>> weighted regression analysis. Anyways, anova(..., test="Rao") has been 
>> implemented in R-devel for a while.
>> 
>> This doesn't do confidence intervals, though.  That is a somewhat harder 
>> problem -- you'd basically need to redo the likelihood profiling code with a 
>> different criterion.
>> 
>> For a slow and dirty technique, you could see if a parameter value beta0 is 
>> in the CI by including an offset of beta0*x and computing the score test for 
>> whether the shifted parameter (beta-beta0) is zero. Then use uniroot().
>> 
> 
> I think you basically have to do this computation.  The problem is
> that you may not find exactly two endpoints.  For the deviance-based
> intervals, a unimodal likelihood is sufficient to guarantee there are
> exactly two places where the deviance differs from the maximum by the
> desired amount.

Not quite, it could level off and never reach the amount. And I believe the 
unimodality needs to hold for the _profiled_ likelihood. Not sure it is 
actually guaranteed to be true for glm's with non-canonical links.

> Things can be much messier when you are trying to
> get the score divided by its estimated standard error to be 1.96.

Yes. There is a similar issue with nonlinear regression models, although it 
seems that it is  often not that big a problem in practice. 


-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com
"Døden skal tape!" --- Nordahl Grieg

__
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] squared "pie chart" - is there such a thing?

2011-07-23 Thread Thomas Levine
How about just a stacked bar plot?

barplot(matrix(c(3,5,3),3,1),horiz=T,beside=F)

Tom

On Fri, Jul 22, 2011 at 7:14 AM, Naomi Robbins  wrote:
>
> Hello!
> It's a shoot in the dark, but I'll try. If one has a total of 100
> (e.g., %), and three components of the total, e.g.,
> mytotal=data.frame(x=50,y=30,z=20), - one could build a pie chart with
> 3 sectors representing x, y, and z according to their proportions in
> the total.
> I am wondering if it's possible to build something very similar, but
> not on a circle but in a square - such that the total area of the
> square is the sum of the components and the components (x, y, and z)
> are represented on a square as shapes with right angles (squares,
> rectangles, L-shapes, etc.). I realize there are many possible
> positions and shapes - even for 3 components. But I don't really care
> where components are located within the square - as long as they are
> there.
>
> Is there a package that could do something like that?
> Thanks a lot!
>
> -
>
> I included waffle charts in Creating More Effective Graphs.
> The reaction was very negative; many readers let me know
> that they didn't like them. To create them I just drew a table
> in Word with 10 rows and 10 columns. Then I shaded the
> backgrounds of cells so for your example we would shade
> 50 cells one color, 30 another, and 20 a third color.
>
> Naomi
>
> -
>
>
> Naomi B. Robbins
> 11 Christine Court
> Wayne, NJ 07470
> 973-694-6009
>
> na...@nbr-graphs.com 
>
> http://www.nbr-graphs.com
>
> Author of Creating More Effective Graphs
> 
>
> //
>
>
>
>        [[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] Extracting components from a 'boot' class output in R

2011-07-23 Thread Tim Hesterberg
Do
  names(bootObj)
to find out what the components are, and use $ or [[ to extract
components.
Do
  help(boot)
for a description of components of the object (look in the Value section).

That is general advice in R, applying to all kinds of objects -
boot, and many other functions such as lm(), return lists with
a class added, and you can operate on the object as a list using
names(), $, etc.

Tim Hesterberg

>Dear R user,
>
>I used the following to do a bootstrap.
>
>
>>bootObj<-boot(data=DAT, statistic=Lp.est,
>R=1000,x0=3)
>
>I have the following output from the above bootstrap. How
>can I extract  components of the output.
>For example, how can I extract the std.error?
>
>
>> bootObj
>
>ORDINARY NONPARAMETRIC BOOTSTRAP
>
>Call:
>boot(data = DAT, statistic = Lp.est, R = 1000, x0 = 3)
>
>Bootstrap Statistics :
>  original    bias  std. error
>t1*  794.9745 -0.341    4.042099
>
>Any help is greatly appreciated.
>
>Thank you
>
>
>Sarath Banneheka

__
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] Extend my code to run several data at once.

2011-07-23 Thread EdBo
Hi

I have a code that calculate maximisation using optimx and it is working
just fine. I want to extend the code to run several colomns of R_j where j
runs from 1 to 200. If I am to run the code in its current state, it means I
will have to run it 200 times manually. May you help me adjust it to
accomodate several rows of R_j and print the 200 results.

***Please do not get intimidated by the maths in the code.***

my code
##
afull=read.table("D:/hope.txt",header=T)
library(optimx) 
llik = function(x) 
   { 
al_j=x[1]; au_j=x[2]; sigma_j=x[3];  b_j=x[4]
sum(na.rm=T,
ifelse(a$R_j< 0, log(1 / ( sqrt(2*pi) * sigma_j) )-
   (1/( 2*sigma_j^2 ) ) * ( 
(a$R_j+al_j-b_j*a$R_m)^2 ) , 

 ifelse(a$R_j>0 , log(1 / ( sqrt(2*pi) * sigma_j) )-
   (1/( 2*sigma_j^2 ) ) * ( 
(a$R_j+al_j-b_j*a$R_m)^2 ) ,

log(ifelse (( pnorm (au_j, mean=b_j * a$R_m, 
sd= sqrt(sigma_j^2))-
   pnorm(al_j, mean=b_j * a$R_m, sd=sqrt
(sigma_j^2)) ) > 0,

(pnorm (au_j,mean=b_j * a$R_m, sd= 
sqrt(sigma_j^2))-
   pnorm(al_j, mean=b_j * a$R_m, sd= sqrt(sigma_j^2)
)),
1) ) ) )
  )
   } 
start.par = c(-0.01,0.01,0.1,1) 

#looping now
runs=133/20+1


out <- matrix(NA, nrow = runs, ncol = 4,

dimnames = list(paste("Qtr:", 1:runs , sep = ''),

c("al_j", "au_j", "sigma_j", "b_j"))) 

  
## Estimate parameters based on rows 0-20, 21-40, 41-60 of afull
for (i in 1:runs) {
index_start=20*(i-1)+1
index_end= 20*i
a=afull[index_start:index_end,]
out[i, ] <- optimx(llik,par = start.par,method = "Nelder-Mead",
control=list(maximize=TRUE) )[[1]][[1]]
} 

## Yields 
> out
   al_jau_j sigma_jb_j
Qtr:1  0.0012402032 0.001082986 0.012889809 1.14095125
Qtr:2  0.0011302178 0.582718275 0.009376083 0.06615565
Qtr:3  0.0013349347 0.417495301 0.013286103 0.60548903
Qtr:4 -0.0016659441 0.162250321 0.015088915 0.67395511
Qtr:5  0.0043159984 0.004315976 0.013153039 1.17341907
Qtr:6  0.0027333033 0.527280348 0.018423347 0.53905153
Qtr:7 -0.0009214064 0.749695104 0.008730072 0.02108032
> 









--
View this message in context: 
http://r.789695.n4.nabble.com/Extend-my-code-to-run-several-data-at-once-tp3688823p3688823.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] Create a map

2011-07-23 Thread Amy Ruiz
 Hello:
I'm using the library of maps, however, I need to use a map of Puerto Rico, but
apparently does not exist. I wanted to know if there is any way that I
can create
that map?

Thanks,
Amy


-- 
*Amy A. Ruiz Goyco*
*Universidad de Puerto Rico*
*Recinto de Río Piedras*

[[alternative HTML version deleted]]

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


[R] R on Android, at least on DOS

2011-07-23 Thread zcatav
Hello,
Is there a version of R running on Android? I wonder R Project ported to
Android.
If this isn't, a DOS version may be helpfull to run on Android under dosbox.
After a little googling i can't find a soluiton.
Thanks.


--
View this message in context: 
http://r.789695.n4.nabble.com/R-on-Android-at-least-on-DOS-tp3688847p3688847.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] Create a map

2011-07-23 Thread Amy Ruiz Goyco
Hello:
I'm using the library of maps, however, I need to use a map of Puerto Rico, but 
apparently does not exist. I wanted to know if there is any way that I can 
create that map?  

Thanks,
Amy
[[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] FIGARCH

2011-07-23 Thread prashant joshi
I am working on stock market volatility. I now need to apply "FIGARCH" model
using R. I need garchOxFit  package to support R in applying FIGARCH to my
data set.
Please help.
Looking forward for your reply,
With regards,
Prashant

[[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] call a function with explicitly not setting an argument

2011-07-23 Thread jeroen00ms
Is there a way to call a function, and explicitly set an argument to 'not
specified'? My situation is the following. I have a function which passes on
most of its arguments to another function. The second function, myfun2,
serializes all arguments and is out of my control. 

myfun <- function(...){
  return(myfun2(...));
}

now, the value for arguments of myfun are stored in variables. Say I want to
call it with arguments 'foo' and 'bar', which are stored in variables
'myfoo' and 'mybar'. So in my script I call

myfun(foo=myfoo, bar=mybar);

However, I also want to be able to call myfun2 without any arguments. Is
there any value that I can assign to myfoo and mybar, so that
myfun(foo=myfoo, bar=mybar); is identical to myfun();





--
View this message in context: 
http://r.789695.n4.nabble.com/call-a-function-with-explicitly-not-setting-an-argument-tp363p363.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] inside p value 'e'

2011-07-23 Thread xy
Hi could some one please tell me what can identfy my numbers ?
I have like 5.075e-12 , 3.207e-05, 7.438e-07 and 9.393e-08 *** , i dont know
what number they are correspond to? help pls!!

thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/inside-p-value-e-tp3688961p3688961.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] glmnet with binary logistic regression

2011-07-23 Thread fongchun
Hi Patrick, 

Thanks for the reply.  I am referring to using the cv.glmnet() function with
10-fold cross validation and letting glmnet determine the lambda sequence. 
The optimal lambda that it is returning fluctuates between different runs of
cv.glmnet.  Sometimes the model that is return deviates from like including
anywhere from 3-25 predictor variables (I am doing LASSO and I originally
had 235 predictor variables).  I will try the foldid option.  

I was also thinking of a bootstrapping approach where I would actually run
cv.glmnet say 100 times and then take the mean/median lambda across all the
cv.glmnet runs.  This way I generate a confidence interval for my optimal
lambda I woud use in the end.

Another question that I have is I am currently using glmnet to help me fit a
two-class predictor (binary logistic regression).  The cv.glmnet() function
has a type.measure parameter which can be set to auc.  If I am understanding
this correctly, for each lambda it is doing 10 cross-validation and at each
fold it is calculating an AUC.  Therefore, the cross-validation score for
this lambda is the AVERAGE auc across all folds?  Or is it they pool the
predicted response values from each fold and then generate one ROC on all
the predicted values?

Thanks,

Fong



--
View this message in context: 
http://r.789695.n4.nabble.com/glmnet-with-binary-logistic-regression-tp3688126p3689024.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] analizing .txt file with R or an other program

2011-07-23 Thread aRe
Hello together

I have a .txt file with about 1Mio! rows.

Sometimes the rows are in the following order (whereas the number of rows
between the rows marked with an x differ):

...
*SBLINK R 5261507*x
5261439   516.4   364.3  9148.0 ...   816.0 -1133.048.4 MA.C.TB...BL.
5261441   516.4   364.0  9145.0 ...   799.0 -1135.048.7 MA.C.TB...B..
5261443   516.4   363.9  9140.0 ...   817.0 -1171.049.3 MA.C.TB.R
*MSG5261445 Prime 11_fe_ha*x
5261445   516.7   363.8  9133.0 ...   813.0 -1097.049.3 MA.C.TB..
5261447   517.0   363.8  9127.0 ...   818.0 -1144.049.9 MA.C.T.LRTB..
*EBLINK R 5261507   5261645 140*x
5261509.   .0.0 ....   .   . .
5261511.   .0.0 ....   .   . .
*MSG5261512 Mask 8_ma_ma*x
5261513.   .0.0 ....   .   . .
5261515.   .0.0 ....   .   . .
...

Here I would like to generate an output, that gives me the two parts
"...Prime 11_fe_ha" and "...Mask 8_ma_ma" if and only if "...Prime 11_fe_ha"
is situated between "SBLINK..." and "EBLINK...".




Sometimes the rows are in the following order (whereas the number of rows
between the rows marked with an x differ):

...
*MSG5261445 Prime 11_fe_ha*x
5261439   516.4   364.3  9148.0 ...   816.0 -1133.048.4 MA.C.TB...BL.
5261441   516.4   364.0  9145.0 ...   799.0 -1135.048.7 MA.C.TB...B..
5261443   516.4   363.9  9140.0 ...   817.0 -1171.049.3 MA.C.TB.R
*SBLINK R 5261507*x5261445516.7   363.8  9133.0 ...   813.0 -1097.0 
  
49.3 MA.C.TB..
5261447   517.0   363.8  9127.0 ...   818.0 -1144.049.9 MA.C.T.LRTB..
*EBLINK R 5261507   5261645 140*x
5261509.   .0.0 ....   .   . .
5261511.   .0.0 ....   .   . .
*MSG5261512 Mask 8_ma_ma*x
5261513.   .0.0 ....   .   . .
5261515.   .0.0 ....   .   . .
...

Here I would like to generate an output, that consists of the two parts
"...Prime 11_fe_ha" and "...Mask 8_ma_ma" if and only if "SBLINK..." is
situated between "... Prime 11_fe_ha" and "...Mask 8_ma_ma". The place of
the "EBLINK..." is not important. that means also the following structure
should lead to the same output:

...
*MSG5261445 Prime 11_fe_ha*x
5261439   516.4   364.3  9148.0 ...   816.0 -1133.048.4 MA.C.TB...BL.
5261441   516.4   364.0  9145.0 ...   799.0 -1135.048.7 MA.C.TB...B..
5261443   516.4   363.9  9140.0 ...   817.0 -1171.049.3 MA.C.TB.R
*SBLINK R 5261507*x5261445516.7   363.8  9133.0 ...   813.0 -1097.0 
   
5261447   517.0   363.8  9127.0 ...   818.0 -1144.049.9 MA.C.T.LRTB..
5261509.   .0.0 ....   .   . .
5261511.   .0.0 ....   .   . .
*MSG5261512 Mask 8_ma_ma*x
5261513.   .0.0 ....   .   . .
5261515.   .0.0 ....   .   . .
*EBLINK R 5261507   5261645 140*x
...


can someone give me a advice how I could manage this task?

thanks

best



--
View this message in context: 
http://r.789695.n4.nabble.com/analizing-txt-file-with-R-or-an-other-program-tp3689025p3689025.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] Create a map

2011-07-23 Thread Amy Ruiz
 Hello:
I'm using the library of maps, however, I need to use a map of Puerto Rico, but
apparently does not exist. I wanted to know if there is any way that I
can create
that map?

Thanks,
Amy


-- 
*Amy A. Ruiz Goyco*
*Universidad de Puerto Rico*
*Recinto de Río Piedras*

[[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] Trouble getting plot to appear

2011-07-23 Thread cherron
I thought that might have been the case also, but after opening the pdf it's
not there either.

When I restart R it works again.

On Fri, Jul 22, 2011 at 6:32 PM, Daniel Malter [via R] <
ml-node+3688227-1927904147-254...@n4.nabble.com> wrote:

> Typically not, unless the device has not closed properly. Does the second
> plot show up in the pdf?
>
> Daniel
>
> cherron wrote:
> Hello,
>
> >I am currently working on a script and I output plots to pdf using
>
> pdf(...)
> plot(...)
> dev.off()
>
> >then later I was trying to plot something and when I run just
>
> plot(...)
>
> >nothing appears. Is there something about using plot(..) after dev.off()
> that does not allow the window to pop up? In other words I would like to be
> able to see the plot display when just using the plot function. I am using R
> in UNIX if this is at all relevant.
>
> Many thanks,
>
> Casey
>
>
>
> --
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://r.789695.n4.nabble.com/Trouble-getting-plot-to-appear-tp3688078p3688227.html
>  To unsubscribe from Trouble getting plot to appear, click 
> here.
>
>


--
View this message in context: 
http://r.789695.n4.nabble.com/Trouble-getting-plot-to-appear-tp3688078p3689195.html
Sent from the R help mailing list archive at Nabble.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] Fit elipse to xy scatter

2011-07-23 Thread Rolf Turner


(1) The ellipse package, according to its DESCRIPTION file, is a package of
``Functions for drawing ellipses and ellipse-like confidence regions''.  
It has

nothing to do with *fitting* ellipses.

(2) What on earth do you mean by ``fit an elipse (sic) to two lines of 
identity''?


(3) There are (infinitely) many ellipses that could be associated with a 
scatter
plot such as that displayed in the figure you refer.  (E.g. confidence 
ellipses or
predication ellipses, one of each for each level of confidence.) You 
will have to

be much clearer and much more precise about what you wish to accomplish
in order to get any help.

cheers,

Rolf Turner


On 23/07/11 11:44, DrCJones wrote:

Hi,

I know there is a package 'elipse' available but I'm not sure how to use it
for my specific implementation.


What I would like to do is fit an elipse to two lines of identity (at right
angles to each other), as indicated in the following figure:
http://imageshack.us/photo/my-images/30/poincareplotwip.png/

Conceptually, I'm really struggling to even come up with a way of doing
this, let alone an implementation.

Would really appreciate some pointers :)


--
View this message in context: 
http://r.789695.n4.nabble.com/Fit-elipse-to-xy-scatter-tp3688117p3688117.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] inside p value 'e'

2011-07-23 Thread xy
Thank you :)

--
View this message in context: 
http://r.789695.n4.nabble.com/inside-p-value-e-tp3688961p3689418.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] An infinite recursion error please explain!

2011-07-23 Thread mousy0815
In response to the second question about the placement of D<=t, there are two
instances of it: once after the comment "starts inside node" (After the line
with the comment "start & end in first node") and one after "starts outside
node." Did that answer the question? 

I don't know if this helps, but I originally had it in terms of just "m"
time steps (its below; the changed parts are highlighted), but I wanted to
convert it into actual time "w." That's when the problem started.

Probability <- function(N, f, m, b, y, t) {
#N is the number of lymph nodes (500-600)
#f is the fraction of Dendritic cells (in the correct node) that have 
the
antigen
#m is the number of time steps
#b is the starting position (somewhere in the node or somewhere in the 
gap
between nodes. It is a number between 1 and (x+t))
#y is the number of time steps it takes to traverse the gap
#t is the number of time steps it takes to traverse a node. 
A <- 1/N
B <- 1-A
C <- 1-f
D <- (((m+b-1)%%(y+t))+1)

if (b<=t) {starts inside node
if (m<=(t-b)){return(B + A*(C^m))} # start & end in 
first node  
if (D<=t) { # we finish in a node
a <- (B + A*(C^(t-b))) #first node
b <- ((B + A*(C^t))^(floor((m+b)/(y+t))-1))  # 
intermediate nodes (if
any)
c <- (B + A*(C^D))  # last node   
return(a*b*c)
} else {return(Probability(N, f, *(m-1)*, b, y, 
t))} ## finish in a gap 
} else {## starts outside node
if (m<=(y+t-b)) {return(1)} #also end in the gap
if (D<=t) { #end in a node
b <- ((B + A*(C^t))^(floor((m/(y+t)
c <- (B + (A*(C^D)))
return(b*c)
} else {return(Probability(N, f, *(m-1)*, b, y, 
t))} #outside node
}
}

I changed (m-1) to (m*q-q) in order to get the same effect, but perhaps it
had some adverse effect?

I still don't know how to fix this... 

--
View this message in context: 
http://r.789695.n4.nabble.com/An-infinite-recursion-error-please-explain-tp3688260p3689597.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] An infinite recursion error please explain!

2011-07-23 Thread mousy0815
edit: I fixed it; apparently I needed to change the ceiling(w/q) to w%/%q,
though I'm not really sure why that made such a difference.

--
View this message in context: 
http://r.789695.n4.nabble.com/An-infinite-recursion-error-please-explain-tp3688260p3689621.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] call a function with explicitly not setting an argument

2011-07-23 Thread Joshua Wiley
On Sat, Jul 23, 2011 at 6:31 AM, jeroen00ms  wrote:
> Is there a way to call a function, and explicitly set an argument to 'not
> specified'? My situation is the following. I have a function which passes on
> most of its arguments to another function. The second function, myfun2,
> serializes all arguments and is out of my control.
>
> myfun <- function(...){
>  return(myfun2(...));
> }
>
> now, the value for arguments of myfun are stored in variables. Say I want to
> call it with arguments 'foo' and 'bar', which are stored in variables
> 'myfoo' and 'mybar'. So in my script I call
>
> myfun(foo=myfoo, bar=mybar);
>
> However, I also want to be able to call myfun2 without any arguments. Is
> there any value that I can assign to myfoo and mybar, so that
> myfun(foo=myfoo, bar=mybar); is identical to myfun();

I am not aware of any (which is not to say there is not), but what
about catching ... between myfun and myfun2, and removing the
arguments you do not want passed on?  I had something like this in
mind:

myfun2 <- function(test, ...) {
  cat(missing(test), fill = TRUE)
  cat(..., fill = TRUE)
}

myfun <- function(...) {
  d <- list(...)
  index <- sapply(d, identical, y = "RemoveMe")
  d <- d[!index]
  do.call(myfun2, d)
}

myfun(foo = 1, test = "hi")
myfun(foo = 1, test = "RemoveMe")


Josh



>
>
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/call-a-function-with-explicitly-not-setting-an-argument-tp363p363.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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.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.