Re: [R] help files for a function

2011-03-15 Thread Joshua Wiley
Hi Erin,

There is no "appropriate directory" until you have a package.  Until
the package is built, R will not access and use the help
documentation.  So I guess the answer is, "wherever it is convenient
for you to find and edit as your function develops until the time when
you put it in one of your packages however small and generally not
meant for distribution to others that particular package may be".

Cheers,

Josh

On Tue, Mar 15, 2011 at 9:38 PM, Erin Hodgess  wrote:
> Dear R People:
>
> Suppose I have the following function and I generate the documentation for it:
>
>> f <- function(x) {
> + return(x^2)
> + }
>> prompt(f)
> Created file named 'f.Rd'.
> Edit the file and move it to the appropriate directory.
>>
>
> What would be the appropriate directory if I haven't created my new
> package yet, please?
>
> Thanks,
> Erin
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodg...@gmail.com
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

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


[R] help files for a function

2011-03-15 Thread Erin Hodgess
Dear R People:

Suppose I have the following function and I generate the documentation for it:

> f <- function(x) {
+ return(x^2)
+ }
> prompt(f)
Created file named 'f.Rd'.
Edit the file and move it to the appropriate directory.
>

What would be the appropriate directory if I haven't created my new
package yet, please?

Thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

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


Re: [R] Does R have a "const object"?

2011-03-15 Thread Thomas Lumley
Actually, you can do this using locked bindings.  Look at ?lockBinding

Locked bindings are how namespaces get const function definitions, and
active bindings (on the same help page) are how R CMD check notices
that you are using T and F when you mean TRUE and FALSE.

   -thomas


On Wed, Mar 16, 2011 at 1:52 PM,   wrote:
> Cheer up! R is a step closer to that concept than the old FORTRAN compilers 
> that couldn't even guarantee that 37 was a constant if used repeatedly in a 
> subroutine call.
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of Uwe Ligges
> Sent: Tuesday, March 15, 2011 2:23 PM
> To: xiagao1982
> Cc: r-help
> Subject: Re: [R] Does R have a "const object"?
>
>
>
> On 15.03.2011 15:53, xiagao1982 wrote:
>> Hi, all,
>>
>> Does R have a "const object" concept like which is in C++ language? I want 
>> to set some data frames as constant to avoid being modified unintentionally. 
>> Thanks!
>
>
> Although there is almost never a "No" in R, the best short answer is: "No".
>
> Best,
> Uwe  Ligges
>
>
>>
>>
>>
>> xiagao1982
>> 2011-03-15
>>
>>       [[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.
>
>
>
>
> message may contain confidential information. If you are not the designated 
> recipient, please notify the sender immediately, and delete the original and 
> any copies. Any use of the message by you is prohibited.
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

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


Re: [R] Serial Date

2011-03-15 Thread Raoni Rosa Rodrigues
Hello Mr. Grothendieck, 

thanks for your reply!

Text book that I use (Spector, 2008) dind't comment about this feature of chron 
function... 

I just don't understand why we have 10957 days of difference between dates 
(look that date on your mail seems to be 1981, not 2011), and not the 25568 
days expected due the difference in origin: 1/1/1900 of excel against 1/1/1970 
of chron package.

Best,

Raoni




--- Em ter, 15/3/11, Gabor Grothendieck  escreveu:

> De: Gabor Grothendieck 
> Assunto: Re: [R] Serial Date
> Para: "Raoni Rosa Rodrigues" 
> Cc: "R Help" 
> Data: Terça-feira, 15 de Março de 2011, 11:24
> On Sun, Mar 13, 2011 at 10:00 PM,
> Raoni Rosa Rodrigues
> 
> wrote:
> > Hello R Help,
> >
> > I'm working in a project with a software that register
> date and time data in serial time format. This format is
> used by excel, for exemple. In this format, 40597.3911423958
> is 2011/2/23 09:23:15. First part is number os days since
> 1900/1/1, and second part is a fraction of a day.
> >
> 
> Try this:
> 
> > library(chron)
> > chron(40597.3911423958)
> [1] (02/24/81 09:23:15)
> 
> See R News 4/1 and the references there.
> 
> -- 
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
> 




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


Re: [R] (R) transitions in a Markov Chain

2011-03-15 Thread Kjetil Halvorsen
To add to this, I am sure this have been answerted earlier on the list,
so you could try to search the archives.

On Tue, Mar 15, 2011 at 8:59 PM, Ben Bolker  wrote:
> Estefania Nares  hotmail.com> writes:
>
>> I have to generate 1000 transitions of a discrete time Markov Chain and
>> then give and estimation of the equilibrium distribution.
>>
>> I know the transition matrix.
>>
>> 0.3   0.7   0
>> 0.2   0.5   0.3
>> 0     0.4   0.6
>> Do you know how to do it with R?
>>
>
>  This sounds like homework, and it is the policy of this
> list not to give answers to homework.
>
>  To get you started, though, see
>
> ?matrix
> ?"%*%"
>
> and possibly
> ?eigen
>
>   good luck
>     Ben Bolker
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] File > Save As...

2011-03-15 Thread Duncan Murdoch

On 11-03-15 9:10 PM, Hadley Wickham wrote:

Could getSrcFilename() gain a default argument so that
getSrcFilename() would by default return the path of the executing
script?


No, it needs to see a function defined in that script.


But I thought default arguments were evaluated in the parent
environment?  Does that not follow for source attributes as well?


No, defaults are evaluated in the evaluation frame of the function. 
That's why you can use local variables in them, e.g. the way rgamma uses 
1/rate as a default for scale.


But the point isn't evaluation here:  the point is the parsing.  A 
function gets its source attribute when it is parsed, so getSrcFilename 
needs to be passed something that was parsed in the script.


Duncan Murdoch

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


Re: [R] Questions on dividing lists and tapply

2011-03-15 Thread Henrique Dallazuanna
Try this:

mapply('/', l1, l2, SIMPLIFY = FALSE)

and

tapply(1:5, lapply(indxLi, as.numeric), sum)


On Tue, Mar 15, 2011 at 6:06 PM, Rohit Pandey  wrote:
>
> Hello R community,
>
> I have two questions about using R.
>
> The first is about dividing each element of a list with another similar
> sized list. So, if the first list has two elements and so does the second,
> then the result should also be a list with two elements.
>
> For example, the inputs are:
>
> list(matrix(1:6,ncol=2),matrix(1:6,ncol=2))->l1
> l2<-list(1:3,2)
>
> I want to get a list, l3 with the first element being l1[[1]]/l2[[1]] and
> the second one, l1[[2]]/l2[[2]].
>
> I had asked a similar question before and the solution using mapply works
> well for a list and a vector, but for two lists, it will return an array
> (and not a list).
>
> My second question is about the tapply function.
>
> tapply(1:5,list(c(1,1,2,2,3),c(1,2,1,1,3)),sum)
> will give me:
>
>   1    2    3
> 1  1   2  NA
> 2  7  NA  NA
> 3 NA  NA   5
> The index here is a list: list(c(1,1,2,2,3),c(1,2,1,1,3)).
>
> However, if I get the same index list through one of the other apply
> functions (like by) for example,
> indxLi<-by(rbind(c(1,1,2,2,3),c(1,2,1,1,3)),1:2,function(x){return(x)})
> then the tapply no longer works with this list.
> tapply(1:5,indxLi,sum) gives me the error:
>
> Error in sort.list(y) : 'x' must be atomic for 'sort.list'
> Have you called 'sort' on a list?
>
> Is there a way to use the above list in the tapply function?
>
> Many thanks in advance,
>
> --
> Thanks,
> Rohit
> Mob: 91 9819926213
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



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

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


Re: [R] Matrix building to remove for loops

2011-03-15 Thread Henrique Dallazuanna
Try this:

fi_2 <- diag(1, i)
fi_2[lower.tri(fi_2)] <- 1 - runif(sum(lower.tri(fi_2))) ^ .5
fi_2[upper.tri(fi_2)] <- fi_2[lower.tri(fi_2)]

On Tue, Mar 15, 2011 at 7:51 PM, Brian Pellerin <
brianpatrickpelle...@gmail.com> wrote:

> Hello R users,
>
> I would like to reduce the number of for loops in my code. I build these
> matrices (5 times). The main diagonal are 1s and the two sides along
> the
> main diagonal mirror each other as follows:
>
>
> i<-5
> fi<-matrix(0,nrow=i,ncol=i)#floral inhibition matrix for(r in 1:i){ for(c
> in
> 1:i){ if(r==c){ fi[r,c]<-1 }else if(r fi[r,c]<-fi[c,r] } } }
> fi
>
> Any thoughts?
>
> Sincerely,
> Brian
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

[[alternative HTML version deleted]]

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


Re: [R] (R) transitions in a Markov Chain

2011-03-15 Thread Ben Bolker
Estefania Nares  hotmail.com> writes:

> I have to generate 1000 transitions of a discrete time Markov Chain and 
> then give and estimation of the equilibrium distribution. 
> 
> I know the transition matrix.
> 
> 0.3   0.7   0
> 0.2   0.5   0.3
> 0 0.4   0.6
> Do you know how to do it with R?
> 

  This sounds like homework, and it is the policy of this
list not to give answers to homework.

  To get you started, though, see

?matrix
?"%*%"

and possibly
?eigen

   good luck
 Ben Bolker

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


Re: [R] Does R have a "const object"?

2011-03-15 Thread rex.dwyer
Cheer up! R is a step closer to that concept than the old FORTRAN compilers 
that couldn't even guarantee that 37 was a constant if used repeatedly in a 
subroutine call.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Uwe Ligges
Sent: Tuesday, March 15, 2011 2:23 PM
To: xiagao1982
Cc: r-help
Subject: Re: [R] Does R have a "const object"?



On 15.03.2011 15:53, xiagao1982 wrote:
> Hi, all,
>
> Does R have a "const object" concept like which is in C++ language? I want to 
> set some data frames as constant to avoid being modified unintentionally. 
> Thanks!


Although there is almost never a "No" in R, the best short answer is: "No".

Best,
Uwe  Ligges


>
>
>
> xiagao1982
> 2011-03-15
>
>   [[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.




message may contain confidential information. If you are not the designated 
recipient, please notify the sender immediately, and delete the original and 
any copies. Any use of the message by you is prohibited. 
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] File > Save As...

2011-03-15 Thread Hadley Wickham
>> Could getSrcFilename() gain a default argument so that
>> getSrcFilename() would by default return the path of the executing
>> script?
>
> No, it needs to see a function defined in that script.

But I thought default arguments were evaluated in the parent
environment?  Does that not follow for source attributes as well?

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Two issues: WEKA code in R // Probability Estimation Tree algorithms

2011-03-15 Thread Patrick Skorupka
Hi everyone, 

this email basically pursues two distinct main goals. I appreciate any help! 

First of all I was wondering if there is any possibility to get WEKA files 
(coded in Java) to run in R respectively RWeka. I first considered if it was 
possible with the Weka_interface implemented in RWeka but apparently it is not. 
Is there any way? 

Secondly I am looking for implementations to produce probabilities via 
Probability Estimation Trees. First results can be obtained using RWeka and 
other packages in addition but moreover I am looking for advanced algorithms 
implemented in R / RWeka.  
These include especially m-Estimate and m-Branch for smoothing probabilities, 
curtailment of trees, Kernel Density, weights in tree leafs as well as 
implementations of specific developed algorithms like Random Decision Tree, 
Confusion Tree Factor or Newton Trees for R/RWeka. 
Although I am aware that chance for positive replies regarding this matter is 
very low I decided to give this a go. In case you can help me out with this 
request please feel also free to suggest how I can help you respectively your 
organization in return.

Best regards

Patrick
--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] adding linear regression data to plot

2011-03-15 Thread derek
Hello R,

I would like to print regression data in graph. I mean the output from:
k=lm(formula,data)
summary(k)

Or somehow extract and print only coefficients and R-squared.



--
View this message in context: 
http://r.789695.n4.nabble.com/adding-linear-regression-data-to-plot-tp3357946p3357946.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] Questions on dividing lists and tapply

2011-03-15 Thread Rohit Pandey
Hello R community,

I have two questions about using R.

The first is about dividing each element of a list with another similar
sized list. So, if the first list has two elements and so does the second,
then the result should also be a list with two elements.

For example, the inputs are:

list(matrix(1:6,ncol=2),matrix(1:6,ncol=2))->l1
l2<-list(1:3,2)

I want to get a list, l3 with the first element being l1[[1]]/l2[[1]] and
the second one, l1[[2]]/l2[[2]].

I had asked a similar question before and the solution using mapply works
well for a list and a vector, but for two lists, it will return an array
(and not a list).

My second question is about the tapply function.

tapply(1:5,list(c(1,1,2,2,3),c(1,2,1,1,3)),sum)
will give me:

   123
1  1   2  NA
2  7  NA  NA
3 NA  NA   5
The index here is a list: list(c(1,1,2,2,3),c(1,2,1,1,3)).

However, if I get the same index list through one of the other apply
functions (like by) for example,
indxLi<-by(rbind(c(1,1,2,2,3),c(1,2,1,1,3)),1:2,function(x){return(x)})
then the tapply no longer works with this list.
tapply(1:5,indxLi,sum) gives me the error:

Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?

Is there a way to use the above list in the tapply function?

Many thanks in advance,

-- 
Thanks,
Rohit
Mob: 91 9819926213

[[alternative HTML version deleted]]

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


Re: [R] Matching two vectors

2011-03-15 Thread nblarson
Just use vect_2_id as a subsetting index for vect_1, ie:

vect_2<-vect_1[vect_2_id]


