Re: [R] how to speed up this for loop?

2008-07-22 Thread bartjoosen

I'm not sure if I understand correct, but maybe something like:

apply(dat,2,function(x) sum(x[x<0]))

Please do read the posting guide and post a small, working example!!!

Bart


Rheannon wrote:
> 
> Could anyone tell me a better way to achieve the output of this for loop?
> It seems to run quite slow. I'm sure there must be a more consise way to
> sum from FN to LN, excluding positive values, for each row.
> 
> #sum between FN and LN, excluding positive values
> for(i in 1:R){
> for(j in FN[i]:LN[i]){
> if(Temp[i,j]<0)
> sum[i] <- sum[i] + sum(Temp[i,j])}}
> 
> Cheers, 
> R
> 

-- 
View this message in context: 
http://www.nabble.com/how-to-speed-up-this-for-loop--tp18579577p18584610.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 command history -- can it be like Matlab's?

2008-07-30 Thread bartjoosen

Here is the post where Prof Ripley is reffering to:
http://tolstoy.newcastle.edu.au/R/e2/help/07/09/26668.html


Bart


losemind wrote:
> 
> 
> 
> Prof Brian Ripley wrote:
>> 
>> A patch to do this was posted on 2007-09-29 by Glenn Davis.  Some people 
>> not addicted to Matlab find the behaviour very inconvenient and prefer
>> the 
>> getline/readline behaviour (triggered by ^R/^S) of Rterm and R on Unixen.
>> 
>> On Tue, 29 Jul 2008, losemind wrote:
>> 
>>>
>>> Hi all,
>>>
>>> In R GUI window, if you use "up" and "down" key, you will be able to
>>> recall
>>> the previous and next command that has been used and stored in the
>>> command
>>> history cache.
>>>
>>> But there is one inconvenience:
>> 
>> Or an inconvenience of Matlab not shared by R, depending on your 
>> preferences.
>> 
>>> In Matlab, you can type the first a few characters of the command that
>>> you
>>> previously used,
>>>
>>> and then press “up" key, you will be able to get to that previous
>>> command
>>> very fast,
>>>
>>> no matter how long ago it has been used...
>>>
>>> In R GUI, there is no such functionality.
>>>
>>> Any thoughts on making R work my productivity?
>>>
>>> --
>>>
>>> Also where do I find good debugger for R?
>>>
>>> Thanks!
>>> -- 
>>> View this message in context:
>>> http://www.nabble.com/R-command-historycan-it-be-like-Matlab%27s--tp18719530p18719530.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.
>>>
>> 
>> -- 
>> Brian D. Ripley,  [EMAIL PROTECTED]
>> 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.
>> 
>> 
> 
> 
> 
> Hi,
> 
> I don't find Glenn Davis's patch... where is it?
> 
> I like that Matlab feature. And I am using R GUI on windows...
> 
> Please help me!
> 
> Please also give me pointers to good R debuggers?
> 
> Thanks!
> 
> 

-- 
View this message in context: 
http://www.nabble.com/R-command-historycan-it-be-like-Matlab%27s--tp18719530p18728916.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] Opening R from Tinn without setting directory each time

2008-08-06 Thread bartjoosen

If you first install a newer version of R and aftwards remove a previous
version, Tinn-R gives this behaviour. Doesn't matter if you activate the
option to register.

Best regards

Bart


Philippe Grosjean wrote:
> 
> 
> Paul Chatfield wrote:
>> Hi - someone has just e-mailed me direct with the answer which it'd be
>> helpful to paste just so future users who have the same issue can see. 
>> Just
>> follow the advice below and it works perfectly.
>> 
>> Open a command window (Run;cmd) and cd to the bin directory of your R
>> installation (cd C:/Program Files).  Run the program RSetReg.exe and
>> that's it, Tinn-R should be able to start R.  When you update R repeat
>> the
>> process.
> 
> This shouldn't be needed if you activate the option to register the 
> installed/upgraded version of R in the registry (somewhere at the end of 
>   the installer's questions).
> Best,
> 
> Philippe Grosjean
> 
>> 
>> Paul Chatfield wrote:
>>> Hi - I can access R from Tinn-R by going to Options->Main->Application/R
>>> and setting the search path, but each time I exit Tinn-R I have to
>>> redefine the search path.  Is there no way of fixing that directory as
>>> default?  I have installed R under its default directory C:/Program
>>> Files/R/R-2.7.1 and Tinn under a variety of different places to try to
>>> rectify the problem though currently under C:/Program Files/Tinn-R.  Any
>>> ideas what I'm missing?
>>>
>>> Thanks
>>>
>>> Paul
>>>
>>
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Opening-R-from-Tinn-without-setting-directory-each-time-tp18830678p18852134.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] Trying to run simple survival program in R but does not work

2008-08-07 Thread bartjoosen

When I run your code, I have no problem at all, could you please give us some
more info about what system you are running on, OS, packages loaded, .

Bart


Trev101 wrote:
> 
> Hey,
> 
> I am just starting to learn R now and I typed in this simple survival
> program:
>   
>library(survival)
>t <- c(10,13,18,19,23,30,36,38,54,56,59,75,93,97,104,107,107,107)
>c <- c(1,0,0,1,0,1,1,0,0,0,1,1,1,1,0,1,0,0)
>data <- Surv(t,c)
>km <- survfit(data)   
>summary(km)
>Call: survfit(formula = data)
> 
> but everytime I run it I get this error:
>   
>   Error in eval.with.vis(expr, envir, enclos) : object "Call" not found
> 
> Can someone please help me out I really have no idea wat I have done
> wrong. I have installed the survival library is there maybe some other
> library I need to install?
> 

-- 
View this message in context: 
http://www.nabble.com/Trying-to-run-simple-survival-program-in-R-but-does-not-work-tp18865807p18866431.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] Trying to run simple survival program in R but does not work

2008-08-07 Thread bartjoosen

Survival depends on splines, so you should install the splines library, and
then everything should be fine.

Bart


Trevor Hansen wrote:
> 
> Oh wait it gives me another error saying that: 
> Loading required package: splines
> 
> I cant find the package called splines in the list is that an important
> package?
> 

-- 
View this message in context: 
http://www.nabble.com/Trying-to-run-simple-survival-program-in-R-but-does-not-work-tp18865807p18867071.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] maximization under constraits

2008-08-08 Thread bartjoosen

You wrote MAXIMIZE this function, why not using the maximize option of
constrOptim?
If you read the help file, you will find that if you set the control fnscale
to a negative value, maximisation 
is performed.

constrOptim(c(1,1),neg_loglik, grad=NULL, ui=rbind(c(1,0),c(0,1)),
ci=c(0,0),control=list(fnscale=-1))


Best regards

Bart




babydany84 wrote:
> 
> I'm an Italian student looking for help.
> 
>  
> 
> How can I maximize this function? 
> 
>  
> 
>  neg_loglik<-function(param){
> 
>a<-param[1]
> 
>b <-param[2]
> 
> -(log(pr)-(a*s2)-(b*s)+n*log(2*a)-n*log(1-(b/sqrt(a))*exp((b^2)/(4*a))*(sqrt
> (pi))*(1-pnorm(b/(2*sqrt(a)), mean=0, sd=1))*1))
> 
> }
> 
>  
> 
> Con 
> 
>> pr
> 
> [1] 4.37124e+113
> 
>> s2
> 
> [1] 270486
> 
>> s
> 
> [1] 3646
> 
>> n
> 
> [1] 71
> 
>> 
> 
>  
> 
>  
> 
> Is a -(loglikelihood function), the parameter a e b are positive.
> 
> I've used the function 
> 
>  
> 
> max<-constrOptim(c(1,1),neg_loglik, 
> 
> grad=NULL,
> 
> ui=rbind(c(1,0),c(0,1)), ci=c(0,0))
> 
>  
> 
> but without success cause I think the max is only local.
> 
>  
> 
> Great wishes
> 
>  
> 
> Daniela
> 
>  
> 
>  
> 
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/maximization-under-constraits-tp18870935p18890806.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] ANOVA tables - storing F values

2008-08-12 Thread bartjoosen

Hi,

lets look at an example:
fit <- lm(sr ~ ., data = LifeCycleSavings)
fit.anova <- anova(fit)

you can see the structure from the anova:
str(fit.anova)

Classes ‘anova’ and 'data.frame':   5 obs. of  5 variables:
 $ Df : int  1 1 1 1 45
 $ Sum Sq : num  204.1  53.3  12.4  63.1 650.7
 $ Mean Sq: num  204.1  53.3  12.4  63.1  14.5
 $ F value: num  14.116  3.689  0.858  4.360 NA
 $ Pr(>F) : num  0.000492 0.061125 0.359355 0.042471   NA
 - attr(*, "heading")= chr  "Analysis of Variance Table\n" "Response: sr"


Here you see that you can acces the F values by typing: fit.anova$"F value"
or by fit.anova[,"F value"]
Use the same method for your p-values.

the other way you mentioned brings you to the same methods:
attributes(fit.anova)

$names
[1] "Df"  "Sum Sq"  "Mean Sq" "F value" "Pr(>F)" 

$..


Best regards

Bart
-- 
View this message in context: 
http://www.nabble.com/ANOVA-tables---storing-F-values-tp18937255p18939847.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] Simple look up

2008-08-22 Thread bartjoosen

Please take a look at the manuals before posting (DO read the posting guide!)

Bart
PS: yourdataframe[yourdataframe$TAZ==103,2]





PDXRugger wrote:
> 
> So i am hoping this solution is simple, which i beleive it is.  I would
> like to look up a value in one column of a data set and display the
> corresponding value in the 2nd column.  For example
> TAZVACANT ACRES
> 100   45
> 101   62
> 102   23
> 103   64
> 104   101
> 105   280
> 
> So if i want to find TAZ 103 it would give me 64 as the corresponding
> value.  Hope you guys can help
> 
> Cheers
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Simple-look-up-tp19098777p19103028.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] Upgrading R means I lose my packages

2008-08-29 Thread bartjoosen

On my windows XP machine, if you uninstall R-2.7.1, the libraries which
doesn't come with the original installation remain in the folder C:\Program
Files\R\R-2.7.1\library.
So I first uninstall R-2.7.1, then install R-2.7.2, copy the remaining
packages from the R-2.7.1 folder to the R-2.7.2 library folder.
In R update packages.

Bart



Robert A LaBudde wrote:
> 
> At 04:12 AM 8/28/2008, ONKELINX, Thierry wrote:
> 
>>On a windows machine you get the same problem. Useless one uses tha same
>>trick as Rolf suggested: don't install the packages in the default
>>directory and set R_LIBS to that directory. Then all you need to do
>>after an upgrade is to set R_LIBS in the new version and run
>>update.package(checkBuilt = TRUE). Given Rolf's suggestion I suppose
>>this trick will work on a Mac too.
> 
> What I do in installing a new version of R on a Windows system is as
> follows:
> 
> 1. In the "c:\Program Files\R" folder, the installation is in a 
> subfolder labeled by the version, such as "R-2.7.1".
> 
> 2. I leave the old (say, 2.7.1) version installed, and install the 
> new version (say, 2.7.2). This leaves the old subfolder "R-2.7.1" 
> intact, and creates a new one "R-2.7.2".
> 
> 3. I use a file-compare utility (in my case, Beyond Compare, which I 
> recommend), to compare the subfolders "C:\Program 
> Files\R\R-2.7.1\library" and "C:\Program Files\R\R-2.7.2\library". I 
> set the comparison to find files present or newer in the 2.7.1 folder 
> vs. the 2.7.2. Then I copy all such files over.
> 
> 4. At this point, the 2.7.2 has the same or new packages than 2.7.1, 
> most or all of which will work.
> 
> 5. I use the "Packages|Update Package ..." to update packages to 2.7.2.
> 
> 6. Then I delete the 2.7.1 subfolder.
> 
> You need Administrator rights to do this.
> 
> 
> 
> 
> 
> Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: [EMAIL PROTECTED]
> Least Cost Formulations, Ltd.URL: http://lcfltd.com/
> 824 Timberlake Drive Tel: 757-467-0954
> Virginia Beach, VA 23464-3239Fax: 757-467-2947
> 
> "Vere scire est per causas scire"
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Upgrading-R-means-I-lose-my-packages-tp19193056p19216548.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] convenient way to calculate specificity, sensitivity and accuracy from raw data

2008-09-01 Thread bartjoosen

Dear Felix,

I have no idea about the calculation of your accuracy, sensitivity, etc, but
the sums:

dat <- read.table(file="clipboard") #read in your data as dataframe dat
dat$comp <- apply(dat,1,function(x) sum(x[-c(1,22)]==as.numeric(x[22])))

Good luck

Bart


drflxms wrote:
> 
> Dear R-colleagues,
> 
> this is a question from a R-newbie medical doctor:
> 
> I am evaluating data on inter-observer-reliability in endoscopy. 20
> medical doctors judged 42 videos filling out a multiple choice survey
> for each video. The overall-data is organized in a classical way:
> observations (items from the multiple choice survey) as columns, each
> case (identified by the two columns "number of medical doctor" and
> "number of video") in a row. In addition there is a medical doctor
> number 21 who is assumed to be a gold-standard.
> 
> As measure of  inter-observer-agreement I calculated kappa according to
> Fleiss and simple agreement in percent using the routines
> "kappam.fleiss" and "agree" from the irr-package. Everything worked fine
> so far.
> 
> Now I'd like to calculate specificity, sensitivity and accuracy for each
> item (compared to the gold-standard), as these are well-known and easy
> to understand quantities for medical doctors.
> 
> Unfortunately I haven't found a feasible way to do this in R so far. All
> solutions I found, describe calculation of specificity, sensitivity and
> accuracy from a contingency-table / confusion-matrix only. For me it is
> very difficult to create such contingency-tables / confusion-matrices
> from the raw data I have.
> 
> So I started to do it in Excel by hand - a lot of work! When I'll keep
> on doing this, I'll miss the deadline. So maybe someone can help me out:
> 
> It would be very convenient, if there is way to calculate specificity,
> sensitivity and accuracy from the very same data.frames I created for
> the calculation of kappa and agreement. In these data.frames, which were
> generated from the overall-data-table described above using the
> "reshape" package, we have the judging medical doctor in the columns and
> the videos in the rows. In the cells there are the coded answer-options
> from the multiple choice survey. Please see an simple example with
> answer-options 0/1 (copied from R console) below:
> 
>  video 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
> 1  1 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 2  2 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  1
> 3  3 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 4  4 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 5  5 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  1  0
> 6  6 0 0 0 0 0 0 0 0 0  0  0  0  0  1  0  0  0  0  0  0  0
> 7  7 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 8  8 0 0 0 0 0 0 0 0 0  0  0  0  0  0  1  0  0  0  0  0  0
> 9  9 0 0 0 0 0 0 0 0 0  1  0  1  1  0  1  1  0  0  0  1  0
> 1010 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 1111 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 1212 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 1313 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 1414 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 1515 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 1616 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 1717 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 1818 0 0 0 0 1 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  1
> 1919 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 2020 0 1 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 2121 0 0 0 0 0 0 1 0 0  0  0  0  0  0  0  0  0  0  0  0  1
> 2222 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 2323 0 1 0 0 1 0 1 0 0  1  0  0  1  1  0  0  1  0  0  0  0
> 2424 0 0 0 0 0 0 0 0 0  0  0  0  1  1  1  1  0  1  0  0  1
> 2525 0 0 0 0 0 0 0 0 0  0  0  1  0  0  1  1  0  0  0  0  0
> 2626 0 0 0 0 0 0 0 0 0  0  0  1  0  0  0  0  0  0  0  0  0
> 2727 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 2828 0 1 0 1 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 2929 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 3030 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 3131 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 3232 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 3333 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 3434 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 3535 0 0 0 0 0 0 1 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 3636 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 3737 0 1 1 0 1 0 0 1 0  0  0  0  1  1  1  0  1  0  0  1  1
> 3838 0 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0
> 3939 0 1 0 0 1 0 0 1 0  1  1  0  1  1  0  0  1  1  0  1  1
> 4040 1 1 1 1 1 0 1 0 0  0  0  1  1  1  1  0  0  1  0  0  1
> 4141 0 0 0 0 0 0 0 0 0  1  0  0  0  

Re: [R] manipulating text to generate different formulas to use in nls()

2009-08-11 Thread bartjoosen

Take a look at ?eval

Bart


Héctor Villalobos-2 wrote:
> 
> Hello,
> 
> In doing a series of non-linear estimations of a function which is a sum
> of a varying number 
> of sinusoids, I would like to "autogenerate" the arguments needed by nls()
> depending on that 
> number.
> 
> For example, when there are two sinusoids: 
> 
>   > nls( y ~ mu + A1 * cos(2*pi*f1*x - P1) + A2 * cos(2*pi*f2*x - P2),
> data = some.xy.data, 
> start = list( mu=some.value0, A1=some.value1, P1=some.value2,
> A2=some.value3,
>  P2=some.value4, f1=some.value5, f2=some.value6  ) 
> )
> 
>  Adding a third sinusoid, the model and the starting parameters needed
> become:
> 
>   > nls( y ~ mu + A1 * cos(2*pi*f1*x - P1) + A2 * cos(2*pi*f2*x - P2) + A3
> * cos(2*pi*f3*x - P3), 
> data = some.xy.data, start = list( mu=some.value0,
> A1=some.value1,
> P1=some.value2, A2=some.value3, P2=some.value4,
> A3=some.value5,
> P3=some.value6, f1=some.value7, f2=some.value8, f3=some.value9
> )
> 
> 
> So far, I managed to create the "building blocks" I need but when it comes
> to defining their 
> number I still haven't found a solution (see the following code).
> 
> ##  some fake starting values
> par.ini <- data.frame(period=1:5, invR=1:5, a0=1:5, Amplitude=1:5,
> Phase=1:5)
> 
>   n <- nrow(par.ini) - 1# I'm not interested in
> the last harmonic
>   inip <- par.ini[1:n, c(1, 3:5)] # neither in the second
> column
> amps <- paste("A", 1:n, sep="")
> phas <- paste("P", 1:n, sep="")
> freqs <- paste("f", 1:n, sep="")
> 
>  ( premodl <- paste(amps, " * cos(2*pi*", freqs, "*x - ", phas, ")",
> sep="") )
> 
> 
> ## In the two following instructions, "modl" and "initP" are defined by
> hand. This is what I 
> want to generate "automagically" depending on the number of harmonics (n).
> 
>  ( modl <- paste("y ~ mu", premodl[1],premodl[2], premodl[3], premodl[4],
> sep=" + ") ) 
> 
>  ( initP <- list(mu=sum(inip$a0), 
>   A1=inip$Amplitude[1], P1=inip$Phase[1], 
>   A2=inip$Amplitude[2], P2=inip$Phase[2], 
>   A3=inip$Amplitude[3], P3=inip$Phase[3],   
>   A4=inip$Amplitude[4], P4=inip$Phase[4], 
>   f1=1/inip$period[1], f2=1/inip$period[2],
>   f3=1/inip$period[3], f4=1/inip$period[4])  ) 
> 
> ## not run. These two will be used in
>   res <- nls(modl, data=data.frame(y, x), start=initP)
>  
> 
> 
> Thank you in advance for any insigth.
> 
> Héctor
> 
> 
>  
> -- 
> Héctor Villalobos  
>  CICIMAR - IPN
>  A.P. 592. Col. Centro 
>  La Paz, Baja California Sur, MÉXICO. 23000
>  Tels. (+52 612) 122 53 44; 123 46 58; 123 47 34  ext. 82425
>  Fax.  (+52 612) 122 53 22
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/manipulating-text-to-generate-different-formulas-to-use-in-nls%28%29-tp24907333p24912932.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] executing rscript from VB

2009-09-11 Thread bartjoosen

Maybe I'm missing something, but how about using the shell function?

Bart



Duncan Murdoch-2 wrote:
> 
> On 9/10/2009 9:25 AM, H Rao wrote:
>> Hi,
>> I am looking to execute an R script from VB as  below.
>> The script runs fine but the redirection doesnt seem to happen. The
>> redirection operator and the out file seem to be treated as arguments
>> to the R script. Is there a way to get the > operator working
> 
> That's a VB question.  You should ask Microsoft.
> 
> Duncan Murdoch
> 
>> 
>> thanks, R
>> 
>> System.Diagnostics.Process proc = new System.Diagnostics.Process();
>> proc.StartInfo.FileName = "E:/R/bin/Rscript.exe";
>> proc.StartInfo.Arguments = "E:/R/bin/test.r > test.out";
>> proc.StartInfo.UseShellExecute = true;
>> proc.Start();
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/executing-rscript-from-VB-tp25383342p25396386.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] aproximate a titration kurve to the measure data.

2009-10-01 Thread bartjoosen

Hi,

This should be possible, even with automatic EP detection.
Can you give use some example titration data, or the used matlab code?

If you want some introduction papers to R, take a look at the documents at
CRAN (CRAN > other)

Bart



awayguy wrote:
> 
> Halo
> 
> i'm studying chemistry, today we made an experiment and i have to draw a
> titration kurve for my mess data. we can do it on a mm paper, or we can
> also use a programe. people from chemistry recomend "R"
> last year i studied civil eng. and we used Matlab, as I see, R ist very
> similar to it, but its got other comands.
> But i think R would be a good help for some exercises.
> 
> so my main question is: i have some measurement data from my titration,
> and I want aproximate a kurve to this data. is it possible to do it with
> R?
> 
> a titration kurve looks like this:
> 
>  http://www.nabble.com/file/p25685986/acetic-acid-titration-curve.png 
> 
> hope you can help me, and yes when its possible, if you know something
> like a tutorial then i would be glad if you could post it.
> 
> with regards
> 

-- 
View this message in context: 
http://www.nabble.com/aproximate-a-titration-kurve-to-the-measure-data.-tp25685986p25695773.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] Nelder-Mead with output of simplex vertices

2009-10-13 Thread bartjoosen

Hi,

Is it possible to share the code on this list?
I'm also interested (and maybe others to)
Or are you planning to make a package?

Best regards

Bart



Ted.Harding-2 wrote:
> 
> On 12-Oct-09 13:33:17, Ted Harding wrote:
>> On 12-Oct-09 13:24:01, Terry Therneau wrote:
>>> -- begin included 
>>> Greetings!
>>> I want to follow the evolution of a Nelder-Mead function
>>> minimisation (a function of 2 variables). Hence each simplex
>>> will have 3 vertices.
>>> 
>>> Therefore I would like to have a function which can output
>>> the coordinates of the 3 vertices after each new simplex
>>> is generated. However, there seems to be no way (which I can
>>> detect) of extracting this information from optim() (the 'trace'
>>> argument to 'control' does not seem to have provision for this,
>>> according to '?optim', and I have tried it out without success).
>>> 
>>> --- end include -
>>> 
>>>  Why not put a cat() statement into "fn", the function that you supply
>>> which optim is calling?  That will give the vertices that it tries one
>>> by one.
>>> 
>>> Terry T.
>> 
>> That's neat and simple! It hadn't occurred to me. Thanks!
>> Ted.
> 
> And, 10 seconds after posting, I realised why it hadn't -- there
> would be no visible association between the vertex and the simplex
> (in this instance the triangle) that it belongs to.
> 
> In other words, which two other points in the preceding sequence,
> along with the current one, make up the triangle being tested?
> 
> Given the complexity of the Nelder-Mead process, it would be very
> tricky indeed to try to track this through the sequence of vertices
> which cat() would output.
> 
> As it happens, Ben Bolker kindly sent me code which he wrote (see
> his earlier mail) which does do this nicely, since it has an output
> option within the Nelder-Mead routine itself -- at which point,
> the routine itself knows what the simplex is.
> 
> Ted.
> 
> 
> E-Mail: (Ted Harding) 
> Fax-to-email: +44 (0)870 094 0861
> Date: 12-Oct-09   Time: 14:45:00
> -- 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Nelder-Mead-with-output-of-simplex-vertices-tp25838572p25869383.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] Temperature Prediction Model

2009-10-30 Thread bartjoosen

Hi,

also interested...

If you are checking for non-normal behaviour, first let us define normal
behaviour: only small temperature changes and no steep ramps?

If so, maybe you can make an rolling average of the last x points, and check
if the following point deviates more than ... ?

Or is it more like a trend analysis, to see whether the last variation is a
trend or normal variation?
Then you can take a look at change point analysis.

gl

Bart



Aneeta wrote:
> 
> Thank you Clint for your response. I am happy to know that you have gotten
> interested in this analysis.:-)
> 
> Let me give you some details about sensor networks that would help you
> understand my goal better. Sensor nodes run on small batteries which have
> limited life. So communication amongst various nodes is kept at a minimum
> to preserve battery life. Hence, I am working on a localized analysis
> which each node could perform on its own. 
> 
> The disturbances caused by the malicious nodes would be abrupt and for a
> short span. But please note that the data set that I have supplied is from
> a perfectly working sensor network which is not under any attack. The
> attack model will be simulated separately. I apologize if I have given you
> the idea that the data set consists of noisy data. 
> 
> Ideally I would first like to build a model for the normal behaviour of
> each node from the data set which is at hand. Once we are able to define
> the normal behaviour I could introduce some gorillas and see if we can
> detect that some node is under attack. I have this part figured out.
> 
> I am not looking at a day-of-week dependence. Rather I am looking for a
> time-of-day dependence. We could take into consideration more than 7 days
> of data if that gives us a stronger model. What I was hoping to do was to
> plot the data for the past 7-days on top of each other to get a general
> idea on how the temperature varies throughout the day and thus build an
> equation which would calculate the temperature given the time of the day. 
> 
> Thank you again for your help.
> 
> Best Regards,
> Aneeta
> 
> 
> 
> 
> 
> Clint Bowman wrote:
>> 
>> Aneeta,
>> 
>> My "gorilla and mouse" analogies were referring to the magnitude of 
>> the disturbance and also to its time signature.  Are you only 
>> interested in the large disturbance which is abrupt (the gorilla)? 
>> Or do you also want to be able to detect the more surreptitious 
>> attack which may be quite gradual (the mouse)?
>> 
>> You will want to define the magnitude (and perhaps the associated 
>> duration) of the smallest disturbance that would be important.  I 
>> would look at the entire data set to see what would be the 
>> likelihood of detecting such a change given the noise in the 
>> temperature data.  Or alternatively, use the global analysis to 
>> help define the minimum disturbance that could be detected.
>> 
>> Then see what can be done with just the first 7 days of data (or 
>> for matter the past 7 days regardless of when they occur).
>> 
>> I applaude your goal of looking at each sensor without referring to 
>> other nodes but I think I would develop the analysis by looking for 
>> anomalies in one sensor's data when compared with other sensors and 
>> then focusing on those periods to determine an approach for 
>> detecting a disturbance.
>> 
>> Because you are looking at 7 days, should we assume that you expect 
>> a day-of-week dependence?  If so, I'd be more comfortable if you 
>> used more than one week to develop it.
>> 
>> I fear that you've gotten me quite interested in this analysis, 
>> good luck.
>> 
>> Clint
>> 
>> -- 
>> Clint Bowman INTERNET:   cl...@ecy.wa.gov
>> Air Quality Modeler  INTERNET:   cl...@math.utah.edu
>> Department of EcologyVOICE:  (360) 407-6815
>> PO Box 47600 FAX:(360) 407-7534
>> Olympia, WA 98504-7600
>> 
>> On Sun, 25 Oct 2009, Aneeta wrote:
>> 
>>>
>>> Thank you everyone for all the responses.
>>>
>>> Clint you are correct in assuming that the problem deals with sensors in
>>> a
>>> lab setup which can be assumed to be isolated from outside temperature
>>> changes. And, I am only dealing with temperature so the other parameters
>>> are
>>> not important.
>>>
>>> There will be no gorillas or mouses in the picture but rather some
>>> malicious
>>> attacker who would try to cause disturbances in the normal readings.
>>> That is
>>> why it is important to have an equation that defines 'normal behaviour'.
>>>
>>> The data-sets contain readings for multiple days. I want to take the
>>> first 7
>>> days for each node and establish a relationship between time(column 2)
>>> and
>>> temperature(column 4).
>>>
>>> My objective is not to model temperature variation throughout the year
>>> and
>>> take into consideration climatic changes. Rather, it is to define a
>>> model
>>> for the given data which happens to be temperature recorded by nodes. In
>>> a
>>> simple w

Re: [R] Splitting massive output into multiple text files

2009-11-20 Thread bartjoosen


try:
capture.output(fit5, file=paste("testperm", i, ".txt", sep=""), append=T)


Bart