Vincy Pyne wrote:
> 
> Dear R helpers
> 
> Suppose I have a vector as
> 
> vect_1 = c("AAA", "AA", "A", "BBB", "BB", "B", "CCC")
> 
> vect_1_id = c(1:length(vect_1))
> 
> Through some process I obtain
> 
> vect_2_id = c(2, 3, 7), then I need a new vector say vect_2 which will
> give me
> 
> vect2 = ("AA", "A", "CCC")  i.e. I need the subset of vect_1 as per
> vect_2_id.
> 
> Thanking in advance
> 
> Regards
> 
> Vincy
> 
> 
> 
> 
> 
>   [[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://r.789695.n4.nabble.com/Matching-two-vectors-tp3357591p3357603.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] Daily to Monthly Cumulative Returns

2011-03-15 Thread Rahul Kaura


I want to do a daily, weekly and monthly regression between InvestmentGrade 
Credit Spreads (Dependent Variable) and Treasuries (Independent Variable).

My starting point is daily spread data and daily prices for US treasuries.

Should I convert the US Prices into log returns i.e. log(Pt/Pt-1) or simple 
daily returns (Pt/Pt-1 - 1) for this analysis.

What about Credit Spreads - credit spreads is like a return - so should I take 
log(spread) or simply use the spread.

Lastly , the aggregate from daily to weekly or monthly , what functions should 
I 
use - Do I aggregate the log returns or
the simple returns - do I take a simple sum or a cumulative aggregation - and 
how would I do it in R

I am inclined to use the log returns for everything as regressions, correlation 
calculations all assume normality.

But then to aggregate I would need to use the original returns (or spreads) - 
aggregate cumulatively - and then take the log ?


  
[[alternative HTML version deleted]]

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


Re: [R] Finding coordinates for maximum of a function

2011-03-15 Thread derek
I must have mixed it up. Thank you.

--
View this message in context: 
http://r.789695.n4.nabble.com/Finding-coordinates-for-maximum-of-a-function-tp3355369p3357460.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] Stepwise Discriminant... in R

2011-03-15 Thread Ty Smith
I have tried this with my actual data, and everything works smoothly,
including the monotonically decreasing error rates. e.g.:

   formula  Error
1   Cr   0.4167
2  Cr + Mg   0.1667
3 Cr + Mg + Al 0.0417
4   Cr + Mg + Al + Ba   0.

Thank you for your help.

Ty Smith

[[alternative HTML version deleted]]

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


[R] (R) transitions in a Markov Chain

2011-03-15 Thread Estefania Nares


Dear experts,

I have to generate 1000 transitions of a discrete time Markov Chain and 
then give and estimation of the equilibrium distribution. 

I know the transition matrix.

0.3   0.7   0
0.2   0.5   0.3
0 0.4   0.6
Do you know how to do it with R?

Thanks a lot!

Estefania

  
[[alternative HTML version deleted]]

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


[R] how to set the starting value in lme

2011-03-15 Thread jia liu
Hi,
When I fit the mixed-effects model by lme, I got the convergence error code = 1
message = iteration limit reached without convergence (9). Even after I 
increase the iteration numbers, it still did not work. The only way I found to 
avoid the error message is to increase the number of iterations for the EM 
algorithm, which need to be at least 1100. But the weird thing is that the 
correlation between two random coefficients is always around 1, which is not 
true. So I am thinking the error should be related with the improper starting 
value. But I do not know how to set up my desired starting value in lme 
function. Are there anybody know it? Or met the same problem with me before and 
know how to avoid the error? Thank you for your help.
Bests,
Jia


  
[[alternative HTML version deleted]]

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


Re: [R] File > Save As...

2011-03-15 Thread Gene Leynes
The "getSrcFilename" function is exactly what I was trying to describe, and
I'm excited to know that it's on it way!

I have tried to create that type of function, but I didn't think it was
possible with currently available functions.  I would be interested in
seeing how the new function works, maybe I'll check it out using the google
code search 
tool(although
I usually have a hard time making sense of that code).

Please let me briefly clarify this part:

> But it can.  If you open a script and choose save, it will be saved to the
> same place.
>

I just mean that when you do "save as..." R doesn't seem to use the same
information that it uses during a normal save (the directory or script
name).  In other applications like Microsoft Word, or Python's IDLE (screen
shot attached) the user is shown a dialogue box with the file name in the
current directory of that file.

This is a very minor annoyance though.  I only brought it up because I
thought it would be easier to explain than asking about a function that
would do the job of "getSrcFilename", which is really what I was after.

I rarely upgrade my R versions, but this will definitely be an occasion when
I do!

This makes me want to go back and look at the past release notes to see what
other goodies I've been overlooking.

Thanks again,

Gene



On Mon, Mar 14, 2011 at 8:17 PM, Duncan Murdoch wrote:

> On 11-03-14 8:12 PM, Gene Leynes wrote:
>
>> Yes, I understand.  Normally I use Eclipse, which does what I want for
>> "save as..."
>>
>> The bigger issue is that R can't tell the location of an open script,
>> which makes it harder to create new versions of existing work
>>
>
> But it can.  If you open a script and choose save, it will be saved to the
> same place.  Or do you mean an executing script?  There are indirect ways to
> find the name of the executing script.  For example,
> in R-devel (to become 2.13.0 next month), you can do this:
>
>
> cat("This file is ", getSrcFilename(function(){}, full=TRUE), "\n")
>
> The getSrcFilename() function will be new in 2.13.0.  You can do the same
> in earlier versions, but you need to program it yourself.
>
> Duncan Murdoch
>
>
>
>
>
>> Say you have some great analysis going in "Research 2011-01-01" with a
>> folder for data, code, gui, other languages, excel, whatever else.
>>
>> Then you want to make a new folder for Research 2011-01-02" with the
>> same structure.
>>
>> Making sure that you're setting the right directory in the new version
>> adds a layer of complexity which would be nice to avoid.  It would be
>> really nice to just copy the folders, and let the script detect it's own
>> location so that it could read from the data sub-directory, the gui's
>> sub-directory, etc.  What I want to be able to do is copy the tools I
>> create into different client folders so that anyone can just use the
>> tool without changing the source code which is simple for you or I,
>> but prevents newcomers from using the tools.
>>
>> Apparently I'm in the minority on the next part: but the "save as" thing
>> I was describing before seems very strange to me.  As I teach new people
>> R it's always kind of a hangup that requires a little more explanation,
>> but maybe it's the way I'm looking at it.
>>
>> Thanks for your reply Duncan.
>>
>>
>> On Mon, Mar 14, 2011 at 6:57 PM, Duncan Murdoch
>> mailto:murdoch.dun...@gmail.com>> wrote:
>>
>>On 11-03-14 5:03 PM, Gene Leynes wrote:
>>
>>As much as I love R, there are still the occasional shortcomings.
>>
>>I would love to find a solution to the "save as..." problem.
>>
>>Steps to reproduce the problem:
>>
>>1. Open any version of he R GUI in Windows
>>2. Choose "File>  Open" from the menu
>>3. Open a script that is in a different directory
>>4. Choose "File>  Save As" from the menu
>>
>>
>>In just about any other application you would be presented with
>>a GUI
>>showing the current folder of the script and the current name of
>> the
>>script.  You could then edit the name and save.
>>
>>In R, you have to find the directory of the script and the
>>script name.  It
>>can be annoying from a GUI perspective, especially if you
>>typically work in
>>one directory and store your scripts somewhere else, and the
>>problem is
>>worse when you have many script versions or directories.
>>
>>I know there are many ways to work around this issue.
>>I also know about the batch file project.
>>
>>However, it seems like this is something that users shouldn't
>>*need* to work
>>around.
>>
>>I think this is related to the fact that R has no way of knowing
>> the
>>location of any open script file.
>>(Please correct me if I'm wrong about that last part! )
>>
>>I think this has come up be

[R] Matrix building to remove for loops

2011-03-15 Thread Brian Pellerin
Hello R users,

I would like to reduce the number of for loops in my code. I build these
matrices (5 times). The main diagonal are 1s and the two sides along the
main diagonal mirror each other as follows:


i<-5
fi<-matrix(0,nrow=i,ncol=i)#floral inhibition matrix for(r in 1:i){ for(c in
1:i){ if(r==c){ fi[r,c]<-1 }else if(rhttps://stat.ethz.ch/mailman/listinfo/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] To calculate sample size based on generalized wilcoxon test or Tarone-Ware test

2011-03-15 Thread Zhipeng Wang
Dear all,

I am trying to calculate sample size for a clinical research, on the basis
of  generalized wilcoxon test or Tarone-Ware test.
It seems SAS can do this job using it "POWER" procedure, but SAS is not
available to me.
I would be very grateful if you could let me know if any R package or other
tools which could cope with this problem.

Best Regards,

Wang

[[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] Comparing parts of strings

2011-03-15 Thread Ben Hunter
Hi,

I have a vector of strings (categories), each element of which can be
uniquely found in each element of a much longer vector of about 30 or so
differeint factors. I would like to define another factor variable (drawn
from NewFactorListaccording to which string from "categories" is found in
the longer string of factors. Then I'd do it again, with another set of
categories, and make a table based on the new factors. The last part is
easy, but I've never had luck with string manipulation in R.

for(j in 1:length(categories)){
  for(i in 1:nrow(data)){
ifelse(categories[j] %in% as.character(d1[i,
"col"),data$NewFactor[i]<-NewFactorList[j], data$Check<-"NotYet")
  }
}

Thanks,

Ben

[[alternative HTML version deleted]]

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


Re: [R] File > Save As...

2011-03-15 Thread Duncan Murdoch

On 15/03/2011 4:45 PM, Hadley Wickham wrote:

The bigger issue is that R can't tell the location of an open script,
which makes it harder to create new versions of existing work


But it can.  If you open a script and choose save, it will be saved to the
same place.  Or do you mean an executing script?  There are indirect ways to
find the name of the executing script.  For example,
in R-devel (to become 2.13.0 next month), you can do this:


cat("This file is ", getSrcFilename(function(){}, full=TRUE), "\n")

The getSrcFilename() function will be new in 2.13.0.  You can do the same in
earlier versions, but you need to program it yourself.


Could getSrcFilename() gain a default argument so that
getSrcFilename() would by default return the path of the executing
script?


No, it needs to see a function defined in that script.

Duncan Murdoch

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


Re: [R] fitting a distribution to a ecdf plot

2011-03-15 Thread Frank Harrell
If you try more than one or two distributions the final estimates, while
appearing to have higher precision that the ECDF, will actually have the
same precision.  That is because of model uncertainty.  This would be
revealed by bootstrapping.  There is little advantage to using a parametric
model if nonparametric estimates are used as touchstones.

Frank


Lathouri, Maria wrote:
> 
> Hallo
> yes I tried it as well and it works;
> 
> Thank you a lot
> 
> Maria
> 
> 
> From: Dennis Murphy [djmu...@gmail.com]
> Sent: 15 March 2011 21:36
> To: Lathouri, Maria
> Cc: r-help@r-project.org
> Subject: Re: [R] fitting a distribution to a ecdf plot
> 
> Hi:
> 
> The fitdistrplus package from CRAN may be useful. I tried it on your data
> and the lognormal seemed to fit well, apart from the outlier. I just
> followed the vignette that accompanies the package.
> 
> library(fitdistplus)
> 
> plotdist(NOEccu) # ecdf
> descdist(NOEccu, boot = 1000)  # Cullen-Frey graph based on 1000
> bootstrap samples
> 
> # The Cullen-Frey graph suggests that the distribution is somewhere
> between a Gamma and lognormal
> 
> # Weibull
> N1w <- fitdist(NOEccu, 'weibull')
> # Warning messages:
> # 1: In dweibull(x, shape, scale, log) : NaNs produced
> # 2: In dweibull(x, shape, scale, log) : NaNs produced
> plot(N1w)
> summary(N1w)
> 
> # Gamma
> N1g <- fitdist(NOEccu, 'gamma')
> # Warning messages:
> # 1: In dgamma(x, shape, scale, log) : NaNs produced
> # 2: In dgamma(x, shape, scale, log) : NaNs produced
> # 3: In dgamma(x, shape, scale, log) : NaNs produced
> # 4: In dgamma(x, shape, scale, log) : NaNs produced
> plot(N1g)
> summary(N1g)
> 
> # Lognormal
> N1l <- fitdist(NOEccu, 'lnorm')
> plot(N1l)
> summary(N1l)
> 
> Try it out and see if it suits your needs.
> 
> HTH,
> Dennis
> 
> On Tue, Mar 15, 2011 at 9:00 AM, Lathouri, Maria
> ;>
> wrote:
> Dear all,
> 
> I need to plot an cumulative distribution plot of a variable and then to
> fit a distribution to that, probably a weibull or lognormal.
> 
> I have plotted the ecdf as
>> plot(ecdf(x))
> 
> but I haven't managed to fit the distribution. I have as well attached the
> data.
> 
> I would appreciate if you could help me on that.
> 
> Thank you.
> 
> Kind regards
> Maria
> 
> __
> R-help@r-project.org; mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/fitting-a-distribution-to-a-ecdf-plot-tp3357015p3357954.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] fitting a distribution to a ecdf plot

2011-03-15 Thread Lathouri, Maria
Hallo
yes I tried it as well and it works;

Thank you a lot

Maria


From: Dennis Murphy [djmu...@gmail.com]
Sent: 15 March 2011 21:36
To: Lathouri, Maria
Cc: r-help@r-project.org
Subject: Re: [R] fitting a distribution to a ecdf plot

Hi:

The fitdistrplus package from CRAN may be useful. I tried it on your data and 
the lognormal seemed to fit well, apart from the outlier. I just followed the 
vignette that accompanies the package.

library(fitdistplus)

plotdist(NOEccu) # ecdf
descdist(NOEccu, boot = 1000)  # Cullen-Frey graph based on 1000 bootstrap 
samples

# The Cullen-Frey graph suggests that the distribution is somewhere between a 
Gamma and lognormal

# Weibull
N1w <- fitdist(NOEccu, 'weibull')
# Warning messages:
# 1: In dweibull(x, shape, scale, log) : NaNs produced
# 2: In dweibull(x, shape, scale, log) : NaNs produced
plot(N1w)
summary(N1w)

# Gamma
N1g <- fitdist(NOEccu, 'gamma')
# Warning messages:
# 1: In dgamma(x, shape, scale, log) : NaNs produced
# 2: In dgamma(x, shape, scale, log) : NaNs produced
# 3: In dgamma(x, shape, scale, log) : NaNs produced
# 4: In dgamma(x, shape, scale, log) : NaNs produced
plot(N1g)
summary(N1g)

# Lognormal
N1l <- fitdist(NOEccu, 'lnorm')
plot(N1l)
summary(N1l)

Try it out and see if it suits your needs.

HTH,
Dennis

On Tue, Mar 15, 2011 at 9:00 AM, Lathouri, Maria 
mailto:m.lathour...@imperial.ac.uk>> wrote:
Dear all,

I need to plot an cumulative distribution plot of a variable and then to fit a 
distribution to that, probably a weibull or lognormal.

I have plotted the ecdf as
> plot(ecdf(x))

but I haven't managed to fit the distribution. I have as well attached the data.

I would appreciate if you could help me on that.

Thank you.

Kind regards
Maria

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



[[alternative HTML version deleted]]

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


Re: [R] applying to dataframe rows

2011-03-15 Thread andrija djurovic
Hi,

maybe this:

df<-data.frame(a=c(1,2,3,Inf,4,Inf),b=c(Inf,2,3,4,5,8))

df[apply(df,1, function(x) !any(x==Inf)),]
df[apply(df,1, function(x) any(x==Inf)),]

Andrija


On Tue, Mar 15, 2011 at 10:44 PM, Alexy Khrabrov wrote:

> How do I apply a function to every row of a dataframe most naturally?
>  Specifically, I'd like to filter out any row which contains an Inf in any
> column.  Since all columns are numeric, I guess max should work on a row...
>
> -- Alexy
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] applying to dataframe rows

2011-03-15 Thread Alexy Khrabrov
How do I apply a function to every row of a dataframe most naturally?  
Specifically, I'd like to filter out any row which contains an Inf in any 
column.  Since all columns are numeric, I guess max should work on a row...

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


Re: [R] fitting a distribution to a ecdf plot

2011-03-15 Thread Dennis Murphy
Hi:

The fitdistrplus package from CRAN may be useful. I tried it on your data
and the lognormal seemed to fit well, apart from the outlier. I just
followed the vignette that accompanies the package.

library(fitdistplus)

plotdist(NOEccu) # ecdf
descdist(NOEccu, boot = 1000)  # Cullen-Frey graph based on 1000
bootstrap samples

# The Cullen-Frey graph suggests that the distribution is somewhere between
a Gamma and lognormal

# Weibull
N1w <- fitdist(NOEccu, 'weibull')
# Warning messages:
# 1: In dweibull(x, shape, scale, log) : NaNs produced
# 2: In dweibull(x, shape, scale, log) : NaNs produced
plot(N1w)
summary(N1w)

# Gamma
N1g <- fitdist(NOEccu, 'gamma')
# Warning messages:
# 1: In dgamma(x, shape, scale, log) : NaNs produced
# 2: In dgamma(x, shape, scale, log) : NaNs produced
# 3: In dgamma(x, shape, scale, log) : NaNs produced
# 4: In dgamma(x, shape, scale, log) : NaNs produced
plot(N1g)
summary(N1g)

# Lognormal
N1l <- fitdist(NOEccu, 'lnorm')
plot(N1l)
summary(N1l)

Try it out and see if it suits your needs.

HTH,
Dennis

On Tue, Mar 15, 2011 at 9:00 AM, Lathouri, Maria <
m.lathour...@imperial.ac.uk> wrote:

> Dear all,
>
> I need to plot an cumulative distribution plot of a variable and then to
> fit a distribution to that, probably a weibull or lognormal.
>
> I have plotted the ecdf as
> > plot(ecdf(x))
>
> but I haven't managed to fit the distribution. I have as well attached the
> data.
>
> I would appreciate if you could help me on that.
>
> Thank you.
>
> Kind regards
> Maria
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

[[alternative HTML version deleted]]

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


Re: [R] regsubsets() [leaps package] - please share some good examples of use

2011-03-15 Thread Thomas Lumley
On Wed, Mar 16, 2011 at 3:18 AM, agent dunham  wrote:
> Does it mean that regsubsets doesn't work with categorical variables?

No.

> It's because I'm trying the following and I don't know what happens. Any
> help would be appreciated.
>
> varin <- data.frame(v1,v2,...,v7, factor1,..., factor4)
>
> Dependent variable: height
>
> Then:
>
> eu.subsets <- regsubsets(varinc , height,
> method=c("exhaustive"),nvmax=3,nbest =1)
>
> It gives me this errror:
>
> Error en leaps.setup(x, y, wt = weights, nbest = nbest, nvmax = nvmax,  :
>  character variables must be duplicated in .C / .Fortran

As the help says, the first argument x must be either a design matrix
or a model formula.  If you want R to make a design matrix for
categorical variables for you, use a model formula

> By the way, if you introduce weights in regsubsets, is the same as doing
> some kind of robust regression?

No. It's weighted least squares.

-thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

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


Re: [R] Element by element mean of a list of matrices

2011-03-15 Thread hihi
Thank you all, it will help :-)
Bye,
Peter

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


Re: [R] File > Save As...

2011-03-15 Thread Hadley Wickham
>> The bigger issue is that R can't tell the location of an open script,
>> which makes it harder to create new versions of existing work
>
> But it can.  If you open a script and choose save, it will be saved to the
> same place.  Or do you mean an executing script?  There are indirect ways to
> find the name of the executing script.  For example,
> in R-devel (to become 2.13.0 next month), you can do this:
>
>
> cat("This file is ", getSrcFilename(function(){}, full=TRUE), "\n")
>
> The getSrcFilename() function will be new in 2.13.0.  You can do the same in
> earlier versions, but you need to program it yourself.

Could getSrcFilename() gain a default argument so that
getSrcFilename() would by default return the path of the executing
script?

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

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


Re: [R] Does R have a "const object"?

2011-03-15 Thread Duncan Murdoch

On 15/03/2011 2:35 PM, Martin Morgan wrote:

On 03/15/2011 11:34 AM, Duncan Murdoch wrote:
>  On 15/03/2011 2:23 PM, Uwe Ligges wrote:
>>
>>  On 15.03.2011 15:53, xiagao1982 wrote:
>>  >  Hi, all,
>>  >
>>  >  Does R have a "const object" concept like which is in C++ language?
>>  I want to set some data frames as constant to avoid being modified
>>  unintentionally. Thanks!
>>
>>
>>  Although there is almost never a "No" in R, the best short answer is:
>>  "No".
>
>  Very nice answer! Achim, this is a fortune candidate if I ever saw one!

but aren't lockBinding / lockEnvironment a reasonable longer answer? Martin


I think the limitations would also need to be part of the long answer, 
and probably a discussion of environments and scoping rules.  For example,


x <- 1
lockBinding("x", environment())
f <- function() {
  print(x)  # I can see and print the locked variable
  x <- 2  # And change it?  (Not really)
  print(x)
}
f()  # prints a 1 then a 2

Duncan Murdoch

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


Re: [R] Element by element mean of a list of matrices

2011-03-15 Thread Peter Langfelder
On Tue, Mar 15, 2011 at 1:17 PM, hihi  wrote:
> Hi All,
> is there any effiective and dense/compact method to calculate the mean of a 
> list of - of course coincident - matrices on an element by element basis? The 
> resulting matrix' [i, j]-th element is the mean of the list's matrices' [i, 
> j]-th elements respectively...
> Iterating by for statement is quite straightforward, but I am seeking for a 
> more elegant solution, and my attempt with the apply family of functions did 
> not work.

Hi,

in the package WGCNA (I'm the maintainer) we have functions pmean,
pmedian, pquantile etc. if you have your list of matrices in the
variable matList, you should be able to do something like

do.call(pmean, matList)

Example:


library(WGCNA)
a = matrix(c(1:9), 3, 3);
b = a + sample(c(-1, 1), 9, replace = TRUE);
matList = list(a=a, b=b);
do.call(pmean, matList)

results:

> a
 [,1] [,2] [,3]
[1,]147
[2,]258
[3,]369
> b
 [,1] [,2] [,3]
[1,]058
[2,]149
[3,]47   10
> do.call(pmean, matList)
 [,1] [,2] [,3]
[1,]  0.5  4.5  7.5
[2,]  1.5  4.5  8.5
[3,]  3.5  6.5  9.5


HTH,

Peter

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


Re: [R] File > Save As...

2011-03-15 Thread Duncan Murdoch

On 15/03/2011 2:56 PM, Gene Leynes wrote:

The "getSrcFilename" function is exactly what I was trying to describe, and
I'm excited to know that it's on it way!

I have tried to create that type of function, but I didn't think it was
possible with currently available functions.  I would be interested in
seeing how the new function works, maybe I'll check it out using the google
code search 
tool(although
I usually have a hard time making sense of that code).


The source is available in

https://svn.r-project.org/R/trunk/src/library/utils/R/sourceutils.R

Duncan Murdoch


Please let me briefly clarify this part:

>  But it can.  If you open a script and choose save, it will be saved to the
>  same place.
>

I just mean that when you do "save as..." R doesn't seem to use the same
information that it uses during a normal save (the directory or script
name).  In other applications like Microsoft Word, or Python's IDLE (screen
shot attached) the user is shown a dialogue box with the file name in the
current directory of that file.

This is a very minor annoyance though.  I only brought it up because I
thought it would be easier to explain than asking about a function that
would do the job of "getSrcFilename", which is really what I was after.

I rarely upgrade my R versions, but this will definitely be an occasion when
I do!

This makes me want to go back and look at the past release notes to see what
other goodies I've been overlooking.

Thanks again,

Gene



On Mon, Mar 14, 2011 at 8:17 PM, Duncan Murdochwrote:

>  On 11-03-14 8:12 PM, Gene Leynes wrote:
>
>>  Yes, I understand.  Normally I use Eclipse, which does what I want for
>>  "save as..."
>>
>>  The bigger issue is that R can't tell the location of an open script,
>>  which makes it harder to create new versions of existing work
>>
>
>  But it can.  If you open a script and choose save, it will be saved to the
>  same place.  Or do you mean an executing script?  There are indirect ways to
>  find the name of the executing script.  For example,
>  in R-devel (to become 2.13.0 next month), you can do this:
>
>
>  cat("This file is ", getSrcFilename(function(){}, full=TRUE), "\n")
>
>  The getSrcFilename() function will be new in 2.13.0.  You can do the same
>  in earlier versions, but you need to program it yourself.
>
>  Duncan Murdoch
>
>
>
>
>
>>  Say you have some great analysis going in "Research 2011-01-01" with a
>>  folder for data, code, gui, other languages, excel, whatever else.
>>
>>  Then you want to make a new folder for Research 2011-01-02" with the
>>  same structure.
>>
>>  Making sure that you're setting the right directory in the new version
>>  adds a layer of complexity which would be nice to avoid.  It would be
>>  really nice to just copy the folders, and let the script detect it's own
>>  location so that it could read from the data sub-directory, the gui's
>>  sub-directory, etc.  What I want to be able to do is copy the tools I
>>  create into different client folders so that anyone can just use the
>>  tool without changing the source code which is simple for you or I,
>>  but prevents newcomers from using the tools.
>>
>>  Apparently I'm in the minority on the next part: but the "save as" thing
>>  I was describing before seems very strange to me.  As I teach new people
>>  R it's always kind of a hangup that requires a little more explanation,
>>  but maybe it's the way I'm looking at it.
>>
>>  Thanks for your reply Duncan.
>>
>>
>>  On Mon, Mar 14, 2011 at 6:57 PM, Duncan Murdoch
>>  mailto:murdoch.dun...@gmail.com>>  wrote:
>>
>> On 11-03-14 5:03 PM, Gene Leynes wrote:
>>
>> As much as I love R, there are still the occasional shortcomings.
>>
>> I would love to find a solution to the "save as..." problem.
>>
>> Steps to reproduce the problem:
>>
>> 1. Open any version of he R GUI in Windows
>> 2. Choose "File>   Open" from the menu
>> 3. Open a script that is in a different directory
>> 4. Choose "File>   Save As" from the menu
>>
>>
>> In just about any other application you would be presented with
>> a GUI
>> showing the current folder of the script and the current name of
>>  the
>> script.  You could then edit the name and save.
>>
>> In R, you have to find the directory of the script and the
>> script name.  It
>> can be annoying from a GUI perspective, especially if you
>> typically work in
>> one directory and store your scripts somewhere else, and the
>> problem is
>> worse when you have many script versions or directories.
>>
>> I know there are many ways to work around this issue.
>> I also know about the batch file project.
>>
>> However, it seems like this is something that users shouldn't
>> *need* to work
>> around.
>>
>> I

Re: [R] Element by element mean of a list of matrices

2011-03-15 Thread Henrique Dallazuanna
Try this:

l <- list(matrix(rnorm(9), 3), matrix(rnorm(9), 3), matrix(rnorm(9), 3))
Reduce('+', l) / length(l)


On Tue, Mar 15, 2011 at 5:17 PM, hihi  wrote:

> Hi All,
> is there any effiective and dense/compact method to calculate the mean of a
> list of - of course coincident - matrices on an element by element basis?
> The resulting matrix' [i, j]-th element is the mean of the list's matrices'
> [i, j]-th elements respectively...
> Iterating by for statement is quite straightforward, but I am seeking for a
> more elegant solution, and my attempt with the apply family of functions did
> not work.
>
> Thank you,
> by
> Peter
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

[[alternative HTML version deleted]]

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


Re: [R] Element by element mean of a list of matrices

2011-03-15 Thread Claudia Beleites

Peter,

as the matrices in the list have the same shape, you can unlist them 
into an array and then use rowMeans.


HTH

Claudia

Am 15.03.2011 21:17, schrieb hihi:

Hi All,
is there any effiective and dense/compact method to calculate the mean of a 
list of - of course coincident - matrices on an element by element basis? The 
resulting matrix' [i, j]-th element is the mean of the list's matrices' [i, 
j]-th elements respectively...
Iterating by for statement is quite straightforward, but I am seeking for a 
more elegant solution, and my attempt with the apply family of functions did 
not work.

Thank you,
by
Peter

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Element by element mean of a list of matrices

2011-03-15 Thread hihi
Hi All,
is there any effiective and dense/compact method to calculate the mean of a 
list of - of course coincident - matrices on an element by element basis? The 
resulting matrix' [i, j]-th element is the mean of the list's matrices' [i, 
j]-th elements respectively...
Iterating by for statement is quite straightforward, but I am seeking for a 
more elegant solution, and my attempt with the apply family of functions did 
not work.

Thank you,
by
Peter

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


Re: [R] Matching two vectors

2011-03-15 Thread Sarah Goslee
vect_1[vect_2_id]

and perhaps a readthrough of some of the very nice
intro to R materials available online.

Sarah

On Tue, Mar 15, 2011 at 3:41 PM, Vincy Pyne  wrote:
> Dear R helpers
>
> Suppose I have a vector as
>
> vect_1 = c("AAA", "AA", "A", "BBB", "BB", "B", "CCC")
>
> vect_1_id = c(1:length(vect_1))
>
> Through some process I obtain
>
> vect_2_id = c(2, 3, 7), then I need a new vector say vect_2 which will give me
>
> vect2 = ("AA", "A", "CCC")  i.e. I need the subset of vect_1 as per vect_2_id.
>
> Thanking in advance
>
> Regards
>
> Vincy
>
>
>
>
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Matching two vectors

2011-03-15 Thread Vincy Pyne
Dear R helpers

Suppose I have a vector as

vect_1 = c("AAA", "AA", "A", "BBB", "BB", "B", "CCC")

vect_1_id = c(1:length(vect_1))

Through some process I obtain

vect_2_id = c(2, 3, 7), then I need a new vector say vect_2 which will give me

vect2 = ("AA", "A", "CCC")  i.e. I need the subset of vect_1 as per vect_2_id.

Thanking in advance

Regards

Vincy





[[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] Bug in lattice auto.key argument

2011-03-15 Thread JLucke
The Lattice auto.key argument has a bug in R.12.2.

R version 2.12.2 (2011-02-25)
Platform: i386-pc-mingw32/i386 (32-bit)

other attached packages:
[1] lattice_0.19-17

loaded via a namespace (and not attached):
[1] grid_2.12.2

If I set up my plot parameters as

require(lattice)
superpose.line.settings <- trellis.par.get("superpose.line")
str(superpose.line.settings) 
superpose.line.settings$col <- 1
superpose.line.settings$lty <- c(1,2,5) *
superpose.line.settings$lwd <- 2
trellis.par.set("superpose.line",superpose.line.settings)

and then set up my key list as

my.key <- list(space="top", points=FALSE, lines=TRUE, columns=3)

and then run xyplot with the argument auto.key=my.key, 
I do NOT get the proper legend at the top of the plot.
Instead of the lines in the legend having the characteristics of 
lty=c(1,2,5), they have the characteristics of lwd=c(1,2,5).

The auto.key argument works fine in R.12.1

R version 2.12.1 (2010-12-16)
Platform: i386-pc-mingw32/i386 (32-bit)
.
other attached packages:
[1] lattice_0.19-13

loaded via a namespace (and not attached):
[1] grid_2.12.1

 
Joe
[[alternative HTML version deleted]]

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


Re: [R] Help on 'object(s) are masked from 'package:base"

2011-03-15 Thread David Winsemius


On Mar 15, 2011, at 1:03 PM, YAddo wrote:


Dear All:

I am a newbie to R.  I am trying to use the lmsqreg.fit pack,  
although I
have installed(I think) it I am not able to invoke it when  write  
the code

for it.  Here's what I got when I installed it.

package 'lmsqreg' successfully unpacked and MD5 sums checked


And here is what I got with library(lmsqreg):

Attaching package: 'lmsqreg'

The following object(s) are masked from 'package:base':   Version

Qs:

Has anybody encountered this problem before?


Your interpretation of that message is wrong. It just means that the  
function by that name has covered up the base function `Version` of  
the same name. If you wanted to use the base function, it is still  
there and could be accessed by base::Version().


How do I resolve this?



Nothing further needed ... you have successfully loaded that package.

--

David Winsemius, MD
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.


Re: [R] Reporting odds ratios or risk ratios from GLM

2011-03-15 Thread David Winsemius


On Mar 15, 2011, at 1:25 PM, lafadnes wrote:

I am a new R user (am using it through the Rcmdr package) and have  
struggled
to find out how to report OR and RR directly when running GLM models  
(not

only reporting coefficients.)

Example of the syntax that I have used:

GLM.2 <- glm(diarsev ~ treatmentarm +childage +breastfed,
family=binomial(logit), data=fieldtrials2)
summary(GLM.2)

This works well except that I manually have to calculate the OR  
based on the
coefficients. Can I get these directly (with confidence intervals)  
by just

amending the syntax?


Look at predict.glm {stats}. It gives both facilities and the help  
page looks very clear.


--

David Winsemius, MD
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.


Re: [R] Reporting odds ratios or risk ratios from GLM

2011-03-15 Thread Aaron Mackey
OR <- exp(coef(GLM.2)[-1])
OR.ci <- exp(confint(GLM.2)[-1,])

-Aaron

On Tue, Mar 15, 2011 at 1:25 PM, lafadnes  wrote:

> I am a new R user (am using it through the Rcmdr package) and have
> struggled
> to find out how to report OR and RR directly when running GLM models (not
> only reporting coefficients.)
>
> Example of the syntax that I have used:
>
> GLM.2 <- glm(diarsev ~ treatmentarm +childage +breastfed,
> family=binomial(logit), data=fieldtrials2)
> summary(GLM.2)
>
> This works well except that I manually have to calculate the OR based on
> the
> coefficients. Can I get these directly (with confidence intervals) by just
> amending the syntax?
>
> Will be grateful for advice!
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Reporting-odds-ratios-or-risk-ratios-from-GLM-tp3357209p3357209.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.
>

[[alternative HTML version deleted]]

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


Re: [R] Does R have a "const object"?

2011-03-15 Thread Uwe Ligges



On 15.03.2011 19:35, Martin Morgan wrote:

On 03/15/2011 11:34 AM, Duncan Murdoch wrote:

On 15/03/2011 2:23 PM, Uwe Ligges wrote:


On 15.03.2011 15:53, xiagao1982 wrote:
> Hi, all,
>
> Does R have a "const object" concept like which is in C++ language?
I want to set some data frames as constant to avoid being modified
unintentionally. Thanks!


Although there is almost never a "No" in R, the best short answer is:
"No".


Very nice answer! Achim, this is a fortune candidate if I ever saw one!


but aren't lockBinding / lockEnvironment a reasonable longer answer? Martin



Thanks. Indeed they are - and I had a vague idea there might be 
something I did not know, hence I said "there is almost never a \"No\" 
in R".



Uwe




Duncan Murdoch

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





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


[R] Reporting odds ratios or risk ratios from GLM

2011-03-15 Thread lafadnes
I am a new R user (am using it through the Rcmdr package) and have struggled
to find out how to report OR and RR directly when running GLM models (not
only reporting coefficients.)

Example of the syntax that I have used:

GLM.2 <- glm(diarsev ~ treatmentarm +childage +breastfed,
family=binomial(logit), data=fieldtrials2)
summary(GLM.2)

This works well except that I manually have to calculate the OR based on the
coefficients. Can I get these directly (with confidence intervals) by just
amending the syntax?

Will be grateful for advice!

--
View this message in context: 
http://r.789695.n4.nabble.com/Reporting-odds-ratios-or-risk-ratios-from-GLM-tp3357209p3357209.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Help on 'object(s) are masked from 'package:base"

2011-03-15 Thread YAddo
Dear All:

I am a newbie to R.  I am trying to use the lmsqreg.fit pack, although I
have installed(I think) it I am not able to invoke it when  write the code
for it.  Here's what I got when I installed it. 

package 'lmsqreg' successfully unpacked and MD5 sums checked 


And here is what I got with library(lmsqreg):

Attaching package: 'lmsqreg'

The following object(s) are masked from 'package:base':   Version

Qs:

Has anybody encountered this problem before? 

How do I resolve this?

Thank you.


-Y Addo






--
View this message in context: 
http://r.789695.n4.nabble.com/Help-on-object-s-are-masked-from-package-base-tp3357163p3357163.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] Does R have a "const object"?

2011-03-15 Thread Gabor Grothendieck
On Tue, Mar 15, 2011 at 10:53 AM, xiagao1982  wrote:
> Hi, all,
>
> Does R have a "const object" concept like which is in C++ language? I want to 
> set some data frames as constant to avoid being modified unintentionally. 
> Thanks!
>
>

LockBinding will prevent a variable from being modified (but you could
still rm it and then subsequently create a variable of the same name).

> xx <- 33
> lockBinding("xx", .GlobalEnv)
> xx <- 44
Error: cannot change value of locked binding for 'xx'
> rm(xx) # can still do this


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Does R have a "const object"?

2011-03-15 Thread Martin Morgan

On 03/15/2011 11:34 AM, Duncan Murdoch wrote:

On 15/03/2011 2:23 PM, Uwe Ligges wrote:


On 15.03.2011 15:53, xiagao1982 wrote:
> Hi, all,
>
> Does R have a "const object" concept like which is in C++ language?
I want to set some data frames as constant to avoid being modified
unintentionally. Thanks!


Although there is almost never a "No" in R, the best short answer is:
"No".


Very nice answer! Achim, this is a fortune candidate if I ever saw one!


but aren't lockBinding / lockEnvironment a reasonable longer answer? Martin



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.



--
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793

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


Re: [R] Persistent storage between package invocations

2011-03-15 Thread Henrik Bengtsson
It would be nice to have a standard directory where R can write things
this way.  A semi-standard directory is given by
Sys.getenv("R_LIBS_USER"), which defaults to ~/R/.../.  Maybe ~/R/
could serve as that convention?  That way we (various developers etc)
would also not clutter up users home directory in "random" ways.

Personally I prefer a hidden directory, e.g. ~/.R/, but there are pros
and cons with such an approach.

/Henrik


On Tue, Mar 15, 2011 at 8:57 AM, Prof Brian Ripley
 wrote:
> On Tue, 15 Mar 2011, Hadley Wickham wrote:
>
>> Hi all,
>>
>> Does anyone have any advice or experience storing package settings
>> between R runs?  Can I rely on the user's home directory (e.g.
>> tools::file_path_as_absolute("~")) to be available and writeable
>> across platforms?
>
> No.  First, please use path.expand("~") for this, and it does not
> necessarily mean the home directory (and in principle it might not expand at
> all).  In practice I think it will always be *a* home directory, but on
> Windows there may be more than one (and watch out for local/roaming profile
> differences).
>
> Second, it need not be writeable, and so many package authors write rubbish
> in my home directory that I usually arrange it not be writeable to R test
> processes.
>
> If you want something writeable across processes, use dirname(tempdir()) .
>
>>
>> Hadley
>>
>> --
>> Assistant Professor / Dobelman Family Junior Chair
>> Department of Statistics / Rice University
>> http://had.co.nz/
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> --
> Brian D. Ripley,                  rip...@stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Does R have a "const object"?

2011-03-15 Thread Duncan Murdoch

On 15/03/2011 2:23 PM, Uwe Ligges wrote:


On 15.03.2011 15:53, xiagao1982 wrote:
>  Hi, all,
>
>  Does R have a "const object" concept like which is in C++ language? I want 
to set some data frames as constant to avoid being modified unintentionally. Thanks!


Although there is almost never a "No" in R, the best short answer is: "No".


Very nice answer!  Achim, this is a fortune candidate if I ever saw one!

Duncan Murdoch

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


Re: [R] Does R have a "const object"?

2011-03-15 Thread Uwe Ligges



On 15.03.2011 15:53, xiagao1982 wrote:

Hi, all,

Does R have a "const object" concept like which is in C++ language? I want to 
set some data frames as constant to avoid being modified unintentionally. Thanks!



Although there is almost never a "No" in R, the best short answer is: "No".

Best,
Uwe  Ligges






xiagao1982
2011-03-15

[[alternative HTML version deleted]]

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


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


Re: [R] Calculate monthly means

2011-03-15 Thread KATSCHKE, ADRIAN CIV DFAS
You could use the by() function after a little data manipulation.

The first line will create a field just of the date portion of your datetime 
field. Then you can use the by() function to use the indices you desire to 
calculate the mean.

mSamp$cDT <- chron(unlist(strsplit(as.character(mSamp$Collection_Date), split=" 
"))[seq(1,nrow(mSamp),2)], format="y-m-d", out.format="m/d/y")


with(mSamp, by(Value, list(years(cDT), months(cDT)), mean, na.rm=TRUE))

I like using the chron package for my dates and times.

Adrian 

FOR OFFICIAL USE ONLY.  THIS MESSAGE MAY CONTAIN PERSONNEL DATA OR INFORMATION 
COVERED BY THE PRIVACY ACT OF 1974.  PLEASE ENSURE THIS INFORMATION IS 
PROTECTED FROM UNAUTHORIZED ACCESS AND OR DISCLOSURE.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Carl Nim
Sent: Tuesday, March 15, 2011 10:25 AM
To: r-help@r-project.org
Subject: [R] Calculate monthly means

I am trying to calculate monthly means by year of phosphates and nitrates from 
a multi year data set. Can anybody help me out with the most effective way to 
do this?

My data looks like this:

Collection_Date   Test.Name  Value
2000-01-24 17:00:00    Phosphate   0.108
2000-01-24 17:00:00    Nitrate 0.037
2001-11-12 08:45:00    Phosphate   0.45
...


Thanks and sorry for the blatantly "newbie" question.




  
[[alternative HTML version deleted]]

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


Re: [R] How to read only specified columns from a data file

2011-03-15 Thread David Winsemius


On Mar 15, 2011, at 1:11 PM,  wrote:


I think you need to read an introduction to R.
For starters, read.table returns its results as a value, which you  
are not saving.

The probable answer to your question:
Read the whole file with read.table, and select columns you need,  
e.g.:

tab <- read.table(myfile, skip=2)[,1:5]

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org 
] On Behalf Of Luis Ridao

Sent: Tuesday, March 15, 2011 11:53 AM
To: r-help@r-project.org
Subject: [R] How to read only specified columns from a data file

R-help,

I'm trying to read a data file with plenty of columns.
I just need the first 5 but it doe not work by doing something like:


mycols <- rep(NULL, 430) ; mycols[c(1:4)] <- NA
read.table(myfile, skip=2, colClasses=mycols)


I would have suggested:

mycols <- rep(NULL, 430) ; mycols[1:5] <- rep("numeric", 5)
inp <- read.table(myfile, skip=2, colClasses=mycols)
head(inp)

--
David.



Any suggestions?

Thanks in advance

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




message may contain confidential information. If you are not the  
designated recipient, please notify the sender immediately, and  
delete the original and any copies. Any use of the message by you is  
prohibited.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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
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.


Re: [R] How to read only specified columns from a data file

2011-03-15 Thread rex.dwyer
I think you need to read an introduction to R.
For starters, read.table returns its results as a value, which you are not 
saving.
The probable answer to your question:
Read the whole file with read.table, and select columns you need, e.g.:
tab <- read.table(myfile, skip=2)[,1:5]

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Luis Ridao
Sent: Tuesday, March 15, 2011 11:53 AM
To: r-help@r-project.org
Subject: [R] How to read only specified columns from a data file

R-help,

I'm trying to read a data file with plenty of columns.
I just need the first 5 but it doe not work by doing something like:

> mycols <- rep(NULL, 430) ; mycols[c(1:4)] <- NA
> read.table(myfile, skip=2, colClasses=mycols)

Any suggestions?

Thanks in advance

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




message may contain confidential information. If you are not the designated 
recipient, please notify the sender immediately, and delete the original and 
any copies. Any use of the message by you is prohibited. 
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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)

2011-03-15 Thread rex.dwyer
Hi Jon,  I read your question differently.  Is the answer?  - Rex

> ch=scan(stdin(),what=character(0),n=1)
1: f
Read 1 item
> ch
[1] "f"
>

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Bert Gunter
Sent: Tuesday, March 15, 2011 10:09 AM
To: Jonathan P Daily
Cc: r-help@r-project.org
Subject: Re: [R] (no subject)

?strsplit

x <- "ThisIsaString"
y<- strsplit(x,"")

This gives a list, which you can convert to a vector by unlist(y)

Incidentally, you could have found out about strsplit via R's
help.search("character string") (or similar) or even googling "R
string function" . Please use R's native Help capabilities before
posting to the list.

(I will grant that the unlist()  trick may not be that easy to find).

Also, it's often worthwhile searching the Help archives first. Peter
Dalgaard answered this same question here a day or two ago.

Cheers,
Bert



On Tue, Mar 15, 2011 at 6:35 AM, Jonathan P Daily  wrote:
> I was wondering if there is a way to get read in a single keystroke at a
> time in R as a string, akin to ncurses-style interfaces. I looked into
> readLines, readChar, etc. using stdin, but these all require the use of an
> end of line. Has anyone ever had need to do this or have any ideas on how
> to do this?
>
> Thanks,
> Jon
>
> PS I apologize if this double-sends, but I am having mail client issues.
> --
> Jonathan P. Daily
> Technician - USGS Leetown Science Center
> 11649 Leetown Road
> Kearneysville WV, 25430
> (304) 724-4480
> "Is the room still a room when its empty? Does the room,
>  the thing itself have purpose? Or do we, what's the word... imbue it."
> - Jubal Early, Firefly
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



--
Bert Gunter
Genentech Nonclinical Biostatistics

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




message may contain confidential information. If you are not the designated 
recipient, please notify the sender immediately, and delete the original and 
any copies. Any use of the message by you is prohibited. 
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] fitting a distribution to a ecdf plot

2011-03-15 Thread Carlos Ortega
Hi,

One "easy" way to do that is by using the "nls" (nonlinear least square)
library.

Basically you will test with that if your distribution can be adjusted to
the distribution you say it matches (Weibull?) through the adjustment of
some parameters.

The base package includes the "nls" library, but also you can use nlwr() as
well.
Or check the library NISTnls for particular examples.

Regards,
Carlos Ortega
www.qualityexcellence.es

On Tue, Mar 15, 2011 at 5:23 PM, Lathouri, Maria <
m.lathour...@imperial.ac.uk> wrote:

> Actually I have already done a search on that but it was not much of a
> help. That is why I posted it in the r-help in case it was much more
> helpful.
>
> Thank you.
>
> Kind regards
> Maria
>
> 
> From: David Winsemius [dwinsem...@comcast.net]
> Sent: 15 March 2011 16:19
> To: Lathouri, Maria
> Cc: r-help@r-project.org
> Subject: Re: [R] fitting a distribution to a ecdf plot
>
> On Mar 15, 2011, at 12:00 PM, Lathouri, Maria wrote:
>
> > Dear all,
> >
> > I need to plot an cumulative distribution plot of a variable and
> > then to fit a distribution to that, probably a weibull or lognormal.
> >
> > I have plotted the ecdf as
> >> plot(ecdf(x))
> >
> > but I haven't managed to fit the distribution. I have as well
> > attached the data.
>
> Try a search on one of the R search sites with:
>
> "Fitting distributions with R"  # use the quotes
>
>
> >
> > I would appreciate if you could help me on that.
> >
> > Thank you.
> >
> > Kind regards
> > Maria
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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
> 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.
>

[[alternative HTML version deleted]]

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


Re: [R] fitting a distribution to a ecdf plot

2011-03-15 Thread David Winsemius


On Mar 15, 2011, at 12:23 PM, Lathouri, Maria wrote:

Actually I have already done a search on that but it was not much of  
a help. That is why I posted it in the r-help in case it was much  
more helpful.


There is a tutorial by Ricci with the exact title I suggested looking  
for. At the Baron website a search on that quoted string brought up  
about 40 hits, most of them relevant, and one of them was from Ricci  
with a link to his tutorial. The tutorial has one of its early  
examples fitting a Weibull function.


--
David.


Thank you.

Kind regards
Maria


From: David Winsemius [dwinsem...@comcast.net]
Sent: 15 March 2011 16:19
To: Lathouri, Maria
Cc: r-help@r-project.org
Subject: Re: [R] fitting a distribution to a ecdf plot

On Mar 15, 2011, at 12:00 PM, Lathouri, Maria wrote:


Dear all,

I need to plot an cumulative distribution plot of a variable and
then to fit a distribution to that, probably a weibull or lognormal.

I have plotted the ecdf as

plot(ecdf(x))


but I haven't managed to fit the distribution. I have as well
attached the data.


Try a search on one of the R search sites with:

"Fitting distributions with R"  # use the quotes




I would appreciate if you could help me on that.

Thank you.

Kind regards
Maria
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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
West Hartford, CT


David Winsemius, MD
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.


Re: [R] fitting a distribution to a ecdf plot

2011-03-15 Thread Lathouri, Maria
Actually I have already done a search on that but it was not much of a help. 
That is why I posted it in the r-help in case it was much more helpful. 

Thank you.

Kind regards
Maria


From: David Winsemius [dwinsem...@comcast.net]
Sent: 15 March 2011 16:19
To: Lathouri, Maria
Cc: r-help@r-project.org
Subject: Re: [R] fitting a distribution to a ecdf plot

On Mar 15, 2011, at 12:00 PM, Lathouri, Maria wrote:

> Dear all,
>
> I need to plot an cumulative distribution plot of a variable and
> then to fit a distribution to that, probably a weibull or lognormal.
>
> I have plotted the ecdf as
>> plot(ecdf(x))
>
> but I haven't managed to fit the distribution. I have as well
> attached the data.

Try a search on one of the R search sites with:

"Fitting distributions with R"  # use the quotes


>
> I would appreciate if you could help me on that.
>
> Thank you.
>
> Kind regards
> Maria
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
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.


Re: [R] Problem with nls.lm function of minpack.lm package.

2011-03-15 Thread Ravi Varadhan
One things you should do, as Kate suggested, is to check whether the Jacobian 
functiions are correctly code.  You can do this with "numDeriv" package:

require(numDeriv)
?jacobian

Compare the jacobian from numDeriv with your jacobian for a few reasonable 
parameter vectors.  

Ravi.


Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu


- Original Message -
From: Yann Périard Larrivée 
Date: Tuesday, March 15, 2011 11:57 am
Subject: [R] Problem with nls.lm function of minpack.lm package.
To: "r-help@r-project.org" 


> Dear R useRs, 
>  
>  I have a problem with nls.lm function of minpackl.lm package.
>  
>  I need to fit the Van Genuchten Model to a set of data of Theta and 
> hydraulic conductivity with nls.lm function of minpack.lm package.
>  
>  For the first fit, the parameter estimates keep changing even after 
> 1000 iterations (Th)
>  
>  and
>  
>  I have a following error message for fit of hydraulic conductivity (k);
>  
>  Reason for termination: The cosine of the angle between `fvec' and 
> any column of the
>  Jacobian is at most `gtol' in absolute value.
>  
>  I dont know what I can do for solve my problem
>  
>  Yesterday I asked to Katharine Mullen
>  
>  Here are her aswer
>  
>  Yann Périard
>   
>  Étudiant à la maîtrise en sols et environnement
>  Département des sols et de génie agroalimentaire
>   
>  Centre de Recherche en Horticulture
>  Pavillon Envirotron, Université Laval
>  2480 boulevard Hochelaga, local 2241
>  Québec (Qc), Canada
>  G1V 0A6
>  Tél.: 418-656-2131 poste 8229
>  Courriel : yann.periard-larrive...@ulaval.ca
>  
>  De : Katharine Mullen [kmul...@nist.gov]
>  Date d'envoi : 14 mars 2011 18:05
>  À : Yann Périard Larrivée
>  Objet : Re: your mail
>  
>  Dear Yann Périard,
>  
>  Thanks for including a reproducible example.  The error message you see
>  generally means that nls.lm cannot improve the model fit further, and 
> so
>  is stopping.  This happens when the objective function being minimized
>  (the sum squared residuals) does not change as the algorithm tries to 
> vary
>  the parameters (the way the parameter vector changes is decided by either
>  a finite difference method or the Jacobian function you supply).
>  
>  There are some strange things going on with your models; in the case 
> of
>  this call:
>  
>  out <- nls.lm(par = guess, fn = fcn, jac = fcn.jac,
> fcall = f.Th, jcall = j.Th,
> h = h, Th = Th, control = nls.lm.control(maxfev = integer(),
>  maxiter = 1, nprint=100))
>  
>  The parameter estimates keep changing even after 1000 iterations.  
> This is
>  not good.
>  
>  In the second fit, I change the starting values slightly, to
>  
>  ##starting values (alp = 0.04, n = 1.6, L = 0.5)
>  guess.k <- c(alp = 0.08, n = 1.61, L = 0.51)
>  
>  ## to use an analytical expression for the gradient found in fcn.jac
>  ## uncomment jac = fcn.jac
>  out.k <- nls.lm(par = guess.k, fn = fcn.k, jac = fcn.jac.k,
> fcall = f.k, jcall = j.k,
> h = h, k = k, control = nls.lm.control(gtol = 1, 
> epsfcn =
>  .01,
> factor = 100, maxiter = 1, nprint 
> = 50))
>  
>  and do not get any movement of the parameters toward the correct values.
>  
>  I suggest that you try to figure out what is wrong with your Jacobian
>  functions and/or model functions.  Also consider posting the message 
> you
>  sent me to the R-help mailing list; many people that read this list are
>  interested in nonlinear regression problems, and will be eager to offer
>  their insights.
>  
>  Regarding combination of two residual functions: using finite difference
>  derivatives, it is straightforward.  You define a new residual function,
>  resid2, that evaluates both old residual functions, and returns their
>  scaled sums. So if you had
>  
>  foo1(par1, ...)
>  
>  and foo2(par2, ...)
>  
>  you define
>  
>  resid2 <- function(c(par1,par2), ...) {
>  sse1 <- foo1(par1, ...)
>  sse2 <- foo2(par2, ...)
>  return(sse1 * w1 + sse2 * w2)
>  }
>  
>  w1 and w2 are weights that determine how much each of the old residual
>  functions contributes to the combined fit.
>  
>  Hope this helps, and best regards,
>  Kate
>  
>  --
>  Katharine Mullen
>  Structure Determination Methods Group, Ceramics Division
>  National Institute of Standards and Technology (NIST)
>  100 Bureau Drive, M/S 8520
>  Gaithersburg, MD, 20899, USA
>  phone: 001 301 975 6890
>  email: katharine.mul...@nist.gov
>  
>  On Mon, 14 Mar 2011, Yann Périard Larrivée wrote:
>  
>  > Hi Mrs Mullen
>  >
>  > I have a problem for fitting the following Van Genuchten Model to a 
> set of data of
>  > hydraulic conductivity with nls.lm function of minpack.lm p

Re: [R] Calculate monthly means

2011-03-15 Thread Daniel Kaschek
On Tue, 2011-03-15 at 07:24 -0700, Carl Nim wrote: 
> I am trying to calculate monthly means by year of phosphates and nitrates 
> from a multi year data set. Can anybody help me out with the most effective 
> way to do this?
> 
> My data looks like this:
> 
> Collection_Date Test.Name Value
> 2000-01-24 17:00:00 Phosphate 0.108
> 2000-01-24 17:00:00 Nitrate 0.037
> 2001-11-12 08:45:00 Phosphate 0.45
> ...
> 
> 
> Thanks and sorry for the blatantly "newbie" question.

Let's say you have a data.frame, mydata, with the above data. Then you
could write a function

mymean <- function(year, month, substance) {
  mysub <- subset(mydata,
format(as.PPSIXlt.date(Collection_Date), "%Y") == year,
format(as.POSIXlt.date(Collection_Date), "%b") == month,
Test.Name == substance)
  return(mean(mysub$value))
}

Then you need to apply this function to every combination of year, month
and substance in your data.frame. You can do this by

M <- expand.grid(2000:2010, month.abb, c("Phosphate", "Nitrate"))
meanValues <- apply(M, 1, mymean(myRowEntry[1], myRowEntry[2],
myRowEntry[3])

In the end you can put the result together with M, i.e.

M <- cbind(M, meanValues)




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

-- 
Daniel Kaschek
Physikalisches Institut, Freiburg
Hermann-Herder-Str. 3
79104 Freiburg

Office:  Westbau, 02020
Phone:   +49-761-203-8531


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


Re: [R] JAGS/BUGS on gene expression data

2011-03-15 Thread Mark Leeds
hi: you also may want to look at the admit package. it does metropolis
hastings using a weighted mixture of t-distributions so you just need to
write a function for the likelihood you're trying to get the parameters for.
I don't know about it's speed or efficiency for large data sets but
you could try it and see what happens. I've used it and it was fine but the
data set was
not large. good luck.









On Tue, Mar 15, 2011 at 10:20 AM, nblarson  wrote:

> 64 Bit R w/JAGS seems to be stalling out as well, I ran a test run of 100
> iterations and it's been hanging for 8 hours so that doesn't seem to be the
> solution.  I'll take a look at PYMC.  That CppBUGS package looks pretty
> interesting, I'll keep my eye on it.
>
> My C programming book arrives today from Amazon...so if all else fails...
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/JAGS-BUGS-on-gene-expression-data-tp3354065p3356723.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.
>

[[alternative HTML version deleted]]

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


Re: [R] fitting a distribution to a ecdf plot

2011-03-15 Thread David Winsemius


On Mar 15, 2011, at 12:00 PM, Lathouri, Maria wrote:


Dear all,

I need to plot an cumulative distribution plot of a variable and  
then to fit a distribution to that, probably a weibull or lognormal.


I have plotted the ecdf as

plot(ecdf(x))


but I haven't managed to fit the distribution. I have as well  
attached the data.


Try a search on one of the R search sites with:

"Fitting distributions with R"  # use the quotes




I would appreciate if you could help me on that.

Thank you.

Kind regards
Maria
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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
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.


[R] fitting a distribution to a ecdf plot

2011-03-15 Thread Lathouri, Maria
Dear all,

I need to plot an cumulative distribution plot of a variable and then to fit a 
distribution to that, probably a weibull or lognormal.

I have plotted the ecdf as
> plot(ecdf(x))

but I haven't managed to fit the distribution. I have as well attached the data.

I would appreciate if you could help me on that.

Thank you.

Kind regards
Maria
NOECCu
67.88904443
150.1397457
186.4661306
125.4586537
164.6450167
82.26572728
46.12957405
139.3670831
77.3140337
73.71616087
89.24381267
55.49698407
161.4744795
110.9611291
103.3427988
120.978441
121.3764833
100.1028412
145.5605989
142.3290787
145.3679277
93.62492361
55.48686698
128.11105
69.65897422
77.74185999
115.8001364
50.45232492
90.35071838
132.9893917
77.72242849
64.28160263
54.01295646
83.71891269
134.0958513
64.60377903
48.18032813
130.486115
56.73379201
52.23087454
50.33847793
54.88254634
109.1721021
48.20831769
87.10977697
47.02111749
63.29204939
48.15737916
59.51869418
63.70426227
83.97669506
93.56957986
94.13697821
49.81656675
41.49804514
51.05645798
61.76354398
60.6012629
54.42093914
93.51486665
60.54396105
48.85428234
166.7654584
146.810965
80.95967487
167.2626315
59.47330368
72.86066214
116.4378185
55.64725599
121.2565064
71.47595431
133.7136451
73.82132992
137.8096239
49.83650594
81.08199187
89.36373311
47.72963718
49.02577131
54.0245052
47.18943578
106.7524366
92.86330941
107.7602873
80.46842086
203.1770731
63.47382772
106.0130281
90.67128789
85.91406122
85.65280069
129.637575
81.89671307
115.5356497
65.53656745
129.3789983
83.07309212
95.3862417
47.64942729
44.58198126
65.91324525
85.98441643
173.7522613
68.43518477
62.19982961
60.48931609
79.84400257
196.0585861
79.15253575
198.4031949
188.8371774
67.2503906
76.7620257
154.1797827
84.26522759
70.97081638
56.37466386
129.0594303
114.5855536
73.67967762
536.9946813
78.95253975
71.19112816
51.24938953
67.10699555
93.07971733
52.55033118
48.98038035
71.99776449
87.15210545
120.8311727
63.00287326
67.90228061
87.24346937
170.9653141
174.1646464
51.72208312
55.25671981
67.79918864
52.23148551
68.94684451
58.64711247
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] color under lm line

2011-03-15 Thread Eik Vettorazzi
Hi Keith,
how about this:

fit<-function(x,coefs) x*coefs[2]+coefs[1]
plot(1:10,1:10,type="n")
x<-par("usr")[1:2]
cf1<-c(a=3,b=.5) #eg coefs from a lm-object
cf2<-c(a=1,b=.9) #another line, coloring only intersection
polygon(c(x,rev(x)),c(fit(x,cf1),fit(rev(x),cf2)),col="red")

setting one of the coef vectors to c(0,0) colors the area under the
other line.

hth.

Am 15.03.2011 00:02, schrieb Marlin Keith Cox:
> Hi,
> I would like to add a color under a lm line and not the plotted line.  Is
> this possible?  In the example, I do not want the area under the curve red,
> but rather under the llm line.
> 
> x=seq(0,5,len=100)
> y=-(x-5)^2
> llm<-lm(y~x)
> plot(x,y)
>  polygon(c(x,x[length(x)]), c(y, y[1]), col='red')
> abline(llm)
> keith
> 

-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

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


Re: [R] Persistent storage between package invocations

2011-03-15 Thread Prof Brian Ripley

On Tue, 15 Mar 2011, Hadley Wickham wrote:


Hi all,

Does anyone have any advice or experience storing package settings
between R runs?  Can I rely on the user's home directory (e.g.
tools::file_path_as_absolute("~")) to be available and writeable
across platforms?