A Singh wrote:
> 
> Dear List,
> 
> I thought it would be much easier to put a second query into a second
> mail.
> 
> I need to print 426*1 blocks of variance components data, where 426 is 
> the number of columns of data that have 1 permutations of variance 
> generated for each of them.
> 
> I have tried printing out a smaller number of permutations for a smaller 
> number of markers and that has worked.
> 
> However, since a text file will not handle 4 million blocks in a single 
> file (which is what I ultimately need to do), is there a way to tell R to 
> create a new file for every 10 or so columns?
> 
> I tried to use some suggested code that looked like:
> 
> for (j in 1:426)
> {
>  write(cbind(modeldf[,j:(j+9)]),file=as.character(j))
>  j <- j+10
> }
> 
> ..but can't figure out how to put it into my own code and make it work.
> 
> I did find one example of code for split files, each successive file being 
> labeled as a series of numbers, but I couldn't figure out how to even
> adapt 
> that to my model.
> 
> I cannot figure out what other way there is to conveniently view 4 m.
> items 
> of data without losing some of it somewhere..
> 
> Any help will be much much appreciated..
> 
> Aditi
> 
> --
> 
> Code for shorter sample file:
> 
> 
> model<-read.table("...)
> 
> modeldf<-data.frame(model)
> 
> modeldf[2:13<-lapply(modeldf[2:13],factor)
> 
> colms<-(modeldf)[4:13]   ## 10 markers only in this file
> se<-c(1:1000)
> 
> for(f in colms)
> {
> print("Marker")
> {
> for( i in 1:1000)
> {
> print("perm no.")
> print(se[i])
> {
> peg.no.prm<-sample(peg.no, length(peg.no))
> try(fit5<-lmer(data=modeldf, peg.no.prm~1 + (1|family/f)))
> print(summary(fit5))
> capture.output(fit5, file="testperm5.txt", append=T)
> }}}
> }
> 
> 
> The data files are at:
>>>
>>>
>>> >> ml> (excel)
>>> http://www.4shared.com/file/131980512/dc7308b/Testvcomp10.html
>>> (txt)
> --
> 
> 
> --
> A Singh
> aditi.si...@bristol.ac.uk
> School of Biological Sciences
> University of Bristol
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Splitting-massive-output-into-multiple-text-files-tp26429300p26432040.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] advice about R for windows speed

2009-11-20 Thread bartjoosen

I can only speak for the Windows part, but isn't it possible to test on
Windows 7 64bit?
(you can download a test version, and use a dual boot setup to try)
I always heard about the difficulties with WinXP 64bit, so maybe that is
just the problem?
Another thing to find out: maybe you can take advantage of the 4 processors
of your quadcore by using snow or similar?

Bart





Carlos Hernandez-7 wrote:
> 
> Thanks for your reply! I just added some more details below.
> 
> Our code needs around 1GB of RAM and all machines and R configurations
> have
> its default maximum above this number.
> 
> Our suspicion is that the windows server could run the code in half of its
> current time (given the apparent factor of 2 between windows and other OS
> timing). There may be something very important either in the R
> configuration
> or in our code that we should take care of?
> 
> I appreciate a lot any further advice or hints, specially about speeding
> up
> the code in the windows xp server with QuadCore Xeon processors.
> 
> Best regards,
> 
> Carlos
> 
> 
> 
> 
> 
> 
> **Server running WinXP 64bit (R 2.10.0 32bit , QuadCore Xeon 2.6GHz 8G
> Ram)
> Time per 25 Iterations "6.17"
> 
> 
> **Dell Latitude running Linux 32bit (R 2.9.2, Intel Core 2 Duo P9500 @
> 2.53GHz, 4GB ram)
> Time per 25 iterations "2.88"
> 
> **Dell Latitude running Win Vista 32bit (R 2.10.0, Intel Core 2 Duo P9500
> @
> 2.53GHz, 4GB ram) with New DLL in terminal
> Time per 25 iterations "5.53"
> 
> ---
> **Macbook pro running Snow Leopard (R 2.10.0, 2.16GHz Intel Core 2 Duo &
> 2GB
> ram)
> Time per 25 Iterations "4.58"  (both R 2.10.0 32bit and 64bit produce
> almost
> identical timings)
> 
> **Macbook pro running WinXp natively (R 2.10.0 32bit, 2.16GHz Intel Core 2
> Duo & 2GB ram)
> Time per 25 Iterations "8.23"
> 
> note: for the Dell and MacBook Pro we replaced the Rblas.dll file of R for
> Windows with the file available here
> http://cran.r-project.org/bin/windows/contrib/ATLAS/C2D/
> 
> ==
> 
> 
> 
> On Thu, Nov 19, 2009 at 5:06 PM, Marc Schwartz 
> wrote:
> 
>> On Nov 19, 2009, at 9:25 AM, Carlos Hernandez wrote:
>>
>>  Dear All,
>>> I appreciate any advice or hints you could provide about the following.
>>>
>>> We are running R code in a server (running Windows XP and QuadCore Xeon
>>> processors, see details below) and we would like to use the server
>>> efficiently. Our code takes a bit more than 6 seconds per 25 iterations
>>> in
>>> the server using a default R 2.10.0 installation.
>>>
>>> We tested our code in two other computers, a Dell Latitute and a MacBook
>>> Pro, and from the details that i include below you will notice that the
>>> code
>>> needs almost twice the time when we used R for Windows compared against
>>> the
>>> time the code needs when we use Linux or MacOSX 10.6.2 in each of these
>>> computers.
>>>
>>> I'm sorry I don't provide details on the code we are using. The code
>>> consists of all sort of operations (matrix inverses, random number
>>> generation, vectorized functions, a few loops, and so on). I hope I can
>>> get
>>> some advice from you despite the lack of specific code details.
>>>
>>> Is there any important R feature we should configure manually in the
>>> windows
>>> server to speed the code up? Is there an optimized BLAS available
>>> somewhere
>>> for this type of machine? Is these something else apart of an optimized
>>> BLAS
>>> that we could do to improve the timing?
>>>
>>> Best regards,
>>>
>>> Carlos
>>>
>>>
>>>
>>>
>>> **Server running WinXP (QuadCore Xeon 2.6GHz 8G Ram)
>>> Time per 25 Iterations "6.17"
>>>
>>> 
>>> **Dell Latitude running Linux (R 2.9.2, Intel Core 2 Duo P9500 @
>>> 2.53GHz,
>>> 4GB ram)
>>> Time per 25 iterations "2.88"
>>>
>>> **Dell Latitude running Win Vista (R 2.10.0, Intel Core 2 Duo P9500 @
>>> 2.53GHz, 4GB ram) with New DLL in terminal
>>> Time per 25 iterations "5.53"
>>>
>>> ---
>>> **Macbook pro (2.16GHz Intel Core 2 Duo & 2GB ram)
>>> Time per 25 Iterations "4.58"
>>>
>>> **Macbook pro running WinXp (2.16GHz Intel Core 2 Duo & 2GB ram)
>>> Time per 25 Iterations "8.23"
>>>
>>>
>>> note: for the Dell and MacBook Pro we replaced the Rblas.dll file of R
>>> for
>>> Windows with the file available here
>>> http://cran.r-project.org/bin/windows/contrib/ATLAS/C2D/
>>>
>>
>>
>> Are you running 32 bit R on each platform or are you using 64 bit R on
>> Linux and OSX?
>>
>> On the Dell, you are running two different versions of R and you don't
>> indicate the R versions on the MacBook.
>>
>> The RAM configuration on each computer is different, which will impact
>> the
>> timings to some extent, depending upon how much RAM you may require for
>> your
>> R code, given other processes that are running and before any disk
>> swapping
>> kicks in. You might want to review R Windows FAQ 2.9, if you have not
>> already:
>>
>>
>> http://cran.r-project.org/bin/windows/base/rw-FAQ.html#There-seems-to-be-a-limit-on-the-memory-

Re: [R] Functions Accessing Databases

2009-04-03 Thread bartjoosen

Hi,

There seems to be something wrong with your function getinfo.

Try first to substitute your dbGetQuery by a print statement, so that you
can see what is going on:
getinfo=function(t){print(the SQL query)}
allinfo=sapply(c(1985:2007),getinfo)

If these results look good, you can change your function back to
dbGetQuery(con, )
If not, show your results, and we will look again

Bart




Bob Roberts-2 wrote:
> 
> Hello,
>I'm accessing a MySQL database from inside R and had a problem with a
> function. In the database, there is data from years 1985 to 2007 that I
> would like to retrieve. I can easily get the data from one year by the
> following:
> info1985=dbGetQuery(con, statement='the SQL query')
> Inside the statement, I have a column that is set to the desired year
> (e.g. table.column=1985) through a WHERE clause, but when I write a
> function like the following:
> getinfo=function(t){dbGetQuery(con,statement='the SQL query')}
> and instead of using a specific year, I substitute in t (e.g.
> table.column=t) in a WHERE clause
> When I go to do
> allinfo=sapply(c(1985:2007),getinfo)
> I get the following error message: RS-DBI driver: (could not run
> statement: Unknown column 't' in 'where clause')
> Is there anyway around this error? Or is not possible to substitute in
> years with a function and sapply through SQL?
> Thanks so much.
> 
> 
> 
>   
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Functions-Accessing-Databases-tp22860193p22865610.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] automatic exploration of all possible loglinear models?

2009-04-22 Thread bartjoosen

Hi,

you could also take a look at:
http://www.nabble.com/finding-best-fitting-model-td22852224.html


Bart


ryancw wrote:
> 
> Is there a way to automate fitting and assessing loglinear models for
> several nominal variables . . . something akin to step or drop1 or add1
> for linear or logistic regression?
> 
> Thanks.
> 
> --Chris
> -- 
> Christopher W. Ryan, MD
> SUNY Upstate Medical University Clinical Campus at Binghamton
> 40 Arch Street, Johnson City, NY  13790
> cryanatbinghamtondotedu
> 
> "If you want to build a ship, don't drum up the men to gather wood,
> divide the work and give orders. Instead, teach them to yearn for the
> vast and endless sea."  [Antoine de St. Exupery]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/automatic-exploration-of-all-possible--loglinear-models--tp23141046p23171352.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] How to get rid of loop?

2009-04-28 Thread bartjoosen

Hi,

how about this:
x <- runif(100) 
n <- length( x ) 

y2 <- rep(0,n)
y2[x > 0.75] <- 1
y2[x < 0.25] <- -1
cx <- cumsum(abs(y2) )
m <- match(cx, cx)
y2[y2==0] <- 2
y2[x<0.5 & y2[m]==1] <- 0
y2[x>0.5 & y2[m]==-1] <- 0
y3 <- y2
y3[y3==0] <- 1
y3[y3==2] <- 0
cx <- cumsum(abs(y3))
m <- match(cx, cx)
y2 <- y2[m]


Best regards

Bart
-- 
View this message in context: 
http://www.nabble.com/How-to-get-rid-of-loop--tp23226779p23273405.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] How to skip rest of code

2009-05-04 Thread bartjoosen

How about:

x <- F
if (x) {
 print("true") 
} else {
print("false")
}


Bart


mli-2 wrote:
> 
> Dear R users,
>  
> Suppose I have 2 R script files: 'test1.R' and 'test2.R' and one R file
> 'main.R' which sources each of them. I wonder if there is a way to skip
> rest of code in 'test1.R' once a condition is met but still continue to
> run rest of script from the 'main'R' file.
>  
> A simple example is shown below. I hope only 'message1' and 'message3' can
> be shown up without using if(...) else statement for skipped part in
> 'test1.R'.
>  
> #main.R:
> source("test1.R")
> source("test2.R")
> ===
> #test1.R
> # In this example the goal is to skip executing the line of
> print("message2").
> # without using if() else statement.
> x <- TRUE
> if (x) {
> print("message1")
> q() # want to skip rest of code in test1.R ONLY
> }
> # lots of lines can start from here.
> print("message2")
> ===
> #test2.R
> print("message3")
>  
>  
> Thank you.
> Ming-chung Li
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-skip-rest-of-code-tp23320816p23365295.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] odbcConnectAccess function

2009-05-04 Thread bartjoosen

You can use R CMD BATCH if I'm correctly.
How about define a query through your routine, process the results of this
query through R, write this output in a new table, or a textfile, and load
this with your subroutine.

Bart



Felipe Carrillo wrote:
> 
> 
> Steve: I am already using it importing data from Access to R but was
> wondering if it can be used the other way around, creating a subroutine in
> an access module and using the RODBC functions from there.
> 
> 
> 
> --- On Thu, 4/30/09, steve_fried...@nps.gov 
> wrote:
> 
>> From: steve_fried...@nps.gov 
>> Subject: Re: [R] odbcConnectAccess function
>> To: mazatlanmex...@yahoo.com
>> Cc: r-h...@stat.math.ethz.ch, r-help-boun...@r-project.org
>> Date: Thursday, April 30, 2009, 7:38 AM
>> Feilipe,
>> 
>> You should look at the RODBC package
>> 
>> It works great !
>> 
>> Steve
>> 
>> Steve Friedman Ph. D.
>> Spatial Statistical Analyst
>> Everglades and Dry Tortugas National Park
>> 950 N Krome Ave (3rd Floor)
>> Homestead, Florida 33034
>> 
>> steve_fried...@nps.gov
>> Office (305) 224 - 4282
>> Fax (305) 224 - 4147
>> 
>> 
>>
>>
>>  Felipe Carrillo   
>>
>>  >   
>>  ahoo.com>  
>>To 
>>  Sent by: 
>> r-h...@stat.math.ethz.ch
>>  r-help-boun...@r- 
>> cc 
>>  project.org   
>>
>>
>>Subject 
>>[R]
>> odbcConnectAccess function  
>>  04/30/2009 07:17  
>>
>>  AM MST
>>
>>
>>
>>
>>
>>  Please respond to 
>>
>>  mazatlanmex...@ya 
>>
>>   hoo.com  
>>
>>
>>
>>
>>
>> 
>> 
>> 
>> 
>> 
>> HI:
>> Is it possible to use the RODBC package within MS Access. I
>> have been using
>> from R but was just wondering if it could be used along
>> with R(D)COM.
>> Something like this:
>> 
>> Dim dbs As DAO.Database
>> Dim rst As DAO.Recordset
>> Dim myApp As StatConnector
>> Set myApp = New StatConnector
>> myApp.GetErrorText
>> myApp.Init "R"
>> 
>> myApp.EvaluateNoReturn "library(RODBC)"
>> myApp.EvaluateNoReturn "myDB <-
>> odbcConnectAccess(CurrentDb)"
>> 'query the database and save it as R object 'a'
>> myApp.EvaluateNoReturn "a <- sqlQuery(CurrentDb,
>> Paste(""select * From
>> Sample""))"
>> myApp.EvaluateNoReturn "plot(a)"
>> 
>> Thanks in advance
>> 
>> 
>> Felipe D. Carrillo
>> Supervisory Fishery Biologist
>> Department of the Interior
>> US Fish & Wildlife Service
>> California, USA
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained,
>> reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/odbcConnectAccess-function-tp23317361p23365104.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] Can't find package for decision plot anymore

2009-05-06 Thread bartjoosen

Hi,

About a year ago I found some references to a package which takes a
dataframe and derived rules from it.
If I remember correctly, there were examples shown from the Iris data.
You could choose between a graphical representation with balloons with
choises, or a text version: if x > y then z.

I searched a lot on this stuff, but couldn't find it anymore

Anyone who can point me to the right package?

Thanks

Bart

-- 
View this message in context: 
http://www.nabble.com/Can%27t-find-package-for-decision-plot-anymore-tp23404066p23404066.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] Improving data processing efficiency

2008-06-05 Thread bartjoosen

Maybe you should provide a minimal, working code with data, so that we all
can give it a try.
In the mean time: take a look at the Rprof function to see where your code
can be improved.

Good luck

Bart


Daniel Folkinshteyn-2 wrote:
> 
> Hi everyone!
> 
> I have a question about data processing efficiency.
> 
> My data are as follows: I have a data set on quarterly institutional 
> ownership of equities; some of them have had recent IPOs, some have not 
> (I have a binary flag set). The total dataset size is 700k+ rows.
> 
> My goal is this: For every quarter since issue for each IPO, I need to 
> find a "matched" firm in the same industry, and close in market cap. So, 
> e.g., for firm X, which had an IPO, i need to find a matched non-issuing 
> firm in quarter 1 since IPO, then a (possibly different) non-issuing 
> firm in quarter 2 since IPO, etc. Repeat for each issuing firm (there 
> are about 8300 of these).
> 
> Thus it seems to me that I need to be doing a lot of data selection and 
> subsetting, and looping (yikes!), but the result appears to be highly 
> inefficient and takes ages (well, many hours). What I am doing, in 
> pseudocode, is this:
> 
> 1. for each quarter of data, getting out all the IPOs and all the 
> eligible non-issuing firms.
> 2. for each IPO in a quarter, grab all the non-issuers in the same 
> industry, sort them by size, and finally grab a matching firm closest in 
> size (the exact procedure is to grab the closest bigger firm if one 
> exists, and just the biggest available if all are smaller)
> 3. assign the matched firm-observation the same "quarters since issue" 
> as the IPO being matched
> 4. rbind them all into the "matching" dataset.
> 
> The function I currently have is pasted below, for your reference. Is 
> there any way to make it produce the same result but much faster? 
> Specifically, I am guessing eliminating some loops would be very good, 
> but I don't see how, since I need to do some fancy footwork for each IPO 
> in each quarter to find the matching firm. I'll be doing a few things 
> similar to this, so it's somewhat important to up the efficiency of 
> this. Maybe some of you R-fu masters can clue me in? :)
> 
> I would appreciate any help, tips, tricks, tweaks, you name it! :)
> 
> == my function below ===
> 
> fcn_create_nonissuing_match_by_quarterssinceissue = function(tfdata, 
> quarters_since_issue=40) {
> 
>  result = matrix(nrow=0, ncol=ncol(tfdata)) # rbind for matrix is 
> cheaper, so typecast the result to matrix
> 
>  colnames = names(tfdata)
> 
>  quarterends = sort(unique(tfdata$DATE))
> 
>  for (aquarter in quarterends) {
>  tfdata_quarter = tfdata[tfdata$DATE == aquarter, ]
> 
>  tfdata_quarter_fitting_nonissuers = tfdata_quarter[ 
> (tfdata_quarter$Quarters.Since.Latest.Issue > quarters_since_issue) & 
> (tfdata_quarter$IPO.Flag == 0), ]
>  tfdata_quarter_ipoissuers = tfdata_quarter[ 
> tfdata_quarter$IPO.Flag == 1, ]
> 
>  for (i in 1:nrow(tfdata_quarter_ipoissuers)) {
>  arow = tfdata_quarter_ipoissuers[i,]
>  industrypeers = tfdata_quarter_fitting_nonissuers[ 
> tfdata_quarter_fitting_nonissuers$HSICIG == arow$HSICIG, ]
>  industrypeers = industrypeers[ 
> order(industrypeers$Market.Cap.13f), ]
>  if ( nrow(industrypeers) > 0 ) {
>  if ( nrow(industrypeers[industrypeers$Market.Cap.13f >= 
> arow$Market.Cap.13f, ]) > 0 ) {
>  bestpeer = 
> industrypeers[industrypeers$Market.Cap.13f >= arow$Market.Cap.13f, ][1,]
>  }
>  else {
>  bestpeer = industrypeers[nrow(industrypeers),]
>  }
>  bestpeer$Quarters.Since.IPO.Issue = 
> arow$Quarters.Since.IPO.Issue
>  
> #tfdata_quarter$Match.Dummy.By.Quarter[tfdata_quarter$PERMNO == 
> bestpeer$PERMNO] = 1
>  result = rbind(result, as.matrix(bestpeer))
>  }
>  }
>  #result = rbind(result, tfdata_quarter)
>  print (aquarter)
>  }
> 
>  result = as.data.frame(result)
>  names(result) = colnames
>  return(result)
> 
> }
> 
> = end of my function =
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Improving-data-processing-efficiency-tp17676300p17678034.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] Area Under a Curve

2008-07-02 Thread bartjoosen

You can take a look at AUC in the PK package


stephen sefick wrote:
> 
> I would like to integrate the area under a curve without any smoothing or
> the like- just on the raw numbers.  I looked at integrate() but it
> requires
> a function which I assume means something like x+x^2+x^3
> 
> is there a built in function in R for this?
> 
> #let's say
> x <- seq(1:50)
> y <- seq(1:50)
> plot(y~x)
> # the are would be 1250
> # I would like to be able to do this but on more complicated numeric sets
> of
> points say dissolved oxygen mass
> 
> 
> thanks
> 
> stephenr
> 
> -- 
> Let's not spend our time and resources thinking about things that are so
> little or so large that all they really do for us is puff us up and make
> us
> feel like gods. We are mammals, and have not exhausted the annoying little
> problems of being mammals.
> 
> -K. Mullis
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Area-Under-a-Curve-tp18226826p18231936.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] re cursively divide a value to get a sequence

2008-07-09 Thread bartjoosen

Maybe something like this:

f1 with loop, f2 without.


f1 <- function(start,len, div) {
x <- rep(start,len)
for (i in 2 : (len-1)) {
x[i] <- x[i-1]/div
}
x[len] <- 0
return(x)
}



f2 <- function(start,len, div) {
x <- rep(start,len)
y <- div^(0:(len-1))
x <- x/y
x[length(x)] <- 0
return(x)
}


system.time(f1(1,10,0.5))
system.time(f2(1,10,0.5))


Best regards

Bart



Anne-Marie Ternes wrote:
> 
> Hi,
> 
> if given the value of, say, 15000, I would like to be able to divide
> that value recursively by, say, 5, and to get a vector of a determined
> length, say 9, the last value being (set to) zero- i.e. like this:
> 
> 15000 3000 600 120 24 4.8 0.96 0.192 0
> 
> These are in fact concentration values from an experiment. For my
> script, I get only the starting value (here 15000), and the factor by
> which concentration is divided for each well, the last one having, by
> definition, no antagonist at all.
> 
> I have tried to use "seq", but it can "only" do positive or negative
> increment. I didn't either find a way with "rep", "sweep" etc. These
> function normally start from an existing vector, which is not the case
> here, I have only got a single value to start with.
> 
> I suppose I could do something "loopy", but I'm sure there is a better
> way to do it.
> 
> Thanks a lot for your help, hope the question is not too dumb...
> 
> Anne-Marie
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/recursively-divide-a-value-to-get-a-sequence-tp18358046p18358674.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] Start preferred RGui

2008-07-11 Thread bartjoosen

Re-installing R did the trick for me a while ago, don't know if this still
works with the current Tinn-R version.



Ptit_Bleu wrote:
> 
> Hello Marcia,
> 
> I had a similar problem when I updated Tinn-R.
> Under XP, in the file Document and Settings\... \Application
> Data\Tinn-R\ini\Tinn.ini,
> I replaced
> sPathRGui=\bin\Rgui.exe
> by
> rguiPreferred=C:\R\bin\Rgui.exe (to adjust to your path)
> 
> It worked for me. I hope it will work for you.
> 
> Have a nice week-end,
> Ptit Bleu. 
> 

-- 
View this message in context: 
http://www.nabble.com/Start-preferred-RGui-tp18400190p18402969.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] Re place with previous value

2008-03-27 Thread bartjoosen

Maybe something like:

f <- function(x,y) ifelse(sign(y[x])==-1,return(y[x-1]), return(y[x]))
test[,3] <- sapply(seq_along(test[,3]),f,test[,3])





Ravi S. Shankar wrote:
> 
> Hi R,
> 
> I have a dataframe with
> dim(test)
> [1] 435150  4
> class(test)
> [1] "data.frame"
> In the third column every time a number with "-" appears I need to
> replace with previous value
> I am using the following code
> s=which(substr(as.character(test[,3]),1,1)=="-")
>  for(i in 1:length(s)) test[s[i],3] = test[s[i]-1,3]
> 
> Is there a faster way of doing this?
> 
> sessionInfo()
> R version 2.5.1 (2007-06-27) 
> i386-pc-mingw32 
> 
> locale:
> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> States.1252;LC_MONETARY=English_United
> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
> 
> attached base packages:
> [1] "stats" "graphics"  "grDevices" "utils" "datasets"
> "methods"  
> [7] "base" 
> Thanks in advance
> 
> 
> Ravi Shankar S 
>  
> 
> This e-mail may contain confidential and/or privileged i...{{dropped:10}}
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Replace-with-previous-value-tp16310560p16323983.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] iterative loop with user input?

2008-04-04 Thread bartjoosen

Your example runs fine at my pc, except from the readLines("File with 30
) part.

But this is probably a striped code, so maybe you should take a look at
flush.console().

Bart


Christopher Marcum wrote:
> 
> Hello R-Users,
> 
> I would like to use an iterative loop to collect user input from within a
> function. I'm sure that this would be some combination of "for","break",
> and "next" but have not been able to get the syntax down.
> 
> I would like to print some text to the screen at each step in the loop,
> ask the user for input which is saved in an object, and then advance the
> loop.
> 
> Here is an example:
> 
> #anchor is a file with unique ids
> anchor<-rep(1:30)
> anchor<-paste(anchor,"uid",sep="")
> 
> #codelist is where I would like to store user input
> codelist<-NULL
> 
> for(i in 1:30) {
> #tell the user which ID is being coded
> print(paste("You are coding unique ID",anchor[i],sep=":   "))
> #Read a line from a text file:
> print(readLines(file="file_with_30_lines.txt",warn=F)[i])
> #Ask the user for input
> codelist[i]<-readline(paste("Select one of the following: \n \t please
> enter 1, 2, or 3: \n Enter Your Response HERE:   ",sep=""))
> }
> 
> Ideally, loop should work from inside a function.
> 
> Any tips? Thanks in advance for your time and patience.
> 
> Best,
> Chris Marcum
> Sociology/Cal(it)^2
> University of California-Irvine
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/iterative-loop-with-user-input--tp16481541p16489236.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] getting serial anovas from a complex lm object obtained with a matrix of responses

2008-04-04 Thread bartjoosen

Hi,

I'm not aware of a way to do this without some looping/applying, but this
should do the trick:

x <- 1:10
y <- rnorm(100,x,0.5)
dim(y) <- c(10,10)
mod <- lm(y~x)

do.call(rbind,lapply(summary(mod),function(x) coefficients(x)[,4]))

This will give you the p values/model


Bart


Mark W Kimpel wrote:
> 
> I have fit a model to ~20k different genes and would now like to extract
> the
> p-val for one of the effects, again for each individual gene.
> 
> My model code is:
> mod <- lm(myResponseMatrix~ Time)
> 
> Were I to do this with a response vector rather than matrix, the following
> would work:
> anovaResult<- anova(mod)
> 
> With a more complex lm object, such as that generated above, it seems
> anova
> is trying to compare all the models to each other, a Herculean task for
> ~20k
> models and NOT what I want.
> 
> Without resorting to a slow loop/apply approach, is there a way to get
> lightening fast anova results in a fashion similar to that obtained from
> lm?
> 
> Mark
> 
> -- 
> Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry
> Indiana University School of Medicine
> 
> 15032 Hunter Court, Westfield, IN 46074
> 
> (317) 490-5129 Work, & Mobile & VoiceMail
> (317) 663-0513 Home (no voice mail please)
> 
> **
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/getting-serial-anovas-from-a-complex-lm-object-obtained-with-a-matrix-of-responses-tp16475434p16489817.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] How can we creat conditional data frame

2008-04-04 Thread bartjoosen

Hello,

altough I'm not an expert, I found a solution (maybe not the most
elegant.)

d<-as.Date(c("2000/01/03","2000/01/05","2000/01/19","2000/01/28")) 
r<-rnorm(4) 
da<-data.frame(d,r) 

a<-as.Date("01/01/2000","%d/%m/%Y") 
b<-as.Date("30/01/2000","%d/%m/%Y") 
ab<-seq(a,b,by=1) 
c<-format(ab,"%a") 
date<-data.frame(ab,c) 
date<-subset(date,c!="Sun") 
date<-subset(date,c!="Sat") 


names(da) <- c("a","r")
names(date) <- c("a","day")
outp <- merge(date,da,all=T)
outp$hd <-0
outp$hd[!is.na(outp$r)] <- 1


Kind regards

Bart

saikat sarkar wrote:
> 
> Hi, 
> 
> R experts. I am a new user of R and trying to learn this program. 
> 
> I have a problem. Here is the code.
> 
> d<-as.Date(c("2000/01/03","2000/01/05","2000/01/19","2000/01/28"))
> r<-rnorm(4)
> da<-data.frame(d,r)
> 
> a<-as.Date("01/01/2000","%d/%m/%Y")
> b<-as.Date("30/01/2000","%d/%m/%Y")
> ab<-seq(a,b,by=1)
> c<-format(ab,"%a")
> date<-data.frame(ab,c)
> date<-subset(date,c!="Sun")
> date<-subset(date,c!="Sat")
> 
> Here I have 2 data frame. 
> 
> da
> -
>d  r
> 1 2000-01-03  1.2105865
> 2 2000-01-05 -0.8962776
> 3 2000-01-19 -1.0438936
> 4 2000-01-28  2.1329387
> 
> ---
> date
> --
>   ab   c
> 3  2000-01-03 Mon
> 4  2000-01-04 Tue
> 5  2000-01-05 Wed
> 6  2000-01-06 Thu
> 7  2000-01-07 Fri
> 10 2000-01-10 Mon
> 11 2000-01-11 Tue
> 12 2000-01-12 Wed
> 13 2000-01-13 Thu
> 14 2000-01-14 Fri
> 17 2000-01-17 Mon
> 18 2000-01-18 Tue
> 19 2000-01-19 Wed
> 20 2000-01-20 Thu
> 21 2000-01-21 Fri
> 24 2000-01-24 Mon
> 25 2000-01-25 Tue
> 26 2000-01-26 Wed
> 27 2000-01-27 Thu
> 28 2000-01-28 Fri
> 
> ---
> 
> In data frame-"DA"- I have return(r) and date
> In data frame-"Date"- where I have date and day.
> 
> Now I need to create a data frame where returns will be conditional on
> date and rest will be zero. 
> 
> ---
> like this
> -
> 
>  abc   rhd
> 3  2000-01-03 Mon1.2105865  0
> 4  2000-01-04 Tue 0  1
> 5  2000-01-05 Wed0  1
> 6  2000-01-06 Thu 0  1
> 7  2000-01-07 Fri   0  1
> 
> -
> 
> From this I can figureout the hoildays and then put each holidays equal to
> 1. 
> 
> 
> Please help me. 
> 
> Thanking you 
> 
> saikat
> 
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-can-we-creat-conditional-data-frame-tp16491208p16491562.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Format regression result summary

2008-04-15 Thread bartjoosen

This should be refined, but it gives you a start:

.dat<- summary(mod)$coefficients
namen <- row.names(.dat)
Est <- .dat[,1]
Err <- .dat[,2]
p <- .dat[,4]
p[p<0.0001] <- "***"
p[p<0.001] <- "**"
p[p<0.01] <- "*"
p[p<0.05] <- "."
p[p>0.05] <-" "

cat(paste(namen,"\t", Est, p, "\n\t\t(",Err,")\n"))

Bart


Thiemo Fetzer wrote:
> 
> Hello to the whole group.
> 
> I am a newbie to R, but I got my way through and think it is a lot easier
> to
> handle than other software packages (far less clicks necessary).
> 
> However, I have a problem with respect to the summary of regression
> results.
> 
> The summary function gives sth like:
> 
> Residuals:
>  Min   1Q   Median   3Q  Max 
> -0.46743 -0.09772  0.01810  0.11175  0.42252 
> 
> Coefficients:
>  Estimate Std. Error t value Pr(>|t|)
> (Intercept)  3.750367   0.172345  21.761  < 2e-16 ***
> Var1-0.002334   0.009342  -0.250 0.802948
> Var2   0.012551   0.005927   2.117 0.035444 *
> 
> Var3 0.015380   0.074537   0.206 0.836730
> Var3 0.098602   0.026448   3.728 0.000250 ***
> ...
> 
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
> 
> Residual standard error: 0.1614 on 202 degrees of freedom
> Multiple R-squared: 0.1983, Adjusted R-squared: 0.1506 
> F-statistic: 4.163 on 12 and 202 DF,  p-value: 7.759e-06
> 
> However, my wish is the output to have a format like:
> 
>  Estimate 
> (Intercept)  3.750367*** 
>   (0.172345)
> Var1-0.002334
>   (0.009342)
> Var2   0.012551*
>   (0.005927)
> 
> Etc. so that the standard errors are in parantheses below the estimates.
> Next to the estimates should be the * indicating significance.
> 
> I thought that should go by accessing the elements in the summary object,
> yet, I got started and figured that is quite complicated. 
> 
> Is there a quick and dirty way? 
> Basically I want the same print-out as the summary, except that I don't
> want
> the t-statistic and not the p-value, only the significance codes.
> 
> Thanks a lot in advance
> 
> Thiemo
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Format-regression-result-summary-tp16636200p16698297.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] optimization setup

2008-04-23 Thread bartjoosen

The error comes from the way you specify the parameters:
At least not as elegant, but it works:

function4 <- function(x){
theta1 <- x[1]
theta2 <- x[2]
theta3 <- x[3]
function3(theta1,theta2,theta3)
}

fit<-optim(par=c(1, 1.2, .2), fn=function4) 


Bart



threshold wrote:
> 
> Hi, here comes my problem, say I have the following functions (example
> case)
> #
> function1 <- function (x, theta) 
> {a <- theta[1] ( 1 - exp(-theta[2]) ) * theta[3] )
>  b <- x * theta[1] / theta[3]^2
>  return( list( a = a, b = b )) }
> #---
> function2<-function (x, theta) 
> {P <- function1(x, theta)
>   c <- P$a * x * exp(-theta[2])
>   d <- P$b * exp(x)
>   q <- theta[1] / theta[3]
>   res <- c + d + q; res}
> 
> # Function to be optimized
> function3 <- function(theta1,theta2,theta3) {
> n <- length(data)
> -sum( function2(x = data[2:n], theta = c(theta1, theta2, theta3) ))}
> # 'data' is my input ts class object
> #--
> 
> Then I want to maximize function3 with respect to theta(s) (given some
> starting values) 
> 
> fit<-optim(par=c(theta1=1, theta2=1.2, theta3=.2), fn=function3)
> 
> I get the following:
> Error in function1(x, theta) : 
>   argument "theta2" is missing, with no default
> 
> Where I made a mistake? I will appreciate any help ...
> 
> r
> 

-- 
View this message in context: 
http://www.nabble.com/optimization-setup-tp16825410p16833769.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] generic question -> Genomics with R

2008-04-29 Thread bartjoosen

I'm not sure what you are trying to do with R, but maybe you should take a
look at the Task Views and see if there is something you can use at your
field of work:
http://www.stats.bris.ac.uk/R/web/views/


Bart



Ricardo Rodríguez wrote:
> 
> Hi everybody,
> 
> I am trying to make my mind about the use of R for Computational and 
> Statistical Approaches to Genomics.
> 
> I know this is a vaste field: this is the main reason why I am sending 
> this message to this always useful list! Any key/entry point to this 
> field will be extremely welcome!
> 
> Please, could you help me to go in the right direction?
> 
> Thanks!!!
> 
> Ricardo
> 
> -- 
> Ricardo Rodríguez
> Your XEN ICT Team
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/generic-question--%3E-Genomics-with-R-tp16954827p16955748.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] no applicable method for "names"