No.  First, please use path.expand("~") for this, and it does not 
necessarily mean the home directory (and in principle it might not 
expand at all).  In practice I think it will always be *a* home 
directory, but on Windows there may be more than one (and watch out 
for local/roaming profile differences).


Second, it need not be writeable, and so many package authors write 
rubbish in my home directory that I usually arrange it not be 
writeable to R test processes.


If you want something writeable across processes, use 
dirname(tempdir()) .




Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

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



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

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


[R] How to read only specified columns from a data file

2011-03-15 Thread Luis Ridao
R-help,

I'm trying to read a data file with plenty of columns.
I just need the first 5 but it doe not work by doing something like:

> mycols <- rep(NULL, 430) ; mycols[c(1:4)] <- NA
> read.table(myfile, skip=2, colClasses=mycols)

Any suggestions?

Thanks in advance

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


Re: [R] Newbie-ish question on iteratively applying function to dataframe

2011-03-15 Thread Ista Zahn
Hi Claus,

On Tue, Mar 15, 2011 at 9:33 AM, Claus O'Rourke  wrote:
> Hi,
> I am trying to recursively apply a function to a selection of columns
> in a dataframe. I've had a look around and from what I have read, I
> should be using some version of the apply function, but I'm really
> having some headaches with it.

I would just do it in a loop (see below)
>
> Let me be more specific with an example.
>
> Say I have a data frame similar to the following
>
> A     x     y     z     r1    r2    r3    r4
> 0.1  0.2  0.1 ...
> 0.1  0.3 ...
> 0.2 ...
>
> i.e., a number of columns, each of the same length, and all containing
> real numbers. Of these columns, I want to model one variable, say A,
> as a function of other variables, say x, y, z, and any one of my r1,
> r2, r3, ... variables.
>
> i.e., I want to model
> A ~ x + y + z + r1
> A ~ x + y + z + r2
> 
> A ~ x + y + z + rn
>
> But where the number of 'r' variables I will have will be large, and I
> don't know the specific number of these variables in advance.
>
> My question first is, how can I select all the columns in a dataframe
> that have a heading that matches a string pattern?