2007-11-15 Thread Bartjoosen

I think you have an object x which doensn't allow to give names.
If you use names(z) it will work.
To see what kind of object x is: class(x)


Regards

Bart


Schiller Judith 1541 EB wrote:
> 
> hi,
> 
> after installing R-2.6.0 the function "names" doesn't work anymore on my
> windows xp machine. 
> for example for a simple vector i get
> 
>> z <- 1:3
>> names(x)
> Error in UseMethod("name"): no applicable method for "names"
> 
> ... instead of NULL. the same is true for lists and dataframes. attr(z,
> "names") is a workaround, but i don't want to change all my functions.
> 
> is this a know bug? thanks for any comments, 
> judith schiller 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/no-applicable-method-for-%22names%22-tf4806311.html#a13764385
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] any measure for curvature

2007-11-21 Thread Bartjoosen

You mean non-linearity?
You can use a lack of fit test by using:
anova(lm(y ~ x+factor(x), data))
The F-value of factor(x) is the lack of fit test, and when lineair, the p
value should be <0.05 when using 0.95% significance.

Bart


Wensui Liu wrote:
> 
> in statistics, is there a measure for curvature? how to detect and
> quantify the curvature between 2 variales instead of using
> visualization?
> thank you so much!
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/any-measure-for-curvature-tf4837912.html#a13853341
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] plotting help needed

2008-01-09 Thread bartjoosen

maybe this is what you want:
plot(all~c(1:2),type="b",col="blue",xlim=c(1,4),ylim=c(20,150),pch=c("a","b"),yaxt="none")
 
lines(all2~c(2:3),type="o",col="yellow",pch=c("d","e")) 

for some manuals, look at the contributed documents section at the R
homepage


Bart


ran2 wrote:
> 
> Dear all,
> 
> i need some help with plotting.
> 
> the specific problem is the following:
> 
> #FYI
> a=100
> b=95
> d=94.5
> e=70
> 
> all=c(a,b)
> all2=c(d,e)
> plot(all,type="b",col="blue",xlim=c(1,4),ylim=c(20,150))
> lines(all2,type="o",col="yellow")
> 
> 
> this does work so far, but ...
> i´d like to have 4 intersects, just named by characters.. no scale  
> please.
> the second problem is, i am trying to start the second vector where  
> the first vector stops (same point on the x-axis - y is different ;) )
> 
> admittedly all this sounds quite basic, but i couldnt get a long with  
> it for  a while. if somebody knows a good manual about graphics in R,  
> i´d be happy if you let me know.
> 
> thanks in advance !
> 
> matthias 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/plotting-help-needed-tp14697049p14707893.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] diff in a dataframe

2008-01-10 Thread bartjoosen


Maybe:
cbind(df,rbind(NA,apply(log(df),2,diff)))


Bart



Vishal Belsare wrote:
> 
> I have a dataframe say:
> 
> date   price_g   price_s
>  0.340.56
>  0.360.76
>.  .
>.  .
>.  .
> 
> and so on. say, 1000 rows.
> 
> Is it possible to add two columns to this dataframe, by computing say
> diff(log(price_g) and diff(log(price_s)) ?
> 
> The elements in the first row of these columns cannot be computed, but
> can I coerce this to happen and assign a missing value there? It would
> be really great if I could do that, because in this case I don't have
> to re-index my transformed series to the dates again in a new
> dataframe.
> 
> Thanks in anticipation.
> 
> 
> Vishal Belsare
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/diff-in-a-dataframe-tp14728790p14731043.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] How to load functions in R

2008-09-11 Thread bartjoosen

Take a look at ?source


Mihai.Mirauta wrote:
> 
> 
> Hello,
> 
> I am trying to use self created functions in other scripts than the one
> where they are stored.
> For the moment I am using the following structure of commands to do
> that:
> 
> 1. Load the text file with the functions in the current script:
> x=parse("path")
> 2. transform the tex in a function: f1=eval(x[1]), f2=eval(x[2]) if more
> than one function is stored in the text file
> 3. use the functions as normal
> 
> Is there another possibility to do the same?
> Thank you,
> 
> Mihai Mirauta
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-load-functions-in-R-tp19434909p19434944.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] error message documentation: "Error: no function to return from, jumping to top level"

2008-10-02 Thread bartjoosen

I think you wrote a function, but pass only snippets of code from your script
to your R-console.
The part which return the error is the following:
return()

return can only be used to return from a function and not as a command in
the R-console.

Bart

TU wrote:
> 
> Dear R Users,
> 
> Are error messages in R documented somewhere ? I am getting the following 
> error message and would like to track down what it means and which 
> specific routine triggers it:
> 
> Error: no function to return from, jumping to top level
> 
> Once I figure out which snippet of code triggers it, I can submit to the 
> list a working example in case I cannot get to the bottom of the problem 
> myself.
> 
> Thanks in advance,
> Tolga
> 
> Generally, this communication is for informational purposes only
> and it is not intended as an offer or solicitation for the purchase
> or sale of any financial instrument or as an official confirmation
> of any transaction. In the event you are receiving the offering
> materials attached below related to your interest in hedge funds or
> private equity, this communication may be intended as an offer or
> solicitation for the purchase or sale of such fund(s).  All market
> prices, data and other information are not warranted as to
> completeness or accuracy and are subject to change without notice.
> Any comments or statements made herein do not necessarily reflect
> those of JPMorgan Chase & Co., its subsidiaries and affiliates.
> 
> This transmission may contain information that is privileged,
> confidential, legally privileged, and/or exempt from disclosure
> under applicable law. If you are not the intended recipient, you
> are hereby notified that any disclosure, copying, distribution, or
> use of the information contained herein (including any reliance
> thereon) is STRICTLY PROHIBITED. Although this transmission and any
> attachments are believed to be free of any virus or other defect
> that might affect any computer system into which it is received and
> opened, it is the responsibility of the recipient to ensure that it
> is virus free and no responsibility is accepted by JPMorgan Chase &
> Co., its subsidiaries and affiliates, as applicable, for any loss
> or damage arising in any way from its use. If you received this
> transmission in error, please immediately contact the sender and
> destroy the material in its entirety, whether in electronic or hard
> copy format. Thank you.
> Please refer to http://www.jpmorgan.com/pages/disclosures for
> disclosures relating to UK legal entities.
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/error-message-documentation%3A-%22Error%3A-no-function-to-return-from%2C-jumping-to-top-level%22-tp19776107p19776262.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] function in R

2008-10-02 Thread bartjoosen

you can see the different methods of mean by: methods(mean)
Then you can type mean.default and you will see the complete code.

Bart


Alphonse Monkamg wrote:
> 
> 
> 
> 
> 
> Dear ALL,
> 
> Does anyone know how to get the complete code program for any build-in
> function
> in R, e.g. when I tape mean in the R-console, I get the following: 
> 
>  mean
> 
> function (x, ...) 
> 
> UseMethod("mean")
> 
> 
> 
> but I need the full mean function.
> 
> 
> 
> Thank in advance,
> 
> 
> 
> Alphonse.
> 
> 
>   
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/function-in-R-tp19777553p19777674.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] Maximum number of pasted 'code' lines?

2008-10-15 Thread bartjoosen

Hello,

Writing 19000 lines of R-script in Excel sounds terrible.
Could you provide us some code (please NOT 19000 lines), and the way you
generate this with Excel,
maybe we can figure out a much shorter/faster way to accomplish the same
result?

Bart



Duncan Murdoch-2 wrote:
> 
> On 10/14/2008 2:39 PM, Michael Just wrote:
>> Erik, Roger, others:
>> 
>> Why I use excel: the ability to concatenate and 'drag' formulas. I use it
>> because it is what I know. Apparently, excel is frowned upon, what should
>> I
>> be using? I don't know how else to create many very similar lines of R
>> code.
> 
> I think you're solving the wrong problem.  It's unlikely that you really 
> need a 19000 line R script, especially if it's a script that Excel could 
> create: it's likely that a loop in R would be much more compact and 
> easier to read.
> 
> Duncan Murdoch
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Maximum-number-of-pasted-%27code%27-lines--tp19978992p19994869.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] Defining a "list"

2008-10-15 Thread bartjoosen

maybe:

result <- list()
for (i in 1:10) result[[i]] <- rnorm(i)

Bart




Megh Dal wrote:
> 
> Can anyone please tell me how to define a "list". Suppose I want to define
> a list object "result" with length n then want to fill each place of
> "result" with different objects. For e.g.
> 
> i=1
> result[1] = rnorm(1)
> 
> i=2
> result[2] = rnorm(2)
> 
> ...
> 
> i=n
> result[n] = rnorm(n)
> 
> What would be the best way to do that?
> 
> Regards,
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Defining-a-%22list%22-tp19991526p19994922.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] R2HTML and output from a function

2008-12-18 Thread bartjoosen

Hello,

did you try to replace the print commands with HTML?
But first you have to specify a file through HTMLStart and at the end of the
function HTMLStop.
Including plots is no problem, but you have to save them and then with the
HTMLInsertGraph function insert them into your report.

Kind regards

Bart


Fredrik Karlsson wrote:
> 
> Dear list,
> 
> I am trying to construct a report function that would go through all
> the object in the current environment and print them in HTML form.
> What I have got is:
> 
> dataReport <- function(){
> 
>   #First tables
>   tabs <- ls(sys.frame(), pattern=".*table")
>   
>   for(currT in tabs){
>   cat("\n\n")
>   print(currT)
>   if(length(dim(get(currT))) > 2){
>   #We have to use ftable
>   require(Hmisc)
>   print(ftable(get(currT)))   
>   }
>   else{
>   print(get(currT))
>   print(chisq.test(get(currT)))   
>   }
>   
>   }   
>   
>   #Next, the lme models
>   mods <- ls(sys.frame(), pattern=".*lme")
>   require(nlme)
>   for(currM in mods){
>   if(class(get(currM)) %in% c("lme","lm")){
>   cat("\n\n")
>   print(currM)
> 
>   print(anova(get(currM)))
>   }
>   
>   }   
>   
> }
> 
> This generally works in the console. However, it I try to get the
> output processed by R2HTML, I get only the output of one table.
> So, now I have 2 questions:
> 
> 1) Is there a way to get the output of all the print commands of the
> function to be processed by R2HTML?
> 2) Is there a way to include saved plots in the output too?
> 
> 
> /Fredrik
> 
> 
> -- 
> "Life is like a trumpet - if you don't put anything into it, you don't
> get anything out of it."
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/R2HTML-and-output-from-a-function-tp21070859p21072921.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] Plotting graph for Missing values

2009-01-26 Thread bartjoosen

> I added "patientinformation1" variable and then I gave the command for
> "tapply" but its giving me the following error:
>
> Error in tapply(pat1, format(dos, "%Y%m"), function(x) sum(x == 0)) :
>   arguments must have same length



seems like you added patientinformation1, but still use pat1 in the tapply
call.

Bart
-- 
View this message in context: 
http://www.nabble.com/Plotting-graph-for-Missing-values-tp21659322p21666790.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] How to comment in R

2009-02-11 Thread bartjoosen

If you don't want to use the # before each comment line, you could try
something like defining a function which returns nothing and then type some
text after calling the function:

comm <- function(x) {invisible()}

comm("This is just a test,
trying to comment without typing the hashes"
)

But I don't recommend this kind of approach, what's wrong with the default
hashes everybody use?

Bart



Wacek Kusnierczyk wrote:
> 
>> Hi Mihai,
>>
>> one (very bad style) way would be
>>
>> if (FALSE) {
>>comment
>>comment
>>comment
>> }
>>
> 
> this works only if the enclosed text is syntactically valid r code.  that
> is, you can't have multiline free text comments done this way, neither can
> you temporarily comment out unfinished and unparsable code.
> 
> an extension to the parser that would accept multiline start-end comment
> tags, be it c-style /* */, perl-style =pod =cut, whatever, should be
> fairly  trivial to implement.  (the perl-style pod markup is particularly
> easy to parse, because it suffices to recognize '^=' on a line, no
> advanced pattern-matching needed.)
> 
> somewhat surprising there is no such functionality there in r (or is there
> any?), it would be quite convenient.
> 
> vQ
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-comment-in-R-tp21950370p21952539.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] Chromatogram deconvolution and peak matching

2009-02-17 Thread bartjoosen

Hi,

I'm trying to match peaks between chromatographic runs.
I'm able to match peaks when they are chromatographed with the same method,
but not when there are different methods are used and spectra comes in to
play.

While searching I found the ALS package which should be usefull for my
application, but I couldn't figure it out.

I made some dummy chroms with R, which mimic my actual datasets, to play
with, but after looking at the manuals of ALS, I'm affraid I can't get the
job done. Can someone put me on the right way?

Here is my code to generate the dummy chroms, which also plots the 2 chroms
and the spectra of the 3 peaks:

#2D chromatogram generation
par(mfrow=c(3,1))
time <- seq(0,20,by=0.05)
f <- function(x,rt) dnorm((x-rt),mean=0,sd=rt/35)
c1 <- f(time,6.1)
c2 <- f(time,5.6)
c3 <- f(time,15)
plot(c1+c2+c3~time,type="l",main="chrom1")

#spectrum generation
spectra <- function(x,a,b,c,d,e) a + b*(x-e) + c*((x-e)^2) + d*((x-e)^3)
x <- 220:300
s1 <- spectra(x,(-194.2),2.386,(-0.009617),(1.275e-05),0)
s2 <- spectra(x,(-1.054e02),1.3,(-5.239e-03),(6.927e-06),-20)
s3 <- spectra(x,(-194.2),2.386,(-0.009617),(1.275e-05),20)

chrom1.tot <-
data.frame(time,outer(c1,s1,"*")+outer(c2,s2,"*")+outer(c2,s2,"*"))
names(chrom.tot)[-1] <- x

#generation of chromatogram 2
c1 <- f(time,2.1)
c2 <- f(time,4)
c3 <- f(time,8) 
plot(c1+c2+c3~time,type="l",main="chrom2")

chrom2.tot <-
data.frame(time,outer(c1,s1,"*")+outer(c2,s2,"*")+outer(c2,s2,"*"))
names(chrom.tot)[-1] <- x

plot(s1~x,type="l",main="spectra")
lines(s2~x,col=2)
lines(s3~x,col=3)

Thanks for your time

Kind Regards

Bart
-- 
View this message in context: 
http://www.nabble.com/Chromatogram-deconvolution-and-peak-matching-tp22057592p22057592.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] Extract dates from dataframe

2009-03-06 Thread bartjoosen

Hi,

I have the following dataframe:
   IDDates
  1   16-07-01  06-10-95
  224/01/02 06-10-95
  3 16/01/02   16/08/94 12/01/91

And I would like to extract the dates, but couple the ID's to the right
dates, eg:
ID  Dates
116-07-01
106-10-95
224-01-02
2  

I have no clue about how to get started, looks something for the
regexp/grep/... kind of functions, but I don't get the point.

Any thoughts??

Kind regards

Bart Joosen

PS: for the reconstruction of the dataframe:
dat <-
structure(list(ID = c(1, 2, 3), Dates = structure(c(2L, 4L, 6L
), .Label = c("16-01-02   16-08-94", "16-07-01  06-10-95", "24-01-02
06-10-95", 
"24/01/02 06-10-95", "16/01/02   16/08/94", "16/01/02   16/08/94
12/01/91"
), class = "factor")), .Names = c("ID", "Dates"), row.names = c(NA, 
3L), class = "data.frame")


-- 
View this message in context: 
http://www.nabble.com/Extract-dates-from-dataframe-tp22369479p22369479.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] how to omit NA without using ifelse

2009-03-06 Thread bartjoosen

?is.na



Manli Yan wrote:
> 
>I have a 50*50 matrix,some entry are NAs,I want to replace these NA by
> 0,so can I use some syntax to do so other than using ifelse?
>I tried to use replace(a,NA,0),it didnt work~~(a is matrix name)
> 
>   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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-to-omit-NA-without-using-ifelse-tp22365996p22371063.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] stats lm() function