?grep

>
> And then related to this, what would be the best way of repeatedly
> applying my modelling function to the result?

Well, I don't know about the "best" way. But why not just

set.seed(21 )
dat <- as.data.frame(matrix(rnorm(10 ), ncol=100, dimnames=list
(1:1000, c("A", "x", "y", "z", paste("r", 1:96, sep="" )

mods <- list()
for(i in grep("r", names(dat ), value=TRUE)) {
mods[[i]] <- lm(as.formula(paste("A ~ x + y + z + ", i)), data=dat )
}

Note that  you should be cautious about making any inferences based on
this kind of method. In the example above 9 r variables are
"significant" at the .05 level, even though the data was generated
"randomly":

sort(sapply(mods, function(x) coef(summary(x))[5, 4]))

Best,
Ista
>
> Many thanks for any help for this occasional R armature.
>
> Claus
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 data set from selection of rows

2011-03-15 Thread Francisco Gochez
Hi,

What you are after is:

datasubset <- dataset[ dataset[,3] == "text3", ]

Equivalently, you can use:

datasubset <- subset(dataset, subset = dataset[,3] == "text3")

HTH,

Francisco

On Tue, Mar 15, 2011 at 3:09 PM, e-letter  wrote:

> Readers,
>
> For a data set:
>
> text1,23,text2,45
> text1,23,text3,78
> text1,23,text3,56
> text1,23,text2,45
>
> The following command was entered:
>
> datasubset<-data.frame(dataset[,3]=="text3")
>
> The result of
>
> datasubset
>
> is
>
> TRUE
> TRUE
>
> The required result is
>
> text1,23,text3,78
> text1,23,text3,56
>
> What is the correct command to use please?
>
> Thanks in advance.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] create data set from selection of rows

2011-03-15 Thread Mohamed Lajnef
Hi,

Le 15/03/11 16:09, e-letter a écrit :
> Readers,
>
> For a data set:
>
> text1,23,text2,45
> text1,23,text3,78
> text1,23,text3,56
> text1,23,text2,45
>
> The following command was entered:
>
> datasubset<-data.frame(dataset[,3]=="text3")
datasubset<-subset(dataset,dataset[,3]=="text3")
> The result of
>
> datasubset
>
> is
>
> TRUE
> TRUE
>
> The required result is
>
> text1,23,text3,78
> text1,23,text3,56
>
> What is the correct command to use please?
>
> Thanks in advance.

> Regards
M

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


-- 

Mohamed Lajnef,IE INSERM U955 eq 15#
Pôle de Psychiatrie#
Hôpital CHENEVIER  #
40, rue Mesly  #
94010 CRETEIL Cedex FRANCE #
mohamed.laj...@inserm.fr   #
tel : 01 49 81 32 79   #
Sec : 01 49 81 32 90   #
fax : 01 49 81 30 99   #




[[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] Problem with nls.lm function of minpack.lm package.

2011-03-15 Thread Yann Périard Larrivée
Dear R useRs, 

I have a problem with nls.lm function of minpackl.lm package.

I need to fit the Van Genuchten Model to a set of data of Theta and hydraulic 
conductivity with nls.lm function of minpack.lm package.

For the first fit, the parameter estimates keep changing even after 1000 
iterations (Th)

and

I have a following error message for fit of hydraulic conductivity (k);

Reason for termination: The cosine of the angle between `fvec' and any column 
of the
Jacobian is at most `gtol' in absolute value.

I dont know what I can do for solve my problem

Yesterday I asked to Katharine Mullen

Here are her aswer

Yann Périard
 
Étudiant à la maîtrise en sols et environnement
Département des sols et de génie agroalimentaire
 
Centre de Recherche en Horticulture
Pavillon Envirotron, Université Laval
2480 boulevard Hochelaga, local 2241
Québec (Qc), Canada
G1V 0A6
Tél.: 418-656-2131 poste 8229
Courriel : yann.periard-larrive...@ulaval.ca

De : Katharine Mullen [kmul...@nist.gov]
Date d'envoi : 14 mars 2011 18:05
À : Yann Périard Larrivée
Objet : Re: your mail

Dear Yann Périard,

Thanks for including a reproducible example.  The error message you see
generally means that nls.lm cannot improve the model fit further, and so
is stopping.  This happens when the objective function being minimized
(the sum squared residuals) does not change as the algorithm tries to vary
the parameters (the way the parameter vector changes is decided by either
a finite difference method or the Jacobian function you supply).

There are some strange things going on with your models; in the case of
this call:

out <- nls.lm(par = guess, fn = fcn, jac = fcn.jac,
   fcall = f.Th, jcall = j.Th,
   h = h, Th = Th, control = nls.lm.control(maxfev = integer(),
maxiter = 1, nprint=100))

The parameter estimates keep changing even after 1000 iterations.  This is
not good.

In the second fit, I change the starting values slightly, to

##starting values (alp = 0.04, n = 1.6, L = 0.5)
guess.k <- c(alp = 0.08, n = 1.61, L = 0.51)

## to use an analytical expression for the gradient found in fcn.jac
## uncomment jac = fcn.jac
out.k <- nls.lm(par = guess.k, fn = fcn.k, jac = fcn.jac.k,
   fcall = f.k, jcall = j.k,
   h = h, k = k, control = nls.lm.control(gtol = 1, epsfcn =
.01,
   factor = 100, maxiter = 1, nprint = 50))

and do not get any movement of the parameters toward the correct values.

I suggest that you try to figure out what is wrong with your Jacobian
functions and/or model functions.  Also consider posting the message you
sent me to the R-help mailing list; many people that read this list are
interested in nonlinear regression problems, and will be eager to offer
their insights.

Regarding combination of two residual functions: using finite difference
derivatives, it is straightforward.  You define a new residual function,
resid2, that evaluates both old residual functions, and returns their
scaled sums. So if you had

foo1(par1, ...)

and foo2(par2, ...)

you define

resid2 <- function(c(par1,par2), ...) {
sse1 <- foo1(par1, ...)
sse2 <- foo2(par2, ...)
return(sse1 * w1 + sse2 * w2)
}

w1 and w2 are weights that determine how much each of the old residual
functions contributes to the combined fit.

Hope this helps, and best regards,
Kate

--
Katharine Mullen
Structure Determination Methods Group, Ceramics Division
National Institute of Standards and Technology (NIST)
100 Bureau Drive, M/S 8520
Gaithersburg, MD, 20899, USA
phone: 001 301 975 6890
email: katharine.mul...@nist.gov

On Mon, 14 Mar 2011, Yann Périard Larrivée wrote:

> Hi Mrs Mullen
>
> I have a problem for fitting the following Van Genuchten Model to a set of 
> data of
> hydraulic conductivity with nls.lm function of minpack.lm package.
> I have a following error message;
>
> Reason for termination: The cosine of the angle between `fvec' and any column 
> of the
> Jacobian is at most `gtol' in absolute value.
> I dont know what I can do for solve my problem
>
> Here his the code
>
> #fonction pour simulation des données de conductivité hydraulique
> f.k <- function(h, alp, n, L, ksat){
>  ksat <- 0.000108
>  k.mod 
> <-expression(ksat+1+(alp*h)^n)^(n-(1/n))-((alp*h)^(n-1)))^2)/((1+(alp*h)^n)^((n-(1/n))*(L+2)
>
>  eval (k)
> }
> #fonction d'aide pour le gradient analytique
> j.k <- function(h, alp, n, L, ksat){
>  ksat <- 0.000108
>  k.mod 
> <-expression(ksat+1+(alp*h)^n)^(n-(1/n))-((alp*h)^(n-1)))^2)/((1+(alp*h)^n)^((n-(1/n))*(L+2)
>
>  c(eval(D(k.mod, "alp")), eval(D(k.mod, "n")), eval(D(k.mod, "L")))
> } 
> h <- hydro$h
> # Paramètre surestimé pour démarer la simulation
> p.k <- c(alp = 0.04, n = 1.6, L = 0.5)
> ## get data with noise
> k <- hydro$k
> ## plot the data to fit
> par(mfrow=c(2,1), mar = c(3,5,2,1))
> plot(h, k, bg = "black", cex = 0.5, main="data", ylab=expression(K(h)), 
> log="y")
>

Re: [R] create data set from selection of rows

2011-03-15 Thread nblarson
Try using which()

Something like data.frame(dataset[which(dataset[,3]=="text3"),])


e-letter wrote:
> 
> Readers,
> 
> For a data set:
> 
> text1,23,text2,45
> text1,23,text3,78
> text1,23,text3,56
> text1,23,text2,45
> 
> The following command was entered:
> 
> datasubset<-data.frame(dataset[,3]=="text3")
> 
> The result of
> 
> datasubset
> 
> is
> 
> TRUE
> TRUE
> 
> The required result is
> 
> text1,23,text3,78
> text1,23,text3,56
> 
> What is the correct command to use please?
> 
> Thanks in advance.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


--
View this message in context: 
http://r.789695.n4.nabble.com/create-data-set-from-selection-of-rows-tp3356866p3356879.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] RE : run a slef-written function

2011-03-15 Thread Wolfgang RAFFELSBERGER
?source

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Wolfgang Raffelsberger, PhD
IGBMC,
1 rue Laurent Fries,  67404 Illkirch  Strasbourg,  France
wolfgang.raffelsberger (at) igbmc.fr


De : r-help-boun...@r-project.org [r-help-boun...@r-project.org] de la part de 
bra86 [anastasia.krikovts...@tugraz.at]
Date d'envoi : mardi 15 mars 2011 14:21
À : r-help@r-project.org
Objet : [R] run a slef-written function

How could one get started with a self-written function?
I have a function written in .txt format, but can not find the way to import
it to the R space.
Would be very appreciated for help.

--
View this message in context: 
http://r.789695.n4.nabble.com/run-a-slef-written-function-tp3356537p3356537.html
Sent from the R help mailing list archive at Nabble.com.

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

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


[R] Fill vector more efficient than element by element?

2011-03-15 Thread beatleb
Dear R useRs,

I am a newbie. Currently, my script is quick long, therefor I am trying to
improve the efficiency of my script. 
I use often a version of the following code, the script below is just a
simple example, but I especially try to improve the last three lines:

matrix1<-diag(100)
a=2

try<-rep(0,10)
for (i in 1:10){
try[i]<-(matrix1[a*(i+5),7]+matrix1[a*(i+7),8]-matrix1[a*(i+8),9])/matrix1[a*(i+6),a*(i+6)]}

Is it possible to obtain the same result, but more efficient? 

Thank you! 

--
View this message in context: 
http://r.789695.n4.nabble.com/Fill-vector-more-efficient-than-element-by-element-tp3356871p3356871.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] Does R have a "const object"?

2011-03-15 Thread xiagao1982
Hi, all,

Does R have a "const object" concept like which is in C++ language? I want to 
set some data frames as constant to avoid being modified unintentionally. 
Thanks!




xiagao1982
2011-03-15

[[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] Polynomial regression problem

2011-03-15 Thread Matthew McKinney
I have just started using R so forgive me if this question is very
simple. I have a data set (in a data frame called dm) that looks like
this

x (Cells)y(males)
1   0
2   2
3   7
4   12
5   12
6   19
7   22
8   23
9   25
10  23
11  23
12  11
13  8
14  3
15  0
16  0


I centered the dependent and predictor variables and then squared the
predictor to make a quadratic variable.
This left me with 3 variables:
MalesC
CellsC
CellsC2

I then used: >quadraticModel <- lm(MalesC ~ CellsC + CellsC2, data = dm)

This has given me R^2= 0.8821, F= 48.63, and p<0.001

I ran the exact same data in sigma plot and got identical results. My
problem comes from the estimated coefficients I am getting in R when
using >summary(quadraticModel). My coefficient estimates in sigma plot
fit my data set well and agree with Microsoft excels estimates. The
results from R appear to be the coefficients of a curve fitting the
residuals. If I >plot(quadraticModel) it does not draw a curve fitting
my data, but rather the residuals.

What I would like to know is how I can get the coefficient estimates
for the data rather than the residuals, and how to plot that in R.

Thanks,
Matthew McKinney

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


Re: [R] run a slef-written function

2011-03-15 Thread Scott Chamberlain
you could run source(directory/textfilename.txt) [and then you can use it in R]

or paste the function into the console, 

or highlight and pass the function from the built in R text editor, 

or highlight and pass the function from your external text editor (notepad++, 
emacs, textwrangler, etc.)
On Tuesday, March 15, 2011 at 8:21 AM, bra86 wrote: 
> How could one get started with a self-written function?
> I have a function written in .txt format, but can not find the way to import
> it to the R space.
> Would be very appreciated for help.
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/run-a-slef-written-function-tp3356537p3356537.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.
> 

[[alternative HTML version deleted]]

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


Re: [R] regsubsets() [leaps package] - please share some good examples of use

2011-03-15 Thread agent dunham
Does it mean that regsubsets doesn't work with categorical variables?

It's because I'm trying the following and I don't know what happens. Any
help would be appreciated. 

varin <- data.frame(v1,v2,...,v7, factor1,..., factor4)

Dependent variable: height

Then:

eu.subsets <- regsubsets(varinc , height,
method=c("exhaustive"),nvmax=3,nbest =1)

It gives me this errror: 

Error en leaps.setup(x, y, wt = weights, nbest = nbest, nvmax = nvmax,  : 
  character variables must be duplicated in .C / .Fortran

By the way, if you introduce weights in regsubsets, is the same as doing
some kind of robust regression?

Thanks, u...@host.com




--
View this message in context: 
http://r.789695.n4.nabble.com/regsubsets-leaps-package-please-share-some-good-examples-of-use-tp885785p3356716.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] JAGS/BUGS on gene expression data

2011-03-15 Thread nblarson
64 Bit R w/JAGS seems to be stalling out as well, I ran a test run of 100
iterations and it's been hanging for 8 hours so that doesn't seem to be the
solution.  I'll take a look at PYMC.  That CppBUGS package looks pretty
interesting, I'll keep my eye on it.

My C programming book arrives today from Amazon...so if all else fails...

--
View this message in context: 
http://r.789695.n4.nabble.com/JAGS-BUGS-on-gene-expression-data-tp3354065p3356723.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] Calculate monthly means

2011-03-15 Thread Carl Nim
I am trying to calculate monthly means by year of phosphates and nitrates from 
a multi year data set. Can anybody help me out with the most effective way to 
do this?

My data looks like this:

Collection_Date   Test.Name  Value
2000-01-24 17:00:00    Phosphate   0.108
2000-01-24 17:00:00    Nitrate 0.037
2001-11-12 08:45:00    Phosphate   0.45
...


Thanks and sorry for the blatantly "newbie" question.




  
[[alternative HTML version deleted]]

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


Re: [R] sample size of 2 groups of skewed data

2011-03-15 Thread Kjetil Halvorsen
did you try to fit your data with a skew-normal/skew-t distribution?
If that works, you can use simulation.

Kjetil

On Tue, Mar 15, 2011 at 2:31 AM, Lao Meng  wrote:
> Hi all:
> I have a question on sample size calculation of 2 groups of data. If 2
> groups of data are all normal distribution, then I can use the function
> "n.indep.t.test.eq" from samplesize package.But if 2 groups of data are all
> skewed distribution, but not normal distribution,how can I calculate the
> sample size then?
> I've tried many transformation (e.g. log arcsin…) in order to transfer the
> skewed distribution data into normal distribution data, but failed. So what
> I can do is only find a calculation method to do with skewed data.
>
> Any suggestions from you are welcome.
> Thanks a lot for your help.
>
> My best.
>
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

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


Re: [R] indeterminate for loop

2011-03-15 Thread lm609

Thanks! I've never come across 'while' before and it's perfect.


On Mar 15 2011, Jonathan P Daily wrote:


?"while"
You don't want a for loop. You need a while loop.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,
the thing itself have purpose? Or do we, what's the word... imbue it."
- Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/15/2011 10:14:21 AM:

[image removed] 


[R] indeterminate for loop

lm609 


to:

r-help

03/15/2011 10:16 AM

Sent by:

r-help-boun...@r-project.org

Hello,

I have written a 'for' loop which on the first run makes nearest 
neighbour 
calculations for my dataset 'A' in relation to dataset 'B', then based 
on 
these results, some of the rows from A are moved into dataset B, and the 


calculation is repeated on the remaining rows in A. Therefore a smaller 
and 
smaller amount of data is analysed as the loop proceeds, since A is 
losing 
rows each time. The results of the calculation change as less data is 
used, 
but not in a predictable way, therefore the end point of the loop is 
indeterminate.


The script is long and the datasets big, but a simplified example where 
'A' 

and 'B' are datasets, and the function 'ndist2' calculates 'x' is...

for (i in 1:100)
{
C <- data.frame(ndist2(B,A))
C1 <- subset(C, x = min(C$x))
B <- rbind(B, C1)
A <- subset(C, x > min(C$x))
}

So eventually A runs out.

Currently, I let the loop run until a warning comes up which effectively 



says no more data, and at this point it is finished.

What I would now like to do is place this loop inside another loop in 
order 
to run through multiple datasets, but I can't do this when the script 
produces a warning message at the end of each dataset.


Is there any way I can overcome this problem?

Thanks for your help,
Louise

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

http://www.R-project.org/posting-guide.html

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





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


Re: [R] Changing colour of continuous time-series in ggplot2

2011-03-15 Thread Hadley Wickham
You need to specify the group aesthetic - that defines how
observations are grouped into instances of a geom.

Hadley

On Tue, Mar 15, 2011 at 8:37 AM, joeP  wrote:
> Hi,
>
> This seems like there should be a simple answer, but having spent most of
> the day trying to find it, I'm becoming less convinced and as such am asking
> it here.
>
> Here's a sub-set of my data (a data.frame in R):
>
> myDF
>                                time     value      trial
> 1   2011-03-01 01:00:00  64092  FALSE
> 2   2011-03-01 02:00:00  47863  FALSE
> 3   2011-03-01 03:00:00  43685  FALSE
> 4   2011-03-01 04:00:00  44821   TRUE
> 5   2011-03-01 05:00:00  48610   TRUE
> 6   2011-03-01 06:00:00  44856   TRUE
> 7   2011-03-01 07:00:00  55199   TRUE
> 8   2011-03-01 08:00:00  69326  FALSE
> 9   2011-03-01 09:00:00  84048  FALSE
> 10 2011-03-01 10:00:00  81341  FALSE
>
> >From this, I can plot a simple time-series in ggplot:
>
> ggplot(myDF, aes(time,value)) + geom_line()
>
> but I'd like to change the colour of the line based on whether the trial
> value is TRUE or FALSE, so I try:
>
> ggplot(myDF, aes(time,value)) + geom_line(aes(colour=trial))
>
> but this draws a line from the value on row 3 to that on row 8 (essentially
> plotting TRUE and FALSE as separate data-sets).  I've tried using various
> other geometries (inc. geom_path()) but all have produced similar events.
> Is there a way I can plot the time-series in a continuous way (i.e. as one
> data-set) and change only the colour of the line?
>
> Thanks,
> Joe
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Changing-colour-of-continuous-time-series-in-ggplot2-tp3356582p3356582.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.
>



-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

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


[R] create data set from selection of rows

2011-03-15 Thread e-letter
Readers,

For a data set:

text1,23,text2,45
text1,23,text3,78
text1,23,text3,56
text1,23,text2,45

The following command was entered:

datasubset<-data.frame(dataset[,3]=="text3")

The result of

datasubset

is

TRUE
TRUE

The required result is

text1,23,text3,78
text1,23,text3,56

What is the correct command to use please?

Thanks in advance.

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


Re: [R] run a slef-written function

2011-03-15 Thread David Winsemius


On Mar 15, 2011, at 9:21 AM, bra86 wrote:


How could one get started with a self-written function?
I have a function written in .txt format, but can not find the way  
to import

it to the R space.
Would be very appreciated for help.


It would be more typical to use a file extension of .r but I do not  
think the source function cares greatly about that issue. The should  
be material coving this topic in "Introduction to R".


?source

--
David Winsemius, MD
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.


Re: [R] run a slef-written function

2011-03-15 Thread Sarah Goslee
source("myfunction.R") is the usual approach. You could also
just copy your code and paste it into the R console.

Sarah

On Tue, Mar 15, 2011 at 9:21 AM, bra86  wrote:
> How could one get started with a self-written function?
> I have a function written in .txt format, but can not find the way to import
> it to the R space.
> Would be very appreciated for help.


-- 
Sarah Goslee
http://www.functionaldiversity.org

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


Re: [R] Table multiple answers variables

2011-03-15 Thread Orvalho Augusto
This is!

Thank you everyone.

Caveman


On Tue, Mar 15, 2011 at 4:24 PM, Dimitris Rizopoulos <
d.rizopou...@erasmusmc.nl> wrote:

> try the following:
>
> DF <- as.data.frame(matrix(sample(2, 120, TRUE), 10, 12))
>
> Results <- data.frame(
>var = names(DF),
>count = colSums(DF == 1),
>percentage = colMeans(DF == 1)
> )
>
>
> I hope it helps.
>
> Best,
> Dimitris
>
>
>
> On 3/15/2011 3:13 PM, Orvalho Augusto wrote:
>
>> I have a dataset like this:
>>
>>q25_1 q25_2 q25_3 q25_4 q25_5 q25_6 q25_7 q25_8 q25_9 q25_10 q25_11
>> q25_12
>> 1  2 2 1 1 2 1 2 1 1  2  1
>>  3
>> 2  2 2 2 1 2 1 2 1 1  2  1
>>  2
>> 3  2 1 1 1 2 1 2 1 2  2  1
>>  2
>> 4  2 2 1 1 2 2 2 1 1  1  2
>>  2
>> 5  2 2 1 1 2 3 2 1 2  2  2
>>  2
>> 6  2 2 1 1 2 2 2 1 1  1  2
>>  2
>> 7  2 2 1 1 2 3 2 1 2  2  3
>>  2
>> 8  2 2 1 1 1 1 2 1 1  1  2
>>  2
>> 9  2 2 1 1 2 2 2 1 2  2  2
>>  2
>> 10 2 2 1 1 2 2 2 1 2  1  2
>>  2
>>
>> where those q25_ variables are answers (coded 1 for Yes 2 for No). Now I
>> need a way to table counting the ones foreach variables like
>>
>> varcountpercentage
>> q25_1 20  80
>> q25_2 34  85
>> ...
>>
>> Is it possible ir R?
>>
>> For who used stata might use mrtab.
>>
>> Thank you
>> Orvalho
>>
>>[[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.
>>
>>
> --
> Dimitris Rizopoulos
> Assistant Professor
> Department of Biostatistics
> Erasmus University Medical Center
>
> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
> Tel: <%2B31%2F%280%2910%2F7043478>+31/(0)10/7043478
> Fax: <%2B31%2F%280%2910%2F7043014>+31/(0)10/7043014
> Web: http://www.erasmusmc.nl/biostatistiek/
>

[[alternative HTML version deleted]]

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


Re: [R] Keyboard Input

2011-03-15 Thread Jonathan P Daily
Solved. Thanks.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it."
 - Jubal Early, Firefly

Gabor Grothendieck  wrote on 03/15/2011 10:38:34 
AM:

> [image removed] 
> 
> Re: [R] Keyboard Input
> 
> Gabor Grothendieck 
> 
> to:
> 
> Jonathan P Daily
> 
> 03/15/2011 10:38 AM
> 
> Cc:
> 
> Bert Gunter, r-help
> 
> On Tue, Mar 15, 2011 at 10:29 AM, Jonathan P Daily  
wrote:
> > I apologize for being unclear in my original post. What I am trying to
> > achieve is to capture the stdin() connection and read in a single
> > keystroke - including arrow keys and the like - without having to have 
to
> > use the return key each time. My goal is to create a small UI for 
rapidly
> > looking through the results of a large simulation. As I think about it
> > more, though, it is probably going to be easier to dump the data into
> > files and look through it outside of R.
> >
> 
> See:
> http://r.789695.n4.nabble.com/detecting-a-key-press-td2324938.html
> 
> -- 
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com

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


Re: [R] indeterminate for loop

2011-03-15 Thread Jonathan P Daily
?"while"
You don't want a for loop. You need a while loop.
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it."
 - Jubal Early, Firefly

r-help-boun...@r-project.org wrote on 03/15/2011 10:14:21 AM:

> [image removed] 
> 
> [R] indeterminate for loop
> 
> lm609 
> 
> to:
> 
> r-help
> 
> 03/15/2011 10:16 AM
> 
> Sent by:
> 
> r-help-boun...@r-project.org
> 
> Hello,
> 
> I have written a 'for' loop which on the first run makes nearest 
neighbour 
> calculations for my dataset 'A' in relation to dataset 'B', then based 
on 
> these results, some of the rows from A are moved into dataset B, and the 

> calculation is repeated on the remaining rows in A. Therefore a smaller 
and 
> smaller amount of data is analysed as the loop proceeds, since A is 
losing 
> rows each time. The results of the calculation change as less data is 
used, 
> but not in a predictable way, therefore the end point of the loop is 
> indeterminate.
> 
> The script is long and the datasets big, but a simplified example where 
'A' 
> and 'B' are datasets, and the function 'ndist2' calculates 'x' is...
> 
> for (i in 1:100)
> {
> C <- data.frame(ndist2(B,A))
> C1 <- subset(C, x = min(C$x))
> B <- rbind(B, C1)
> A <- subset(C, x > min(C$x))
> }
> 
> So eventually A runs out.
> 
> Currently, I let the loop run until a warning comes up which effectively 

> says no more data, and at this point it is finished.
> 
> What I would now like to do is place this loop inside another loop in 
order 
> to run through multiple datasets, but I can't do this when the script 
> produces a warning message at the end of each dataset.
> 
> Is there any way I can overcome this problem?
> 
> Thanks for your help,
> Louise
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Keyboard Input

2011-03-15 Thread Gabor Grothendieck
On Tue, Mar 15, 2011 at 10:29 AM, Jonathan P Daily  wrote:
> I apologize for being unclear in my original post. What I am trying to
> achieve is to capture the stdin() connection and read in a single
> keystroke - including arrow keys and the like - without having to have to
> use the return key each time. My goal is to create a small UI for rapidly
> looking through the results of a large simulation. As I think about it
> more, though, it is probably going to be easier to dump the data into
> files and look through it outside of R.
>

See:
http://r.789695.n4.nabble.com/detecting-a-key-press-td2324938.html

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Serial Date

2011-03-15 Thread Gabor Grothendieck
On Tue, Mar 15, 2011 at 10:24 AM, Gabor Grothendieck
 wrote:
> On Sun, Mar 13, 2011 at 10:00 PM, Raoni Rosa Rodrigues
>  wrote:
>> Hello R Help,
>>
>> I'm working in a project with a software that register date and time data in 
>> serial time format. This format is used by excel, for exemple. In this 
>> format, 40597.3911423958 is 2011/2/23 09:23:15. First part is number os days 
>> since 1900/1/1, and second part is a fraction of a day.
>>
>
> Try this:
>
>> library(chron)
>> chron(40597.3911423958)
> [1] (02/24/81 09:23:15)
>
> See R News 4/1 and the references there.

Also note that you can adjust it by one day like this:

> chron(40597.3911423958) - 1
[1] (02/23/81 09:23:15)



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Keyboard Input

2011-03-15 Thread Jonathan P Daily
I apologize for being unclear in my original post. What I am trying to 
achieve is to capture the stdin() connection and read in a single 
keystroke - including arrow keys and the like - without having to have to 
use the return key each time. My goal is to create a small UI for rapidly 
looking through the results of a large simulation. As I think about it 
more, though, it is probably going to be easier to dump the data into 
files and look through it outside of R.

Thanks anyways,

Jon
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it."
 - Jubal Early, Firefly

Bert Gunter  wrote on 03/15/2011 10:08:51 AM:

> [image removed] 
> 
> Re: [R] (no subject)
> 
> Bert Gunter 
> 
> to:
> 
> Jonathan P Daily
> 
> 03/15/2011 10:08 AM
> 
> Cc:
> 
> r-help
> 
> ?strsplit
> 
> x <- "ThisIsaString"
> y<- strsplit(x,"")
> 
> This gives a list, which you can convert to a vector by unlist(y)
> 
> Incidentally, you could have found out about strsplit via R's
> help.search("character string") (or similar) or even googling "R
> string function" . Please use R's native Help capabilities before
> posting to the list.
> 
> (I will grant that the unlist()  trick may not be that easy to find).
> 
> Also, it's often worthwhile searching the Help archives first. Peter
> Dalgaard answered this same question here a day or two ago.
> 
> Cheers,
> Bert
> 
> 
> 
> On Tue, Mar 15, 2011 at 6:35 AM, Jonathan P Daily  
wrote:
> > I was wondering if there is a way to get read in a single keystroke at 
a
> > time in R as a string, akin to ncurses-style interfaces. I looked into
> > readLines, readChar, etc. using stdin, but these all require the use 
of an
> > end of line. Has anyone ever had need to do this or have any ideas on 
how
> > to do this?
> >
> > Thanks,
> > Jon
> >
> > PS I apologize if this double-sends, but I am having mail client 
issues.
> > --
> > Jonathan P. Daily
> > Technician - USGS Leetown Science Center
> > 11649 Leetown Road
> > Kearneysville WV, 25430
> > (304) 724-4480
> > "Is the room still a room when its empty? Does the room,
> >  the thing itself have purpose? Or do we, what's the word... imbue 
it."
> > - Jubal Early, Firefly
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 
> 
> 
> -- 
> Bert Gunter
> Genentech Nonclinical Biostatistics

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


Re: [R] Serial Date

2011-03-15 Thread Gabor Grothendieck
On Sun, Mar 13, 2011 at 10:00 PM, Raoni Rosa Rodrigues
 wrote:
> Hello R Help,
>
> I'm working in a project with a software that register date and time data in 
> serial time format. This format is used by excel, for exemple. In this 
> format, 40597.3911423958 is 2011/2/23 09:23:15. First part is number os days 
> since 1900/1/1, and second part is a fraction of a day.
>

Try this:

> library(chron)
> chron(40597.3911423958)
[1] (02/24/81 09:23:15)

See R News 4/1 and the references there.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Table multiple answers variables

2011-03-15 Thread Dimitris Rizopoulos

try the following:

DF <- as.data.frame(matrix(sample(2, 120, TRUE), 10, 12))

Results <- data.frame(
var = names(DF),
count = colSums(DF == 1),
percentage = colMeans(DF == 1)
)


I hope it helps.

Best,
Dimitris


On 3/15/2011 3:13 PM, Orvalho Augusto wrote:

I have a dataset like this:

q25_1 q25_2 q25_3 q25_4 q25_5 q25_6 q25_7 q25_8 q25_9 q25_10 q25_11 q25_12
1  2 2 1 1 2 1 2 1 1  2  1  3
2  2 2 2 1 2 1 2 1 1  2  1  2
3  2 1 1 1 2 1 2 1 2  2  1  2
4  2 2 1 1 2 2 2 1 1  1  2  2
5  2 2 1 1 2 3 2 1 2  2  2  2
6  2 2 1 1 2 2 2 1 1  1  2  2
7  2 2 1 1 2 3 2 1 2  2  3  2
8  2 2 1 1 1 1 2 1 1  1  2  2
9  2 2 1 1 2 2 2 1 2  2  2  2
10 2 2 1 1 2 2 2 1 2  1  2  2

where those q25_ variables are answers (coded 1 for Yes 2 for No). Now I
need a way to table counting the ones foreach variables like

varcountpercentage
q25_1 20  80
q25_2 34  85
...

Is it possible ir R?

For who used stata might use mrtab.

Thank you
Orvalho

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



--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/

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


Re: [R] Table multiple answers variables

2011-03-15 Thread Henrique Dallazuanna
Try this:

data.frame(count = colSums(x == 1), percentage = colSums(x == 1) / nrow(x))


On Tue, Mar 15, 2011 at 11:13 AM, Orvalho Augusto wrote:

> I have a dataset like this:
>
>   q25_1 q25_2 q25_3 q25_4 q25_5 q25_6 q25_7 q25_8 q25_9 q25_10 q25_11
> q25_12
> 1  2 2 1 1 2 1 2 1 1  2  1
>  3
> 2  2 2 2 1 2 1 2 1 1  2  1
>  2
> 3  2 1 1 1 2 1 2 1 2  2  1
>  2
> 4  2 2 1 1 2 2 2 1 1  1  2
>  2
> 5  2 2 1 1 2 3 2 1 2  2  2
>  2
> 6  2 2 1 1 2 2 2 1 1  1  2
>  2
> 7  2 2 1 1 2 3 2 1 2  2  3
>  2
> 8  2 2 1 1 1 1 2 1 1  1  2
>  2
> 9  2 2 1 1 2 2 2 1 2  2  2
>  2
> 10 2 2 1 1 2 2 2 1 2  1  2
>  2
>
> where those q25_ variables are answers (coded 1 for Yes 2 for No). Now I
> need a way to table counting the ones foreach variables like
>
> varcountpercentage
> q25_1 20  80
> q25_2 34  85
> ...
>
> Is it possible ir R?
>
> For who used stata might use mrtab.
>
> Thank you
> Orvalho
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

[[alternative HTML version deleted]]

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


[R] Table multiple answers variables

2011-03-15 Thread Orvalho Augusto
I have a dataset like this:

   q25_1 q25_2 q25_3 q25_4 q25_5 q25_6 q25_7 q25_8 q25_9 q25_10 q25_11 q25_12
1  2 2 1 1 2 1 2 1 1  2  1  3
2  2 2 2 1 2 1 2 1 1  2  1  2
3  2 1 1 1 2 1 2 1 2  2  1  2
4  2 2 1 1 2 2 2 1 1  1  2  2
5  2 2 1 1 2 3 2 1 2  2  2  2
6  2 2 1 1 2 2 2 1 1  1  2  2
7  2 2 1 1 2 3 2 1 2  2  3  2
8  2 2 1 1 1 1 2 1 1  1  2  2
9  2 2 1 1 2 2 2 1 2  2  2  2
10 2 2 1 1 2 2 2 1 2  1  2  2

where those q25_ variables are answers (coded 1 for Yes 2 for No). Now I
need a way to table counting the ones foreach variables like

varcountpercentage
q25_1 20  80
q25_2 34  85
...

Is it possible ir R?

For who used stata might use mrtab.

Thank you
Orvalho

[[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] indeterminate for loop

2011-03-15 Thread lm609

Hello,

I have written a 'for' loop which on the first run makes nearest neighbour 
calculations for my dataset 'A' in relation to dataset 'B', then based on 
these results, some of the rows from A are moved into dataset B, and the 
calculation is repeated on the remaining rows in A. Therefore a smaller and 
smaller amount of data is analysed as the loop proceeds, since A is losing 
rows each time. The results of the calculation change as less data is used, 
but not in a predictable way, therefore the end point of the loop is 
indeterminate.


The script is long and the datasets big, but a simplified example where 'A' 
and 'B' are datasets, and the function 'ndist2' calculates 'x' is...


for (i in 1:100)
{
C <- data.frame(ndist2(B,A))
C1 <- subset(C, x = min(C$x))
B <- rbind(B, C1)
A <- subset(C, x > min(C$x))
}

So eventually A runs out.

Currently, I let the loop run until a warning comes up which effectively 
says no more data, and at this point it is finished.


What I would now like to do is place this loop inside another loop in order 
to run through multiple datasets, but I can't do this when the script 
produces a warning message at the end of each dataset.


Is there any way I can overcome this problem?

Thanks for your help,
Louise

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


Re: [R] Finding coordinates for maximum of a function

2011-03-15 Thread Bert Gunter
Right.

?which.max

is what's needed.

-- Bert

On Tue, Mar 15, 2011 at 6:00 AM, nblarson  wrote:
> That actually won't work.  max(y) will give a value, not a coordinate, so
> x[max(y)] is definitely not what you want.
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Finding-coordinates-for-maximum-of-a-function-tp3355369p3356483.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.
>



-- 
Bert Gunter
Genentech Nonclinical Biostatistics

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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)

2011-03-15 Thread Bert Gunter
?strsplit

x <- "ThisIsaString"
y<- strsplit(x,"")

This gives a list, which you can convert to a vector by unlist(y)

Incidentally, you could have found out about strsplit via R's
help.search("character string") (or similar) or even googling "R
string function" . Please use R's native Help capabilities before
posting to the list.

(I will grant that the unlist()  trick may not be that easy to find).

Also, it's often worthwhile searching the Help archives first. Peter
Dalgaard answered this same question here a day or two ago.

Cheers,
Bert



On Tue, Mar 15, 2011 at 6:35 AM, Jonathan P Daily  wrote:
> I was wondering if there is a way to get read in a single keystroke at a
> time in R as a string, akin to ncurses-style interfaces. I looked into
> readLines, readChar, etc. using stdin, but these all require the use of an
> end of line. Has anyone ever had need to do this or have any ideas on how
> to do this?
>
> Thanks,
> Jon
>
> PS I apologize if this double-sends, but I am having mail client issues.
> --
> Jonathan P. Daily
> Technician - USGS Leetown Science Center
> 11649 Leetown Road
> Kearneysville WV, 25430
> (304) 724-4480
> "Is the room still a room when its empty? Does the room,
>  the thing itself have purpose? Or do we, what's the word... imbue it."
>     - Jubal Early, Firefly
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Bert Gunter
Genentech Nonclinical Biostatistics

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


  1   2   >