2009-03-13 Thread bartjoosen

Altough it depends on what crit you keep your variables, but maybe you should
take a look at ?step.


Bart



Paul Hermes wrote:
> 
> ok,
> i think i have to be more precise of what we are doing.
> first thing: this code is not from me, and Im new to R (and never touched 
> anything like this)
> Im just the lucky guy who has to maintain this crap :)
> this call to the lm function is part of a code wich is used to predict the 
> marketvalues from a bunch of our products.
> as 'target' function it gets the past marketvalues we have in our 
> database.(this is what goes into the 'data' parameter into the lm
> function)
> 
> then we have allot other prices and enviromental data (like similar 
> products, stock sizes, seasonal informations,  )
> with this, the big formula is created (y ~ x1 + x2 + x3 + x4 + x5 ...
> + 
> x300)
> 
> 
> all this goes into the lm call. then the result is somehow anaylsed to 
> figure out wich input data-set had the least influence (or similaryti ) to 
> the past marketvalues. this one gets eleminated and lm is called again 
> wihout this data-set.
> this is done until we just have a small number of datasets left.
> 
> could be that everything im writing here is totaly bullshit (cause im not 
> shure if i got every thing right)
> but this thing is working an creates very nice predictions ;)
> 
> i just fugured that the lm call's in this loop tooks the most time and i 
> want to reduce this.
> any ideas?
> 
> - Original Message - 
> From: "David Winsemius" 
> To: "Paul Hermes" 
> Cc: 
> Sent: Thursday, March 12, 2009 3:42 PM
> Subject: Re: [R] stats lm() function
> 
> 
>>I think you will find that many readers of this list would rather try  to 
>>dissuade you from this misguided strategy. You are unlikely to get  to a 
>>sensible solution in using step-down procedures with this sort of 
>>situation (large number of predictors with modest size of data).
>>
>> -- 
>> David Winsemius
>>
>> On Mar 12, 2009, at 1:59 PM, Paul Hermes wrote:
>>
>>> Hi,
>>>
>>> Im using the lm() function where the formula is quite big (300 
>>> arguments) and the data is a frame of 3000 values.
>>>
>>> This is running in a loop where in each step the formula is reduced  by 
>>> one argument, and the lm command is called again (to check which 
>>> arguments are useful) .
>>>
>>> This takes 1-2 minutes.
>>> Is there a way to speed this up?
>>> i checked the code of the lm function and its seems that its  preparing 
>>> the data and then calls lm.Fit(). i thought about just  doing this 
>>> praparing stuff first and only call lm.fit() 300 times.
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide 
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> David Winsemius, MD
>> Heritage Laboratories
>> West Hartford, CT
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/stats-lm%28%29-function-tp22483608p22492199.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] Using R in a university course: dealing with proposal comments

2008-02-11 Thread bartjoosen

You can use a GUI to teach R, so the programming-style is gone.
But using the command line aproach, it forces you to think about your
analysis.
In an GUI, it's easy to point and click, without knowing what you are doing.
With the command line, you know where you start, and from there you go to
the next step, and so on.
I think you learn more this way.

And of course, its free, so if they are off school or somewhat further, at
work, they still have the possibility to use what they have learned (in
contrary of SPSS maybe).

Bart


Arin Basu-3 wrote:
> 
> Hi All,
> 
> I am scheduled to teach a graduate course on research methods in
> health sciences at a university. While drafting the course proposal, I
> decided to include a brief introduction to R, primarily with an
> objective to enable the students to do data analysis using R. It is
> expected that enrolled students of this course have all at least a
> formal first level introduction to quantitative methods in health
> sciences and following completion of the course, they are all expected
> to either evaluate, interpret, or conduct primary research studies in
> health. The course would be delivered over 5 months, and R was
> proposed to be taught as several laboratory based hands-on sessions
> along with required readings within the coursework.
> 
> The course proposal went to a few colleagues in the university for
> review. I received review feedbacks from them; two of them commented
> about inclusion of R in the proposal.
> 
> In quoting parts these mails, I have masked the names/identities of
> the referees, and have included just part of the relevant text with
> their comments. Here are the comments:
> 
> Comment 1:
> 
> "In my quick glance, I did not see that statistics would be taught,
> but I did see that R would be taught.  Of course, R is a statistics
> programme. I worry that teaching R could overwhelm the class.  Or
> teaching R would be worthless, because the students do not understand
> statistics. " (Prof LR)
> 
> Comment 2:
> 
> Finally, on a minor point, why is "R" the statistical software being
> used? SPSS is probably more widely available in the workplace –
> certainly in areas of social policy etc. " (Prof NB)
> 
> I am interested to know if any of you have faced similar questions
> from colleagues about inclusion of R in non-statistics based
> university graduate courses. If you did and were required to address
> these concerns, how you would respond?
> 
> TIA,
> Arin Basu
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Using-R-in-a-university-course%3A-dealing-with-proposal-comments-tp15405138p15412757.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] Transfer Crosstable to Word-Document

2008-02-20 Thread bartjoosen



Greg Snow-2 wrote:
> 
> 
>> write.table(my.data, 'clipboard', sep="\t")
> 
> Then in Excel just do a paste and the data is there, this saves a couple
> of steps from saving as a .csv file and importing that into excel.  This
> would probably be fine for a few tables.
> 
> 
> 

Just to inform: 

if you use write.table(my.data,'whateverfile.xls',sep="\t", quote=FALSE),
you can open this file right from the windows explorer as a normal excel
file.
If you're already running excel and choose file>open, you will get a dialog
box, where you have to click complete or OK.


Bart

-- 
View this message in context: 
http://www.nabble.com/Transfer-Crosstable-to-Word-Document-tp15504150p15586769.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] Transfer Crosstable to Word-Document

2008-02-22 Thread bartjoosen

I must admit it's a very bad practice, but if you put these files in a
separate folder, and you know what you have been busy with, I think it's
less important. At least it saves you some mouse clicks

But Philippe, you are absolutely rigth about the bad practice!


Bart

Philippe Grosjean wrote:
> 
> 
> 
> Yes, but it is a very bad practice to name a file with .xls extension 
> that is not in Excel file format (here, a tab-separated ASCII file)!
> Best,
> 
> Philippe Grosjean
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Transfer-Crosstable-to-Word-Document-tp15504150p15632864.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] Multiple linear regression with for loop

2008-02-27 Thread bartjoosen

I'm not sure if this is what you want but if you have a matrix as response,
you can use the matrix ~ term:
example:
x <- 1:10
y <- rep(rnorm(10,x,0.5),10)
dim(y) <- c(10,10)
y <- as.matrix(y)
coef(lm(y~x))


Bart


Markus "Mühlbacher" wrote:
> 
> Hi everyone!
> 
>  I have an array containing the following fields for over hundred
> compounds:
> cpd, activity, fixterm, energy1, energy2, energy3, ...
> 
> I want to run a multiple linear regression on all entries of an array.
> Therefore I tried to do this with a for loop. (Maybe there is a direct way
> of calculating it using apply, but I don't know that either.)
>  
>  Actually i tried the following code:
>  
>  ...
>  > attach(data)
>  > for(i in 1:length(cpd)) {
>  > fitted.model <- lm(activity ~ fixterm + i)
>  > coef(fitted.model)
>  > }
>  ...
>  
>  Unfortunatly this loop doesn't give the intended correlation coefficients
> of each regression. If I insert a line "print(i)" into the loop the
> desired values for i are printed correctly. Only the coefficient outputs
> are missing.
>  Probably the solution is very near, but I just can't see it.
>  
>  Many thanks in advance,
>  Markus
>  
>
> -
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Multiple-linear-regression-with-for-loop-tp15703017p15711401.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] printing tables to a pdf

2008-02-29 Thread bartjoosen

Hi Georg,

see textplot in the gplots package
another way is thru sweave and latex, pdf -> latex


Bart



Georg Ehret wrote:
> 
> Dear R community,
>I wish to print tables into a pdf file. How can this be done,
> adding
> headers and several tables to the same file?
> 
> Thanking you for your attention,
> Georg.
> *
> Georg Ehret
> Johns Hopkins
> Baltimore - US
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/printing-tables-to-a-pdf-tp15764732p15765465.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] time experiment

2008-02-29 Thread bartjoosen

A simple RSiteSearch:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/63840.html


Bart


Luís Paulo F. Garcia wrote:
> 
> How do i for have a time of experiment? Have a package for this? Or
> function? In my case the time of experiment is learning machining (svm).
> 
> Tanks :)
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/time-experiment-tp15763897p15765472.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] CREATE INTERFACE TO SELECT DIFERENT OPTIONS

2008-03-06 Thread bartjoosen



ermimi wrote:
> 
> Hello, I´m spanish student, and I´m making the finish project of computer
> science. I´m working in R and I need create a Interface which allow me
> select diferents execution options (similar to a menu). Is posible to
> create this menu,or interface, with R? or I have create this interface
> with other language. 
> 
> Thank you very much, and I hope that you understand my english.
> 


You didn't mention your OS, but if you are on Windows, take a look at
?winMenuAddItem
-- 
View this message in context: 
http://www.nabble.com/CREATE-INTERFACE-TO-SELECT-DIFERENT-OPTIONS-tp15872171p15883374.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] odfWeave examples not working

2008-03-12 Thread bartjoosen

Hi,

I'm currently taking a look at possibilities to report my results, produced
by R.
After looking at LaTex, I'm now considering the odf format, as most people
at my
company work with MS Word. So using odfWeave would be my best bet probably.

But if I run some examples from the odfWeave package, I cant open the output
in Open Office:

demoFile <- system.file("examples", "simple.odt", package = "odfWeave")
outputFile <- gsub("simple.odt", "output.odt", demoFile)
library(odfWeave)
odfWeave(demoFile, outputFile)

This will produce output.odt, which should be opened with OpenOfficeWriter I
think.

But if I run the code above, I get a warning message:
In strsplit(x, ".", extend = FALSE, fixed = TRUE) :
  argument 'extended = FALSE' will be ignored

If I open output.odt, I get a message box from open office to select a
filter used to open the file.
When I choose "open office 1.0 text document" I get: The file is damaged,
should Oo try to repair?
But after repair, I get a blank work sheet.


I'm working on windows XP, session info:
R version 2.6.2 (2008-02-08) 
i386-pc-mingw32 

locale:
LC_COLLATE=Dutch_Belgium.1252;LC_CTYPE=Dutch_Belgium.1252;LC_MONETARY=Dutch_Belgium.1252;LC_NUMERIC=C;LC_TIME=Dutch_Belgium.1252

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

other attached packages:
[1] MASS_7.2-40odfWeave_0.7.3 XML_1.93-2.2   lattice_0.17-4

loaded via a namespace (and not attached):
[1] tools_2.6.2




Kind regards

Bart
-- 
View this message in context: 
http://www.nabble.com/odfWeave-examples-not-working-tp16000639p16000639.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] hello! i need help for a specific graphic issue

2008-03-12 Thread bartjoosen

quick (and dirty) solution:

y.up<- means+stand.error
y.dwn<- means-stand.error

plot(means,ylim=c(3.5,10))
for (i in 1:length(means)) arrows(i,means[i],i,y.up[i],length=0.1)
for (i in 1:length(means)) arrows(i,means[i],i,y.dwn[i],length=0.1)




Giacomo Prodi wrote:
> 
> hello, ladyes and gentlemans.
> 
> check this:
> 
> means<-c(4,6,8)
> stand.error<-c(0.1,0.3,0.5)
> 
> now i've strongly tryed to scatterplot the
> means(y-axis),by showing their sd with the
> arrow(..,code=3,angle=90) function.
> The problem is that my x-axis has categorical values
> (say, factor(x)), and the arrows() can't recognize
> them as right coordinates.
> ?
> thank you all in advance
> B.F. insubria university (varese)
> 
> 
> 
> La web mail più usata al mondo.
> http://it.docs.yahoo.com/mail/overview/index.html
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/hello%21-i-need-help-for-a-specific-graphic-issue-tp16002183p16002532.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] howto find corresponding values in datasource?

2008-03-13 Thread bartjoosen

The x coordinate of the max y value:

x[which.max(mydiff$y)]




Jonas Stein wrote:
> 
> Hi,
> 
> 
> i am sure, that this is a noob-question, but i have searched for 
> hours without any good result. 
> 
> I want to draw a vertical line through the maximum of the first
> derivation.
> 
> Here is a small example. 
> 
> --8<-[mydata.csv]
> HM
> 115
> 222
> 323
> 417
> 510
> --8<-[myquestion.R]--
> mydata <- read.table("mydata.csv", header=TRUE, sep="\t")
> 
> attach(mydata)
> # make a smooth fit through the points and calculate the first derivation
> d/dx
> myspl <- smooth.spline(H, M, all.knots = FALSE, nknots = 10, spar=0.5) 
> mydiff <- predict(myspl, 0:max(H), deriv=1)
> 
> 
> # find the maximum peak max(y)
> y1=y2= max(mydiff$y)
> 
> # now i want to plot a line through the maximum of the derivation
> # how can i get the x-coordinate?
> # segments(x1,y1,x2,y2)
> 
> detach()
> --8<-
> 
> Thank you,
> 
> -- 
> Jonas Stein
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/howto-find-corresponding-values-in-datasource--tp16016130p16023738.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] (no subject)

2008-03-17 Thread bartjoosen

There are several mistakes:
Why are you using only p[1], p[2]? 
Afterwards you try (for i in 1:10) p[i] so you should go to p[10]?
Then you should make a pnew wich holds 10 values, so pnew[i]

This should get you back on track

Bart



Kathy Maher wrote:
> 
> Hi,
> 
> I am trying to use the Fisher scoring method with a geometric
> distribution,
> with p = .07, 100 observations from the geom distrib,  and 10 iterations.
> I cannot quite get the code to work.
> Can anyone see the mistake?
> 
> 
> 
> 
> n <- 100
> 
>  p <- 0.07
> 
>  x <- rgeom(n, p)
> 
> s  <- sum(x)
> 
>  f <- function(x, p) p*(1-p)^x
> 
>  L <- function(p)  p^n*(1-p)^s
> 
> logL <- function(p)  n*log(p)+s*(log(1-p))
> 
> logLprime <- function(p)  (n/p)-(s/(1-p))
> 
> 
> 
> I <- n/p^2*(1-p)
> 
> iter <- 10
> 
> p[1] <- .06
> 
> p[2] <- .11
> 
> 
> 
> 
> 
> for (i in 1:10)
> 
> {
> 
> pnew <- p[i]+logLprime(p[i])/I*(p[i])
> 
> }
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/%28no-subject%29-tp16084593p16093575.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] Creating plots for all variables in a data frame and printing them with the variable name in the main title

2008-03-17 Thread bartjoosen

Here is one way:
lapply(1:ncol(x),function(i) hist(x[,i], main =paste("Histogram
of",names(x)[i])))

Bart


Uli Kleinwechter wrote:
> 
> Dear all,
> 
> I'm just trying to create plots for all variables in a dataframe (named 
> "x") using the following:
> 
> png()
> apply(x,2,hist)
> 
> Just as intended, it produces one plot for each variable. Unfortunately, 
> the main title of each graph is "Histogram of newX[,i]" instead of 
> "Histogram of name of variable". This makes it impossible to assign the 
> graphs to the variables. Is there a way to change this and to make R use 
> the correct variable names in the title of the plot?
> 
> Thank you very much,
> 
> Uli
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Creating-plots-for-all-variables-in-a-data-frame-and-printing-them-with-the-variable-name-in-the-main-title-tp16092442p16093308.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] Error when producing multiple graphes

2008-03-19 Thread bartjoosen

Could you provide us some working codo, so that we can reproduce the error
and see what went wrong?



Uli Kleinwechter wrote:
> 
> Dear all,
> 
> Within a larger script I use the following code to produce barplots for 
> all variables contained in a dataframe "type3m":
> 
> for(xn in names(type3m)) barplot(table(type3m[[xn]]), main = paste
> ("Barplot of", xn), width=0.75,legend.text=barnamesm,
> xlim=c(0,4),ylim=c(0,400))
> 
> The plots are produced and printed into a *.ps file. However, R gives an 
> error message and aborts the script. The error message is:
> 
> Fehler in rect(as.double(xleft), as.double(ybottom),
> as.double(xright),  :
> ungültiges erstes Argument
> 
> (it's in German. In English, it says something like "Error in 
> rect(as.double(xleft), as.double(ybottom), as.double(xright),  : invalid 
> first argument)
> 
> It seems to be some problem with the barplot function. The variables in 
> the dataframe are discrete variables taking values from 1 to 4 (hence, 
> the xlim=c(0,4) and the graph is supposed to show the frequency of each 
> value. Maybe the problem is related to the fact that not some variables 
> don't take all of the values, i.e., there are some that don't take the 
> value 1, for example.
> 
> I spent quite some time trying to solve the problem, but can't manage 
> it. What's wrong here and how can it be solved?
> 
> Thank you very much!
> 
> Uli
> 
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Error-when-producing-multiple-graphes-tp16123596p16140831.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] Incorrect order

2008-10-29 Thread bartjoosen

What's wrong with that result?
you should look at the result as: first take the 3th element of a, then the
first one, than the second one and then the fourth.

if you do a[order(a)] then you get 15,20,30,40.

I suppose you expected:
rank(a)
[1] 2 3 1 4

Good luck

Bart


lll73 wrote:
> 
> 
> I am using the order function and the result seems to be incorrect:
> 
>> a<-c(20,30,15,40)
>> order(a)
> [1] 3 1 2 4
> 
> Any suggestions?
> 
> Thanks,
> Laura
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Incorrect-order-tp20224993p20225235.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] need some help

2008-11-03 Thread bartjoosen

see ?merge



Kurapati,
Ravichandra (Ravichandra) wrote:
> 
> Hi ,
> 
>  
> 
>> df 
> 
> Session_Setup   DCT FwdDataVols_bin countsComp
> 
> 1  User_Initiated NoRLL   1   5058  User_Initiated+NoRLL+1
> 
> 2  User_Initiated NoRLL   2584  User_Initiated+NoRLL+2
> 
> 3  User_Initiated NoRLL   3191  User_Initiated+NoRLL+3
> 
> 4  User_Initiated NoRLL   4128  User_Initiated+NoRLL+4
> 
> 5  User_Initiated NoRLL   5 90  User_Initiated+NoRLL+5
> 
> 6  User_Initiated NoRLL   6 43  User_Initiated+NoRLL+6
> 
> 7  User_Initiated NoRLL   7 45  User_Initiated+NoRLL+7
> 
> 8  User_Initiated NoRLL   8 35  User_Initiated+NoRLL+8
> 
> 9  User_Initiated NoRLL   9 45  User_Initiated+NoRLL+9
> 
> 10 User_Initiated NoRLL  10 20 User_Initiated+NoRLL+10
> 
> 11 User_Initiated NoRLL  12 20 User_Initiated+NoRLL+12
> 
> 12 User_Initiated NoRLL  13 15 User_Initiated+NoRLL+13
> 
> 13 User_Initiated NoRLL  14 25 User_Initiated+NoRLL+14
> 
> 14 User_Initiated NoRLL  15  5 User_Initiated+NoRLL+15
> 
> 15 User_Initiated NoRLL  17  5 User_Initiated+NoRLL+17
> 
> 16 User_Initiated NoRLL  18 10 User_Initiated+NoRLL+18
> 
> 17 User_Initiated NoRLL  19 10 User_Initiated+NoRLL+19
> 
> 18 User_Initiated NoRLL  21  5 User_Initiated+NoRLL+21
> 
> 19 User_Initiated NoRLL  22 30 User_Initiated+NoRLL+22
> 
> 20 User_Initiated NoRLL  23 10 User_Initiated+NoRLL+23
> 
> 21 User_Initiated NoRLL  24 15 User_Initiated+NoRLL+24
> 
> 22 User_Initiated NoRLL  25  5 User_Initiated+NoRLL+25
> 
> 23 User_Initiated NoRLL  27  5 User_Initiated+NoRLL+27
> 
> 24 User_Initiated NoRLL  28 10 User_Initiated+NoRLL+28
> 
> 25 User_Initiated NoRLL  29 10 User_Initiated+NoRLL+29
> 
> 26 User_Initiated NoRLL  30  5 User_Initiated+NoRLL+30
> 
> 27 User_Initiated   RLL   1 50User_Initiated+RLL+1
> 
> 28 User_Initiated   RLL   2 10User_Initiated+RLL+2
> 
> 29 User_Initiated   RLL   3  5User_Initiated+RLL+3
> 
> 30 User_Initiated   RLL   8  5User_Initiated+RLL+8
> 
> 31 User_Initiated   RLL  23  5   User_Initiated+RLL+23
> 
> 32  Session_Setup NoRLL   1749   Session_Setup+NoRLL+1
> 
>  
> 
>  
> 
>  
> 
>  
> 
> Df contains
> 
> Session_Setup   DCT FwdDataVols_bin countsComp
> 
> 1Session_Setup   RLL   1  0 Session_Setup+RLL+1
> 
> 2Session_Setup   RLL   2  0 Session_Setup+RLL+2
> 
> 3Session_Setup   RLL   3  0 Session_Setup+RLL+3
> 
> 4Session_Setup   RLL   4  0 Session_Setup+RLL+4
> 
> 5Session_Setup   RLL   5  0 Session_Setup+RLL+5
> 
> 6Session_Setup   RLL   6  0 Session_Setup+RLL+6
> 
> 7Session_Setup   RLL   7  0 Session_Setup+RLL+7
> 
> 8Session_Setup   RLL   8  0 Session_Setup+RLL+8
> 
> 9Session_Setup   RLL   9  0 Session_Setup+RLL+9
> 
> 10   Session_Setup   RLL  10  0Session_Setup+RLL+10
> 
> 11   Session_Setup   RLL  11  0Session_Setup+RLL+11
> 
> 12   Session_Setup   RLL  12  0Session_Setup+RLL+12
> 
> 13   Session_Setup   RLL  13  0Session_Setup+RLL+13
> 
> 14   Session_Setup   RLL  14  0Session_Setup+RLL+14
> 
> 15   Session_Setup   RLL  15  0Session_Setup+RLL+15
> 
> 16   Session_Setup   RLL  16  0Session_Setup+RLL+16
> 
> 17   Session_Setup   RLL  17  0Session_Setup+RLL+17
> 
> 18   Session_Setup   RLL  18  0Session_Setup+RLL+18
> 
> 19   Session_Setup   RLL  19  0Session_Setup+RLL+19
> 
> 20   Session_Setup   RLL  20  0Session_Setup+RLL+20
> 
> 21   Session_Setup   RLL  21  0Session_Setup+RLL+21
> 
> 22   Session_Setup   RLL  22  0Session_Setup+RLL+22
> 
> 23   Session_Setup   RLL  23  0Session_Setup+RLL+23
> 
> 24   Session_Setup   RLL  24  0Session_Setup+RLL+24
> 
> 25   Session_Setup   RLL  25  0Session_Setup+RLL+25
> 
> 26   Session_Setup   RLL  26  0Session_Setup+RLL+26
> 
> 27   Session_Setup   RLL  27  0Session_Setup+RLL+27
> 
> 28   Session_Setup   RLL  28  0Session_Setup+RLL+28
> 
> 29   Session_Setup   RLL  29  0Session_Setup+RLL+29
> 
> 30   Session_Setup   RLL  3

Re: [R] Data manipulation question

2008-11-06 Thread bartjoosen

How about: 

id <- c(rep("a",4),rep("b",2), rep("c",5), rep("d",1)) 
start <- c(c(0,6,17,20),c(0,1),c(0,5,10,11,50),c(0)) 
stop <- c(c(6,12,20,30),c(1,10),c(3,10,11,30,55),c(6)) 
data <- data.frame(id,start,stop)

f <- function(data){
m <- match(data$start,data$stop) + 1
if (length(m)==1 && is.na(m)) m <- 1 
if (length(m) > 1 && is.na(m[2])) m <- 1
data$stop[min(m,na.rm=T)]
}

by(data,data$id,f)

The if statements in the function are for some special cases, in all the
other cases the firs line will do the trick.
I would like to add that using data is a somewhat bad behavior, as this
overwrites the build in data function of R.
And I changed the way you made up the data.frame, as your method would
convert everything to factors.

Good luck

Bart



Peter Jepsen wrote:
> 
> Dear R-listers,
> 
> I am a relatively inexperienced R-user currently migrating from Stata. I
> am deeply frustrated by this data manipulation question: I know how I
> could do it in Stata, but I cannot make it work in R.
> 
> I have a data frame of hospitalization data where each row represents an
> admission. I need to know when patients were first discharged, but the
> problem is that patients were sometimes transferred between hospital
> departments. In my data a transfer looks like a new admission, except
> that it has a 'start' date equal to the previous admission's 'stop'
> date.
> 
> Here is an example:
> 
> id <- c(rep("a",4),rep("b",2), rep("c",5), rep("d",1))
> start <- c(c(0,6,17,20),c(0,1),c(0,5,10,11,50),c(0))
> stop <- c(c(6,12,20,30),c(1,10),c(3,10,11,30,55),c(6))
> data <- as.data.frame(cbind(id,start,stop))
> data
> #id start stop
> # 1   a 06
> # 2   a 6   12
> # 3   a17   20
> # 4   a20   30
> # 5   b 01
> # 6   b 1   10
> # 7   c 03
> # 8   c 5   10
> # 9   c10   11
> # 10  c11   30
> # 11  c50   55
> # 12  d 06
> 
> So, what I want to end up with is this:
> 
> id start stop
> a  0 12   # This patient was transferred at time 6 and discharged at
> time 12. The admission starting at time 17 is therefore irrelevant.
> b  0 10   
> c  0 3
> d  0 6
> 
> I have tried tons of variations over lapply, sapply, split, for etc.,
> all to no avail. 
> 
> Thank you in advance for any assistance.
> 
> Best regards,
> Peter Jepsen, MD.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Data-manipulation-question-tp20356835p20358624.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] function that uses a variable name as the parameter

2008-11-12 Thread bartjoosen

You're almost there:


a <- 12 # starting value 

add <- function(variable,increment) { 

variable + increment 

} 


add(a,25) 

you shouldn't assign variable + increment to variable, unless you put a
return in your function:

add <- function(variable,increment) { 
variable <- variable + increment 
return(variable)
} 



Bart


David Croll wrote:
> 
> 
> 
> Hello dear R people!
> 
> 
> Several times it occurred to me that a function that uses a variable name
> as a parameter would be helpful, but I did not find out how to write such
> a function. I have experience in several programming language, but I did
> not come across a helpful trick...
> 
> What I want to have is...
> 
> a <- 12 # starting value
> 
> add <- function(variable,increment) {
> 
> variable <- variable + increment
> 
> }
> 
> # by typing a and 25 for example, you specify that 25 will be added to the
> variable a...
> 
> add(a,25)
> 
> # the new a equals 12 + 25 = 37
> 
> Thanks for all the help – I'll try to give my advice when I get across a
> problem I can solve!
> 
> 
> David
> -- 
> GMX Download-Spiele: Preizsturz! Alle Puzzle-Spiele Deluxe über 60%
> billiger.
> http://games.entertainment.gmx.net/de/entertainment/games/download/puzzle/index.html
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/function-that-uses-a-variable-name-as-the-parameter-tp20459842p20460244.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] While loop set up

2008-11-18 Thread bartjoosen

Hello Rodrigo,

You're almost there:
you should make the variable distance before the while loop, and this should
be higher than 14 to go inside the while loop:
selectmarkers<- function(n=10){ 
  tapply(mm$marker, mm$chr, function(m){ 
distances <- 15
   while (max(distances) > 14) { 
 mars<- sort(sample(m, n)) 

distances<- rep(NA, (length(mars)-1)) 
for (i in 1:(length(mars)-1)) { 
  distances[i]<- mm[mars[i+1], 'loc'] - mm[mars[i], 'loc'] 
  } #end of for loop 
   } # end of while loop 

return (mars) 

}  # end of tapply f(m) 
  ) #tapply 
} # end of selectmarkers 


Also take a look at the diff function, to get rid of the for loop:

selectmarkers2<- function(n=10){ 
  tapply(mm$marker, mm$chr, function(m){ 
distances <-15
   while (max(distances) > 14) { 
 mars<- sort(sample(m, n)) 
distances <- diff(mm[mars, 'loc']) 
} # end of while loop 
return (mars) 

}  # end of tapply f(m) 
  ) #tapply 
} # end of selectmarkers 

for n = 10 this won't be a significant difference, but check for n=80:
system.time(selectmarkers(80)) #127 seconds at my system
system.time(selectmarkers2(80)) #1.44 seconds at my system

Kind regards

Bart Joosen

Rodrigo Gularte wrote:
> 
> I am attempting to sample 10 markers from each chr, with a maximum
> distance
> of 14, calculated by the location of the marker in each chromosome as
> loc[i+1] - loc[i].  I presume the easiest way to do this is with a while
> loop, so that the function keeps resampling when the max distains is
> greater
> than 14. Example code is below.
> 
> I have gon as far as to select markers and calculate the distances, A
> while
> loop with set with max(distances)>14 should work, but I'm not sure where
> to
> set this.
> Any help would be appreciated.
> 
> Rodrigo
> 
> #some markers, chromosomes and locations
> loc<- rep(1:100, 5)
> marker<- paste("A", seq(1:500), sep="")
> chr<- rep(1:5, rep(100,5))
> mm<- data.frame(marker, chr, loc)
> 
> selectmarkers<-
> function(n=10){
>   tapply(mm$marker, mm$chr, function(m){
> 
> #   while (max(distances) > 14) {
>  mars<- sort(sample(m, n))
> 
> distances<- rep(NA, (length(mars)-1))
> 
> for (i in 1:(length(mars)-1)) {
>   distances[i]<- mm[mars[i+1], 'loc'] - mm[mars[i], 'loc']
>   } #end of for loop
> #} # end of while loop
> 
> return (mars)
> 
> }  # end of tapply f(m)
>   ) #tapply
> } # end of selectmarkers
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/While-loop-set-up-tp20555712p20559659.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] count the cumulative for each subject

2008-11-24 Thread bartjoosen

How about:

tapply(dat$x1,dat$subject,function(x) cumsum(x))
which gives you a list for each subject.

this can be converted to a vector:
do.call("c",tapply(dat$x1,dat$subject,function(x) cumsum(x)))

So if your data frame is ordered for your subjects:

cbind(your.data.frame,do.call("c",tapply(dat$x1,dat$subject,function(x)
cumsum(x

Good luck

Bart




Daniel Malter wrote:
> 
> Hi,
> 
> subject=c(1,1,1,2,2,2)
> visit=c(1,2,3,1,2,3)
> x1=c(0.5,1.2,0.7,0.4,0.6,0.1)
> 
> cum=NULL #initialize
> for(i in 1:length(subject)){
> cum[i]=sum(x1[subject[i]==subject&visit[i]>=visit])
> } 
> 
> I am sure there is a way with tapply or similar functions that is
> computationally more efficient. But if your dataset is not very large, the
> above function does the job very well.
> 
> Cheers,
> Daniel
> 
> 
> -
> cuncta stricte discussurus
> -
> 
> -Ursprüngliche Nachricht-
> Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im
> Auftrag von gallon li
> Gesendet: Monday, November 24, 2008 2:22 AM
> An: r-help
> Betreff: [R] count the cumulative for each subject
> 
> I have a data set like the following:
> 
> subject visit x1
> 1 1 0.5
> 1 2 1.2
> 1 3 0.7
> 2 1 0.4
> 2 2 0.6
> 2 3 1.0
> .
> 
> where x1 is the interval between the two visits. Now I want to calculate
> the
> cumulative intervals since the beinging, for example
> 
>  subject visit x1 cum
> 1 1 0.5 0.5
> 1 2 1.2 0.5+1.2
> 1 3 0.7 0.5+1.2+0.7
> 2 1 0.4 0.4
> 2 2 0.6 0.4+0.6
> 2 3 1.0 0.4+0.6+1.0
> .
> 
> is there an easy to generate the last veriable cum? The number of visits
> for
> each subject may be different.
> 
> I also want to choose a subset which correspond to the last observation of
> each subject. I am also wondering if there is a fast way to do so.
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/count-the-cumulative-for-each-subject-tp20656012p20657233.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] intersection of two matrices

2008-12-03 Thread bartjoosen

? merge 


complexkid wrote:
> 
> Hi,
> I have two matrices as follow:
> matrix A =
> 
> a=matrix(c(c("abc","abc","bcd","bcd","bce","bce"),c("a1","d2","d1","d2","a1","a2")),6,2)
> 
> and matrix B which contains pair of values :
>  b=matrix(c(c("a1","a2"),c("a1","d2")),2,2)
> 
>  In short, I wish to find out pairs of values in matrix a[,2] having
> same value in a[,1], which occur as a row in matrix b, so that the
> output becomes :
> abc
> bce, or
> 
> even better
> abc a1 d2
> bce a1 a2
> 
>  How can I do that?
> cheers,
> Joshi
> 
> _
> 
> Ms Tejal Joshi
> 
> Researcher
> Center for Biological Sequence Analysis
> Technical University of Denmark
> Kemitorvet, Building 208
> DK-2800 Kgs. Lyngby, Denmark
> Phone: +45 4525 6148
> [EMAIL PROTECTED]
> www.cbs.dtu.dk
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/intersection-of-two-matrices-tp20811826p20814849.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] Selecting rows that are the same in separate data frames

2008-12-09 Thread bartjoosen

I'm not sure what you want, but take a look at ?merge and %in%


ppaarrkk wrote:
> 
> I want to compare two matrices or data frames and select or get an index
> for those rows which are the same in both. I have tried the following :
> 
> 
> 
> 
> 
> 
> a = matrix ( 1:10, ncol = 2 )
> a
> 
> b = matrix ( c ( 2,3,4,7,8,9 ), ncol = 2 )
> b
> 
> a[a==b]
> 
> 
> 
> 
> 
> 
> a = as.data.frame ( matrix ( 1:10, ncol = 2 ) )
> a
> 
> b = as.data.frame ( matrix ( c ( 2,3,4,7,8,9 ), ncol = 2 ) )
> b
> 
> a[a==b]
> 
> 
> 
> 
> 
> 
> 
> 
> Any ideas please.
> 
> 
> Thanks.
> 
> 
> Simon Parker
> Imperial College
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Selecting-rows-that-are-the-same-in-separate-data-frames-tp20916243p20916727.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] Need help optimizing/vectorizing nested loops

2008-12-09 Thread bartjoosen

Hello,

how about changing the last loop to an apply?

time.test2 <- function(dat) { 
  cen <- dat 
  grps <- 5 
  n.rich <- numeric(grps^2) 
  n.ind <- 1 

  for(i in 1:grps) 
for (j in 1:grps) { 
  n.cen <- numeric(ncol(cen) - 2) 
  neighbours <- expand.grid(X=(j-1):(j+1), Y=(i-1):(i+1)) 
  neighbours <- neighbours[-5,] 
  neighbours <- neighbours[which(neighbours[,1] %in% 1:grps & 
 neighbours[,2] %in% 1:grps),] 
n.rich[n.ind] <-
sum(as.logical(apply(merge(neighbours,cen)[,-c(1,2)],2,sum)))
  n.ind <- n.ind + 1 


} 

return(n.rich) 
} 

The timings on my system:
 system.time(time.test(dat))
   user  system elapsed 
   1.650.031.71 
 system.time(time.test2(dat))
   user  system elapsed 
   0.270.000.27 


I'm still thinking about the optimisation for the selection of the cells,
but for the moment I have no clue about any optimisation for this problem.


Kind Regards

Bart


Tyler Smith wrote:
> 
> Hi,
> 
> I'm analyzing a large number of large simulation datasets, and I've
> isolated one of the bottlenecks. Any help in speeding it up would be
> appreciated.
> 
> `dat` is a dataframe of samples from a regular grid. The first two
> columns are the spatial coordinates of the samples, the remaining 20
> columns are the abundances of species in each cell. I need to calculate
> the species richness in adjacent cells for each cell in the sample. 
> For example, if I have nine cells in my dataframe (X = 1:3, Y = 1:3):
> 
>   a b c
>   d e f
>   g h i
> 
> I need to calculate the neighbour-richness for each cell; for a, this is
> the richness of cells b, d and e combined. The neighbour richness of
> cell e would be the combined richness of all the other eight cells.
> 
> The following code does what I what, but it's slow. The sample dataset
> 'dat', below, represents a 5x5 grid, 25 samples. It takes about 1.5
> seconds on my computer. The largest samples I am working with have a 51
> x 51 grid (2601 cells) and take 4.5 minutes. This is manageable, but
> since I have potentially hundreds of these analyses to run, trimming
> that down would be very helpful.
> 
> After loading the function and the data, the call
> 
>   system.time(tmp <- time.test(dat))
> 
> Will run the code. Note that I've excised this from a larger, more
> general function, after determining that for large datasets this section
> is responsible for a slowdown from 10-12 seconds to ca. 250 seconds.
> 
> Thanks for your patience,
> 
> Tyler
> 
> 
> time.test <- function(dat) {
> 
>   cen <- dat
>   grps <- 5
>   n.rich <- numeric(grps^2)
>   n.ind <- 1
>   
>   for(i in 1:grps)
> for (j in 1:grps) {
>   n.cen <- numeric(ncol(cen) - 2)
>   neighbours <- expand.grid((j-1):(j+1), (i-1):(i+1)) 
>   neighbours <- neighbours[-5,] 
>   neighbours <- neighbours[which(neighbours[,1] %in% 1:grps &
>  neighbours[,2] %in% 1:grps),]
>   
>   for (k in 1:nrow(neighbours))
> n.cen <- n.cen + cen[cen$X == neighbours[k,1] &
>  cen$Y == neighbours[k,2], -c(1:2)]
>   
>   n.rich[n.ind] <- sum(as.logical(n.cen))
>   n.ind <- n.ind + 1
> }
> 
> return(n.rich)
> }
> 
> `dat` <- structure(list(
>   X = c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1,
>   2, 3, 4, 5), Y = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4,
>   4, 4, 4, 4, 5, 5, 5, 5, 5), V1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
>   0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 45L, 131L, 0L, 0L, 34L,
>   481L, 1744L), V2 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
>   0L, 1L, 88L, 0L, 70L, 101L, 13L, 634L, 0L, 0L, 71L, 640L, 1636L), V3
>   = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 49L, 3L, 113L,
>   1L, 44L, 167L, 336L, 933L, 0L, 14L, 388L, 1180L, 1709L), V4 = c(0L,
>   0L, 0L, 0L, 0L, 0L, 3L, 12L, 0L, 0L, 2L, 1L, 36L, 45L, 208L, 7L,
>   221L, 213L, 371L, 1440L, 26L, 211L, 389L, 1382L, 1614L), V5 = c(96L,
>   7L, 0L, 0L, 0L, 10L, 17L, 0L, 5L, 0L, 0L, 11L, 151L, 127L, 160L,
>   27L, 388L, 439L, 1117L, 1571L, 81L, 598L, 1107L, 1402L, 891L), V6 =
>   c(16L, 30L, 13L, 0L, 0L, 10L, 195L, 60L, 29L, 29L, 1L, 107L, 698L,
>   596L, 655L, 227L, 287L, 677L, 1477L, 1336L, 425L, 873L, 961L, 1360L,
>   1175L), V7 = c(249L, 101L, 69L, 0L, 18L, 186L, 331L, 291L, 259L,
>   248L, 336L, 404L, 642L, 632L, 775L, 455L, 801L, 697L, 1063L, 978L,
>   626L, 686L, 1204L, 1138L, 627L), V8 = c(300L, 163L, 65L, 145L, 377L,
>   257L, 690L, 655L, 420L, 288L, 346L, 461L, 1276L, 897L, 633L, 812L,
>   1018L, 1337L, 1295L, 1163L, 550L, 1104L, 768L, 933L, 433L), V9 =
>   c(555L, 478L, 374L, 349L, 357L, 360L, 905L, 954L, 552L, 438L, 703L,
>   984L, 1616L, 1732L, 1234L, 1213L, 1518L, 1746L, 1191L, 967L, 1394L,
>   1722L, 1706L, 610L, 169L), V10 = c(1527L, 1019L, 926L, 401L, 830L,
>   833L, 931L, 816L, 1126L, 1232L, 1067L, 1169L, 1270L, 1277L, 1145L,
>   1159L, 1072L, 1534L, 997L, 391L, 1328L, 1414L, 1037L, 444

Re: [R] Cutting & pasting help examples into script window

2007-09-21 Thread Bartjoosen

Same problem here, it never works

Sys.info()
  sysname   release 
"Windows"  "NT 5.1" 
  version  nodename 
"(build 2600) Service Pack 2"  "PCWXPUPLC1" 
  machine login 
"x86" 

version
   _   
platform   i386-pc-mingw32 
arch   i386
os mingw32 
system i386, mingw32   
status 
major  2   
minor  5.1 
year   2007
month  06  
day27  
svn rev42083   
language   R   
version.string R version 2.5.1 (2007-06-27)


Bart

Gustaf Rydevik wrote:
> 
> On 9/21/07, Muenchen, Robert A (Bob) <[EMAIL PROTECTED]> wrote:
>> Now I'm working in 2.5.1 on a home machine also running XP. It has the
>> same problem, and I think I finally figured it out.
>>
>> I've noticed that if the cursor is directly over the text, it becomes an
>> I-beam. When hovering over the blank space around the text, the cursor
>> becomes an arrow. Selections via the arrow almost always paste properly
>> into a script window. Copies made while selecting with the I-beam cursor
>> almost always fail.
>>
>> Regardless of how the selection is done, a paste into Notepad never
>> fails. Copying from Notepad to a script window never fails, regardless
>> of how the paste into Notepad was selected.
>>
>> Very strange!
>>
>> Bob
>>
>> P.S. almost the testing has been with the ?data.frame and ?summary
>> examples.
>>
>> > -Original Message-
>> > From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
>> > Sent: Thursday, September 20, 2007 7:59 PM
>> > To: Muenchen, Robert A (Bob)
>> > Cc: [EMAIL PROTECTED]
>> > Subject: Re: [R] Cutting & pasting help examples into script window
>> >
>> > On 20/09/2007 1:49 PM, Muenchen, Robert A (Bob) wrote:
>> > > Does this look like a bug? If so, is there a different way to report
>> > it?
>> >
>> > It sounds like a bug, but I can't reproduce it.  You said it is
>> > intermittent on your system.  Can you try to work out the conditions
>> > that reliably trigger it?
>> >
>> > It might be something specific to your system; does anyone else see
>> > this?
>> >
>> > Duncan Murdoch
>>
> 
> I notice the same thing, (R 2.5.0), except I can't get the example to
> paste correctly at all-
> The cursor never turns into I-beam.
> 
> /Gustaf
> 
> 
> 
> -- 
> Gustaf Rydevik, M.Sci.
> tel: +46(0)703 051 451
> address:Essingetorget 40,112 66 Stockholm, SE
> skype:gustaf_rydevik
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Cutting---pasting-help-examples-into-script-window-tf4487442.html#a12812794
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] A weird observation from using read.table

2007-09-23 Thread Bartjoosen

Take a look at ?scan.

There is an explanation for the doubling of the string

Bart



Jun Ding wrote:
> 
> Hi Everyone, 
> 
> Recently I got puzzled by the function read.table,
> even though I have used it for a long time. 
> 
> I have such a file (tmp.txt, 2 rows and 3 columns,
> with a space among columns):
> 
> 1 2'-PDE 4
> 2 3'-PDE 5
> 
> if I do:
> a = read.table("tmp.txt", header = F, quote = "")
> a
>   V1 V2 V3
> 1  1 2'-PDE  4
> 2  2 3'-PDE  5
> 
> Everything is fine. 
> 
> However, if I do:
> a = read.table("tmp.txt", header = F)
> a
>   V1 V2 V3
> 1  2 3'-PDE  5
> 2  1 2'-PDE  4
> 3  2 3'-PDE  5
> 
> I know it is related to the "quote" as the default
> includes '. But how can it get one more row in the
> file? Thank you very much for your help in advance!
> 
> Jun
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/A-weird-observation-from-using-read.table-tf4501505.html#a12848830
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] How to speed up multiple for loop over list of data frames

2007-10-17 Thread Bartjoosen

Maybe I'm wrong, but aren't you calculating just the same as cor(data
frame,method ="spearman"), with some further parameters being monitored?

Could you please provide a  commented, minimal, self-contained, reproducible
code, so that we can see what is actually going on and what is the way you
want it?


 

Dieter Best wrote:
> 
> Hi there, 
>
>   I have a multiple for loop over a list of data frames
>
>   for ( i in 1:(N-1) ) { 
> for ( j in (i+1):N ) { 
> for ( p in 1:M ) { 
> v_i[p]= alist[[p]][i,"v"]
> v_j[p]= alist[[p]][j,"v"]
> }  
> rho_s = cor(v_i, v_j, method = "spearman")
> rho_p = cor(v_i, v_j, method = "pearson" )
> iv = c( iv, min(i, j) )
> jv = c( jv, max(i, j) ) 
> rho_sv = c( rho_sv, rho_s)
> rho_pv = c( rho_pv, rho_p)
> }
> }
>
>   N is of the order of 400, M about 800.
>
>   This takes me an entire day basically. Is there anything I could do to
> speed things up or is cor really that slow?
>
>   -- D
> 
> 
>
> -
> 
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-speed-up-multiple-for-loop-over-list-of-data-frames-tf4638585.html#a13249895
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] Error message on script execution

2007-10-31 Thread Bartjoosen

Maybe you can make a simple r-script (for example a jpg-plot of random
numbers, ) and run this.
This should indicate wether its due to the script or to the call to R.
From this you can work your way further down to the problem:
-if it's the script, alter your script step by step until you found the
problem
-if its the call to R: try to fix this first

Bart



Sébastien-18 wrote:
> 
> Dear R_users,
> 
> I am coming back to you about this problem, since I could not solve it 
> by myself and because I did not receive any reply the first time I put 
> the post on the list.
> 
> Thanks in advance for any help you could provide.
> 
> Sebastien
> 
> Sébastien a écrit :
>> Dear R_users,
>>
>> I have some troubles with a visual basic application I have recently 
>> created. This application automatically creates and executes an R 
>> script based on a dataset and settings defined by the user. The .r 
>> file (Create_Diagnostic_plots.r) is saved first in a given folder and 
>> then call using a CMD BATCH instruction in the shell. The problem is 
>> that the script is not executed on all the computers where this 
>> application has been "installed" (it is a simple .exe) - see the error 
>> message below. Please, note that the script runs fine on all computers 
>> when it is executed from the RGUI interface. My guess is that my CMD 
>> BATCH call is somehow wrong.
>>
>> ### This is the error message found at the end of a so-called 
>> 'Create_Diagnostic_plots.r.Rout' file
>>
>> Error: syntax error, unexpected $undefined in "
>> "
>> Execution halted
>>
>> ### This call is working fine
>>
>> "D:\Program Files\R\R-2.5.1\bin\R.exe" CMD BATCH "E:\My 
>> Documents\3_MyExample\WFEV_Multiple_Model\Create_Diagnostic_plots.r"
>>
>> ### This one is not
>>
>> "C:\Program Files (x86)\R\R-2.5.0\bin\R.exe" CMD BATCH 
>> "D:\SKB\3_MyExample\WFEV_Multiple_Model\Create_Diagnostic_plots.r"
>>
>> I wonder if the problem comes from the brackets in Program Files (x86) 
>> but I could not find anything relevant about that in the help files.
>>
>> As usual, your help will be greaty appreciated.
>>
>> Sebastien
>>
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Error-message-on-script-execution-tf4589215.html#a13504648
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.