Re: [R] find value between two other numbers?

2010-08-12 Thread baptiste auguie
Hi,

I see no need to construct the vector, try this instead,

belong = function(x=4, y=c(1,10))  x <= y[2] && x >= y[1]

see also ?findInterval

HTH,

baptiste

On 13 August 2010 01:10, fishkbob  wrote:
>
> So basically I want to do this -
>
> 4 %in% 1:10
> should return true
>
> Would there be another way of doing this without having to do the 1:10 part?
>
> I am using a very large data set and trying to do
>
> 459124 %in% 103000:983000
>
> multiple times for many values, and it is taking quite a long time
>
> Also, I would like to vary the x:y part, so I can't even make an object that
> is c(x:y) and do a which(#=c(x:y)) because I would need to change x and y
> each time.
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/find-value-between-two-other-numbers-tp2323513p2323513.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] find value between two other numbers?

2010-08-12 Thread Jorge Ivan Velez
Hi,

Here is one way:

> is.there <- function(mynumber, a, b)  mynumber %in% a:b
> is.there(4, 1, 10)
[1] TRUE
> is.there(459124, 103000, 983000)
[1] TRUE
> is.there(4, 103000, 983000)
[1] FALSE

HTH,
Jorge


On Thu, Aug 12, 2010 at 7:10 PM, fishkbob <> wrote:

>
> So basically I want to do this -
>
> 4 %in% 1:10
> should return true
>
> Would there be another way of doing this without having to do the 1:10
> part?
>
> I am using a very large data set and trying to do
>
> 459124 %in% 103000:983000
>
> multiple times for many values, and it is taking quite a long time
>
> Also, I would like to vary the x:y part, so I can't even make an object
> that
> is c(x:y) and do a which(#=c(x:y)) because I would need to change x and y
> each time.
> --
> View this message in context:
> http://r.789695.n4.nabble.com/find-value-between-two-other-numbers-tp2323513p2323513.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.


[R] mlogit error

2010-08-12 Thread Maha Bakoben
Hi,

I'm trying to fit a multinomial logistic regression to my data which
consists of 5 discrete variables (scales 1:10) and 1000 observations.

I get the following error:

Error in `row.names<-.data.frame`(`*tmp*`, value = c("NA.NA", "NA.NA",  :
  duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique value when setting 'row.names': ‘NA.NA’

My code:

> flevel1$Q120<-as.factor(flevel1$Q120)
> MData<-mlogit.data(flevel1, varying=NULL,choice="Q120", shape="wide")
> LogitModel<-mlogit(flevel1$Q120~1|flevel1$Q92, data=MData)

MData[1:10,]
 Q56 Q92 Q102 Q119  Q120
1.1   10   7   10   10 FALSE
1.10  10   7   10   10  TRUE
1.2   10   7   10   10 FALSE
1.3   10   7   10   10 FALSE
1.4   10   7   10   10 FALSE
1.5   10   7   10   10 FALSE
1.6   10   7   10   10 FALSE
1.7   10   7   10   10 FALSE
1.8   10   7   10   10 FALSE
1.9   10   7   10   10 FALSE



Your help will be greatly appreciated.

Maha

[[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] find value between two other numbers?

2010-08-12 Thread fishkbob

So basically I want to do this -

4 %in% 1:10
should return true

Would there be another way of doing this without having to do the 1:10 part?

I am using a very large data set and trying to do

459124 %in% 103000:983000

multiple times for many values, and it is taking quite a long time

Also, I would like to vary the x:y part, so I can't even make an object that
is c(x:y) and do a which(#=c(x:y)) because I would need to change x and y
each time.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/find-value-between-two-other-numbers-tp2323513p2323513.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] build.pl in building library with Rtools211

2010-08-12 Thread Hintzen, Niels
R CMD build (lower case) indeed works. I was confused with older versions of 
Rtools where it didn't matter if you used lower or upper case (as well as that 
I thought under DOS upper and lower cases don't make a difference). I was wrong 
however.
Thanks for the help


Van: Uwe Ligges [lig...@statistik.tu-dortmund.de]
Verzonden: donderdag 12 augustus 2010 22:10
Aan: Hintzen, Niels
CC: r-help@r-project.org
Onderwerp: Re: [R]  build.pl in building library with Rtools211

What did you try?
R CMD build (build all lower case) does work for me

Uwe Ligges




On 09.08.2010 22:30, Hintzen, Niels wrote:
> Dear all,
>
> As I couldn't find any thread on the internet I hope the help-list might help 
> me out.
>
> I've tried to update Rtools from R210 used in combination with R2.9.1 to R211 
> in combination with R2.11.1. However, I do not succeed.
>
> I have R2.11.1 running, as well as Inno Setup 5, HTML help and MikTex. A 
> version of Perl is installed too. Environment variable paths are set to link 
> to these directories too.
>
> However, when I try to build a library using: R CMD BUILD mypackage it 
> immediately crashes as apparently it cannot find the file 'build' in 
> R-2.11.1/bin. Indeed, this file is not present there (only build.pl) while 
> this file is present in the R-2.9.1/bin directory.
>
> What obvious thing am I doing wrong.
>
> Your help is much appreciated.
>
> With regards,
>
> Niels Hintzen
>
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] help

2010-08-12 Thread milly

I need a code to export my output to excel 2007.I am dealing with
observations of 15,000.Thank you
-- 
View this message in context: 
http://r.789695.n4.nabble.com/help-tp2323542p2323542.html
Sent from the Export many data to Excel 2007 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] subsetting data points within confidence limit

2010-08-12 Thread Keun-Hyung Choi
Dear R-list

 

Suppose I have a data set stored in hmet, for which I did get confidence
limit on a linear regression as shown below.

My question is how I can subset only data points which are within the
confidence limit.

 

Thank you. 

Keun-Hyung 

 

---

Al=rnorm(100, 3)

Cd=rnorm(100, 0.2)

hmet=data.frame(Al=Al, Cd=Cd)

plot(Al, Cd, xlab="Al", ylab= "Cd", , pch=16)

cd.lm=lm(Cd~ Al, na.action=na.omit, data= hmet)

abline(cd.lm$coeff, lty=1)

xy= data.frame (Al =pretty(hmet$Al, 20))

yhat=predict(cd.lm, newdata=xy, interval="confidence")

ci=data.frame(lower=yhat[,"lwr"], upper=yhat[,"upr"])

lines(xy$Al, ci$lower, lty= 2, lwd=2, col="grey")

lines(xy$Al, ci$upper, lty=2, lwd=2, col="grey")


[[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] Learning ANOVA

2010-08-12 Thread Stephen Liu
Hi David,

Thanks for your advice.

The remaining commands will be;

### Create a side-by-side boxplot of the test01
boxplot(test01$DO ~ test01$Stream)

### Create an ANOVA table
dotest01.aov <-(test01$DO ~ test01$Stream)
summary(dotest01.aov)

### Conduct a Tukey's multiple comparison procedure
TukeyHSD(dotest01.aov)

Any advice?  TIA


B.R.
Stephen L






- Original Message 
From: David Winsemius 
To: Stephen Liu 
Cc: r-help@r-project.org
Sent: Fri, August 13, 2010 12:19:35 PM
Subject: Re: [R] Learning ANOVA


On Aug 12, 2010, at 11:34 PM, Stephen Liu wrote:

> Hi folks,
>
>
> File to be used is on;
> data(InsectSprays)
>
>
> I can't figure out where to insert it on following command;
> test01 <- read.csv(fil.choose(), header=TRUE)

Don't think that would work, even if you did spell file.choose()  
correctly.

?data

"Description
Loads specified data sets, or list the available data sets."


At the console you can just type:

  data(InsectSprays)  # and you have access to that object

If you want to make another copy I suppose you could then type

test01 <- InsectSprays

... but I don't see what you would gain by that.

--
David.



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


Re: [R] Learning ANOVA

2010-08-12 Thread David Winsemius


On Aug 12, 2010, at 11:34 PM, Stephen Liu wrote:


Hi folks,


File to be used is on;
data(InsectSprays)


I can't figure out where to insert it on following command;
test01 <- read.csv(fil.choose(), header=TRUE)


Don't think that would work, even if you did spell file.choose()  
correctly.


?data

"Description
Loads specified data sets, or list the available data sets."


At the console you can just type:

 data(InsectSprays)  # and you have access to that object

If you want to make another copy I suppose you could then type

test01 <- InsectSprays

... but I don't see what you would gain by that.

--
David.

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

2010-08-12 Thread Stephen Liu
Hi folks,


File to be used is on;
data(InsectSprays)


I can't figure out where to insert it on following command;
test01 <- read.csv(fil.choose(), header=TRUE)

Please help.  TIA

B.R.




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

2010-08-12 Thread Yi
Thank you both for response!

Enh, I never think about function though. Good.

My way is using 'aggregate' and 'merge' but it is a little bit trivial.



On Wed, Aug 11, 2010 at 9:13 PM, Dennis Murphy  wrote:

> Hi:
>
> Try this from package plyr:
>
> library(plyr)
> # function to compute sum of squares
> f <- function(df)  with(df, sum((tapply(value, type, sum)/sum(value))^2))
> # apply it to each type of food:
> ddply(data, .(food), conc = f(data))
>food   type value market_con
> 1 drink  water 5  0.5987654
> 2 drink   soda 7  0.5987654
> 3 drink   soda 6  0.5987654
> 4 fruit  apple 2  0.722
> 5 fruit  apple 3  0.722
> 6 fruit orange 1  0.722
>
> HTH,
> Dennis
>
>   On Wed, Aug 11, 2010 at 3:40 PM, Yi  wrote:
>
>>  Thank you for reminding me.
>>
>> ##
>> food=c('fruit','fruit','fruit','drink','drink','drink')
>> type=c('apple','apple','orange','water','soda','soda')
>> value=c(2,3,1,5,7,6)
>> data=data.frame(food,type,value)
>> share=c((2+3)/(2+3+1),5/6,1/6,5/(5+7+6),13/18,13/18)
>>
>> market_con=c(rep(0.833^2+0.167^2,3),rep(0.278^2+0.722^2,3))
>> data$market_con=market_con
>> ##
>>
>> Share= sum of value for specific type for some food / sum of value for all
>> types for some food
>>
>> concentration= sum of square of share
>>
>> For food 1, fruit, for apple ,there are two rows, value =2 and 3; for
>> oranget, value =1.
>>
>> share_apple=(2+3)/(2+3+1)=5/6 ## It is the same for the two rows
>> share_organge=1/6
>>
>> concentration_fruit= share_apple^2+sjare_orange^2=(5/6)^2+(1/6)^2
>>
>> Hope this makes it easier to understand.
>>
>> Thanks
>>
>> Yi
>>
>> On Wed, Aug 11, 2010 at 3:33 PM, Wu Gong  wrote:
>>
>> >
>> > Hi Yi,
>> >
>> > It would be helpful for others to provide a solution if you give your
>> > formulas that calculating the value of share and concentration.
>> >
>> > ?apply will helps.
>> >
>> > Regards,
>> >
>> > Wu
>> >
>> >
>> >
>> > -
>> > A R learner.
>> > --
>> > View this message in context:
>> >
>> http://r.789695.n4.nabble.com/How-to-calculate-the-concentration-tp2321888p2321966.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.
>>
>
>

[[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] Need help to understand integrate function

2010-08-12 Thread Ravi Varadhan
The magic is not in setting options(digits=10).  I did that just to show you 
the accuracy of the answer.  The magic is in setting a more stringent error 
tolerance,  rel.tol=1.e-10.

The divergent error is due to the fact that the default tolerance of (roughly) 
1.e-04 is too large.

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: R_help Help 
Date: Thursday, August 12, 2010 9:23 pm
Subject: Re: [R] Need help to understand integrate function
To: Ravi Varadhan 
Cc: r-help@r-project.org


> Hi Ravi - Thank you. I'm wondering how the magic happens here with
>  options(digits=10)? And the most important point, I do not quite
>  understand why divergent error could occur. In this case, the function
>  is analytically integrable. Any insight would be greatly appreciated
>  so that I learn something out of this. Thank you.
>  
>  Rob
>  
>  On Wed, Aug 11, 2010 at 11:46 PM, Ravi Varadhan  
> wrote:
>  > Try this:
>  >
>  > options(digits=10)
>  >
>  >> integrate(f=powerLaw2, lower=0, upper=Inf, l1=1.8980185, 
> l2=-0.0804259, c0=1, t0=259.78, rel.tol=1.e-10)
>  > 0.01089019946 with absolute error < 3.7e-11
>  >
>  >
>  > 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: R_help Help 
>  > Date: Wednesday, August 11, 2010 9:44 pm
>  > Subject: [R] Need help to understand integrate function
>  > To: r-help@r-project.org
>  >
>  >
>  >> Hi,
>  >>
>  >>  I'm running into a wall when trying to use the integrate 
> function. I
>  >>  have the following setting:
>  >>
>  >>  powerLaw2 <- function(x,l1,l2,c0,t0) {
>  >>
>  >>     idx <- which(x <= 0);
>  >>     if (length(idx) > 0) {
>  >>        x[idx] <- 0;
>  >>     }
>  >>
>  >>     xl <- (-l1+l2)*log(x/t0);
>  >>     L <- log(c0)-l1*log(x)-log(1+exp(xl));
>  >>     L <- exp(L);
>  >>     return(L);
>  >>  }
>  >>
>  >>  plCDF2 <- function(x,l1,l2,c0,t0) {
>  >>
>  >>     print(c(l1,l2,c0,t0));
>  >>     cdf <- 
> integrate(f=powerLaw2,lower=x,upper=Inf,l1=l1,l2=l2,c0=c0,t0=t0,stop.on.error=T);
>  >>     return(cdf$value);
>  >>
>  >>  }
>  >>
>  >>  I know that as long as my l1 > 1 and l2 < 1 the integration above
>  >>  should converge. However, this doesn't seem to be the case when I 
> call
>  >>  integrate function with the following parameter:
>  >>
>  >>
>  >>  Browse[1]> 
> integrate(f=powerLaw2,lower=1e-09,upper=Inf,l1=1.8980185,l2=-0.0804259,c0=1,t0=259.78,stop.on.error=T)
>  >>  failed with message 'the integral is probably divergent'
>  >>
>  >>  Would you please shed some light? And how could I prevent this
>  >>  situation? Thank you.
>  >>
>  >>  Rgds,
>  >>
>  >>  Rob
>  >>
>  >>  __
>  >>  r-h...@r-project.org mailing list
>  >>
>  >>  PLEASE do read the posting guide
>  >>  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] 64 bit RSQLite

2010-08-12 Thread Stephen Liu
Hi folks,

Ubuntu 10.04 64 bit

Where can I find 64 bit RSQLite?

It seems not there;
RSQLite: SQLite interface for R
http://cran.r-project.org/web/packages/RSQLite/index.html

TIA


B.R.
Stephen L




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

2010-08-12 Thread David Smith
On Thu, Aug 12, 2010 at 4:12 PM, Lars Bishop  wrote:
> The company where I work is considering getting a license for Revolution
> Enterprise - Windows 64-bit. I'll appreciate for those familiar with the
> product if can share your experiences with it? In particular, how does it
> compare to the "free" version of R 64-bit?

(I work for Revolution Analytics.)

Here are the main differences:

* The GUI allows you to set breakpoints interactively and do step
debugging. There's a short video of it in action here:
http://bit.ly/bmAlqA

* We optimize the compilation and link it against the Intel MKL
libraries, which makes some linear algebra routines use all cores and
run faster. More details: http://bit.ly/btLUmb

* It includes the foreach, doSMP and doNWS packages, for multicore and
distributed parallel computing.

* It includes the RevoScaleR package (in the upcoming release, out at
the end of this month), for statistical analysis of very large data
sets. Details in this white paper:
http://www.revolutionanalytics.com/bigdata/ (reg. req'd)

* It's supported.

Otherwise, the core open-source R engine is just that: R (namely, R
2.11.1 in the upcoming release), and so works exactly as you'd expect.

Hope that helps,
# David Smith

--
David M Smith 
VP of Marketing, Revolution Analytics  http://blog.revolutionanalytics.com
Tel: +1 (650) 330-0553 x205 (Palo Alto, CA, USA)

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


Re: [R] factor failure

2010-08-12 Thread David Winsemius


On Aug 12, 2010, at 9:00 PM, elaine kuo wrote:


Dear list,


factor function was tried but failed.
Pls kindly help and thank you.

E.


code

rm(list=ls())
library(faraway)
data (pima)

pima$test < - factor (pima$test)


There is a space between your "<" and your "-". R is interppreting  
that as "make a numerical comparison between pima$test on the lhs and  
minus factor(pima$test) on the rhs and quite sensibly saying you have  
given it a nonsensical task.


> pima$test <- factor (pima$test)
> str(pima$test)
 Factor w/ 2 levels "0","1": 2 1 2 1 2 1 2 1 2 2 ...
'


 [1] NA NA NA NA NA NA



--
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] Need help to understand integrate function

2010-08-12 Thread R_help Help
Hi Ravi - Thank you. I'm wondering how the magic happens here with
options(digits=10)? And the most important point, I do not quite
understand why divergent error could occur. In this case, the function
is analytically integrable. Any insight would be greatly appreciated
so that I learn something out of this. Thank you.

Rob

On Wed, Aug 11, 2010 at 11:46 PM, Ravi Varadhan  wrote:
> Try this:
>
> options(digits=10)
>
>> integrate(f=powerLaw2, lower=0, upper=Inf, l1=1.8980185, l2=-0.0804259, 
>> c0=1, t0=259.78, rel.tol=1.e-10)
> 0.01089019946 with absolute error < 3.7e-11
>
>
> 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: R_help Help 
> Date: Wednesday, August 11, 2010 9:44 pm
> Subject: [R] Need help to understand integrate function
> To: r-help@r-project.org
>
>
>> Hi,
>>
>>  I'm running into a wall when trying to use the integrate function. I
>>  have the following setting:
>>
>>  powerLaw2 <- function(x,l1,l2,c0,t0) {
>>
>>     idx <- which(x <= 0);
>>     if (length(idx) > 0) {
>>        x[idx] <- 0;
>>     }
>>
>>     xl <- (-l1+l2)*log(x/t0);
>>     L <- log(c0)-l1*log(x)-log(1+exp(xl));
>>     L <- exp(L);
>>     return(L);
>>  }
>>
>>  plCDF2 <- function(x,l1,l2,c0,t0) {
>>
>>     print(c(l1,l2,c0,t0));
>>     cdf <- 
>> integrate(f=powerLaw2,lower=x,upper=Inf,l1=l1,l2=l2,c0=c0,t0=t0,stop.on.error=T);
>>     return(cdf$value);
>>
>>  }
>>
>>  I know that as long as my l1 > 1 and l2 < 1 the integration above
>>  should converge. However, this doesn't seem to be the case when I call
>>  integrate function with the following parameter:
>>
>>
>>  Browse[1]> 
>> integrate(f=powerLaw2,lower=1e-09,upper=Inf,l1=1.8980185,l2=-0.0804259,c0=1,t0=259.78,stop.on.error=T)
>>  failed with message 'the integral is probably divergent'
>>
>>  Would you please shed some light? And how could I prevent this
>>  situation? Thank you.
>>
>>  Rgds,
>>
>>  Rob
>>
>>  __
>>  r-h...@r-project.org mailing list
>>
>>  PLEASE do read the posting guide
>>  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] storing the results of an apply call

2010-08-12 Thread David Winsemius


On Aug 12, 2010, at 7:54 PM, Greg Snow wrote:


-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net]
Sent: Thursday, August 12, 2010 3:13 PM
To: Greg Snow
Cc: Joshua Wiley; r-help@r-project.org
Subject: Re: [R] storing the results of an apply call


On Aug 12, 2010, at 5:07 PM, Greg Snow wrote:



[1] "metacarpal sit-down unfriendliness chapel ME"



My wife gives "ME"  the "middle phalangeal unfriendliness" message
about once a week.


Well if part of the message was meant for you rather than the  
original posters, then it starts to make more sense.  However,  
realizing that I will need to figure out how to filter results to  
the different questions just shows how much further the package has  
to go before reaching alpha status.


I ran esp once more for you to see if it can help with your problem  
and the response is:


[1] "succumb sheepishly contaminated impassively soapy well-worn  
straddle guarantee ozone opener"


The first part may (or may not) be useful, but there may be  
contamination from someone else's question in there as well.


I don't know ... didn't that "soapy well-worn straddle" part sounded  
hopefully suggestive?




I am afraid that I cannot give any more specific help without a  
short self contained example of the source of your problem (what you  
said or did immediately before the unfriendliness message, not an  
example of the message itself).


Yeah, yeah, yeah, always the same old story. What is it with you R  
programs, anyway? Is always going to be" "give a reproducible example"?


General advice without the examples would be to try buying her  
flowers.


Ah, genuine insight into human female sick-ology. Maybe there's hope  
for package esp yet! Keep at it, Greg.


Hope this helps,


--

David Winsemius, MD
West Hartford, CT




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


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] factor failure

2010-08-12 Thread Erik Iverson

On 08/12/2010 08:00 PM, elaine kuo wrote:

Dear list,


factor function was tried but failed.
Pls kindly help and thank you.

E.


code

rm(list=ls())
library(faraway)
data (pima)

pima$test<  - factor (pima$test)
   [1] NA NA NA NA NA NA


The unreported warning message should have given you a
hint.

I'm guessing you want the assignment operator, which is:

<-  (no spaces)

pima$test <- factor(pima$test)

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

2010-08-12 Thread elaine kuo
Dear list,


factor function was tried but failed.
Pls kindly help and thank you.

E.


code

rm(list=ls())
library(faraway)
data (pima)

pima$test < - factor (pima$test)
  [1] NA NA NA NA NA NA

[[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] storing the results of an apply call

2010-08-12 Thread Greg Snow


> -Original Message-
> From: David Winsemius [mailto:dwinsem...@comcast.net]
> Sent: Thursday, August 12, 2010 3:13 PM
> To: Greg Snow
> Cc: Joshua Wiley; r-help@r-project.org
> Subject: Re: [R] storing the results of an apply call
> 
> 
> On Aug 12, 2010, at 5:07 PM, Greg Snow wrote:
> >
> >
> > [1] "metacarpal sit-down unfriendliness chapel ME"
> 
> 
> My wife gives "ME"  the "middle phalangeal unfriendliness" message
> about once a week.

Well if part of the message was meant for you rather than the original posters, 
then it starts to make more sense.  However, realizing that I will need to 
figure out how to filter results to the different questions just shows how much 
further the package has to go before reaching alpha status.

I ran esp once more for you to see if it can help with your problem and the 
response is:

[1] "succumb sheepishly contaminated impassively soapy well-worn straddle 
guarantee ozone opener"

The first part may (or may not) be useful, but there may be contamination from 
someone else's question in there as well.

I am afraid that I cannot give any more specific help without a short self 
contained example of the source of your problem (what you said or did 
immediately before the unfriendliness message, not an example of the message 
itself).

General advice without the examples would be to try buying her flowers.

Hope this helps,

> --
> 
> David Winsemius, MD
> West Hartford, CT



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

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


Re: [R] storing the results of an apply call

2010-08-12 Thread Greg Snow
> -Original Message-
> From: Marc Schwartz [mailto:marc_schwa...@me.com]
> Sent: Thursday, August 12, 2010 3:32 PM
> To: Greg Snow; Joshua Wiley
> Cc: r-help@r-project.org Forum
> Subject: Re: [R] storing the results of an apply call


> 
> P.S. Pardon me while I go visit with the Emacs Psychotherapist (version
> 23 of course...)

I did paste some of the output from my esp function into the emacs 
psychotherapist program, unfortunately it was neither as enlightening or as 
entertaining as when Carroll's Jaberwocky was analyzed.

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

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

2010-08-12 Thread TGS
I downloaded their Academic version and installed it on a Windows virtual 
machine (as there is not a Mac version available).

I played around with it a little bit and wasn't overly impressed. I still like 
my current configuration: textmate with R bundle on Mac OSX.

With textmate data entry is a breeze, executing commands is a breeze, and 
dealing with graphics is a breeze. Also, I can easily use textmate's Sweave 
bundle to produce documents.

In short, from the very little that I have tried using Revolution, my current 
configuration beats using Revolution.

I just need to continue working on obtaining the R skills!

On Aug 12, 2010, at 4:12 PM, Lars Bishop wrote:

Dear users,

The company where I work is considering getting a license for Revolution
Enterprise - Windows 64-bit. I'll appreciate for those familiar with the
product if can share your experiences with it? In particular, how does it
compare to the "free" version of R 64-bit?

Thanks in advance.

Regards,
Lars.

[[alternative HTML version deleted]]

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

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


[R] R 64-bit and Revolution

2010-08-12 Thread Lars Bishop
Dear users,

The company where I work is considering getting a license for Revolution
Enterprise - Windows 64-bit. I'll appreciate for those familiar with the
product if can share your experiences with it? In particular, how does it
compare to the "free" version of R 64-bit?

Thanks in advance.

Regards,
Lars.

[[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] storing the results of an apply call

2010-08-12 Thread Joshua Wiley
On Thu, Aug 12, 2010 at 2:31 PM, Marc Schwartz  wrote:
> On Aug 12, 2010, at 4:07 PM, Greg Snow wrote:
>
>>> -Original Message-
>>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
>>> project.org] On Behalf Of Joshua Wiley
>>> Sent: Wednesday, August 11, 2010 6:31 PM
>>> To: Lorenzo Cattarino
>>> Cc: r-help@r-project.org
>>> Subject: Re: [R] storing the results of an apply call
>>
>>
>>>
>>> What follows is not really an example.  There is no real data, which
>>> while annoying could be overcome, but we also do not have your
>>> function.  Last I heard, present or future Greg (I mix them up) is
>>> working on a ESP package, but I am pretty certain it has not been
>>> released yet.
>>>
>>
>> Well, past me had hoped that someone (not necessarily any of me) would right 
>> the ESP package, then future me would be able to get a copy and also a copy 
>> of the TimeTravel package and use it to send a copy of the ESP package back 
>> in time to past (or present) me to use.  However, that has not happened yet 
>> (at least not to past or present me, there still is possibility for near 
>> future me to get a copy from far future me).  Possible reasons include that 
>> possibly future me is punishing past and present me for something that we 
>> did or did not do (gotta stick to that diet, maybe that will help) or maybe 
>> even something that near future me will do that has not occurred to present 
>> me as yet.  Or possibly future me procrastinates just as bad as present me 
>> and expects far distant future me to do it while far distant future me has 
>> completed the journey into senility far enough to have forgotten that 
>> moderate distant future me did not get around to doing it yet.
>>
>> While I don't know the exact reasons why I have not yet received a copy of 
>> the future working ESP package, it appears that I have created somewhat of 
>> an expectation for the package, so I have made a crude start.  I have a 
>> function to try, be warned it is very pre-alpha (possible aleph from the 
>> Phonecian alphabet which was a predecessor of the Greek, indicating that it 
>> needs improvements at least through the Phonecian before even being 
>> considered alpha level).  I ran the esp function to see if it could shed 
>> some light on this problem and the result was:
>>
>> [1] "headline rightly silver foolishness insincerely culpability tuba 
>> streptomycin hit clean-cut chateau aerospace diffusely"
>>
>> I then ran the function again hoping for some clarification and received the 
>> short but insightful:
>>
>> [1] "metacarpal sit-down unfriendliness chapel ME"
>>
>> Wanting further detail I ran it one more time and was told:
>>
>> [1] "hemophiliac phonics dumdum secondary helpfulness proximity strychnine 
>> nighthawk waive veggie"
>>
>>
>> So you can see the current implementation is still less helpful than if 
>> people with questions follow the posting guidelines in providing minimal 
>> self contained working code (and the other advice in the guide).
>>
>> Sorry this is not more helpful.
>>
>> P.S.  I have also started on the TimeTravel package, but so far it only 
>> allows for travel in one direction and that at a fairly predictable constant 
>> rate.  I have been working on the "Subjective" section of the code, but so 
>> far it is pretty boring and only makes the time seem to pass slower.
>
>
> Two comments:
>
> 1. Isn't there a risk of the Grandfather Paradox here? (astrophysics is 
> coming back to haunt me...)
>
> 2. I don't know if the fortunes package is the right place, but this exchange 
> needs to be captured...
>
>
> Regards,
>
> Marc Schwartz
>
> P.S. Pardon me while I go visit with the Emacs Psychotherapist (version 23 of 
> course...)

I thought I had found a wondrous therapy function awhile back, but at
my appointment yesterday, freud() behaved so strangely I figured I
should see if everything was okay.  You can only imagine how hurt I
was when I realized freud() just echoed my words back to meI just
wish I could have seen it coming ;-)

> # usual session
> freud()
How are you feeling today? I felt worn out today.
It sounds like you felt worn out today.
>
> # yesterday
> freud()
How are you feeling today? I am afraid I will have to wait several
centuries for the ESP package still :(
It sounds like you am afrayoud you wyoull have to wayout several
centuryoues for the ESP package styoull :(
>
> freud
function() {
  yousaid <- readline("How are you feeling today? ")
  out <- gsub("i|I", "you", yousaid)
  out <- paste("It sounds like", out)
  cat(out, fill = TRUE)
}


Josh

P. S. This was the best Friday ever!

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

2010-08-12 Thread David Smith
I write about R every weekday at the Revolutions blog:
 http://blog.revolutionanalytics.com
and every month I post a summary of articles from the previous month
of particular interest to readers of r-help.

In case you missed them, here are some articles related to R from the
month of July:

http://bit.ly/cXFZrI reviewed the updates to Hadley Wickham's ggplot2
and plyr packages.

http://bit.ly/940vKB linked to an article about R co-creator Ross
Ihaka in New Zealand's Sunday Star Times.

http://bit.ly/au2Mtt noted that the presentations from the R/Finance
2010 conference are available for download.

http://bit.ly/cts8L4 reviewed the StatJump website, which uses R
graphics to visualize US Census results.

http://bit.ly/aMtFFs linked to R-based visualizations of the World
Cup, and showed how to download the data from a Google Spreadsheet
into R.

http://bit.ly/cXuIPR previewed talks from Revolution team members at
useR! 2010. (Slides now available at
http://user2010.org/presentations.html.)

http://bit.ly/ds2kdi reviewed an article from The Data Warehousing
Institute (TDWI) where R was called a "Rock Star".

http://bit.ly/aDP8wf called for beta testers of Revolution's
RevoScaleR package for big data statistics.

http://bit.ly/bequuy related how Drew Conway got engaged, and used R
to analyze the impact on his fiancée's Facebook wall.

http://bit.ly/cdZUSj announced www.inside-r.org, a new community site
for R sponsored by Revolution Analytics.

http://bit.ly/dfor4g reviewed the talks on Day 1 of the useR! 2010
conference. I also posted some photos from the conference here:
http://bit.ly/9mpWYW .

http://bit.ly/cyDlDm linked to an extensive list of plaudits for R
compiled by Paul Murrell.

Revolution CEO Norman Nie continues his media tour, talking about R
and Revolution in a radio interview (http://bit.ly/b86nDR) and in
print (http://bit.ly/cQPRnP).

http://bit.ly/aVSEh2 provides an analysis of the growth in attention
about R, from analyst Steve Miller.

http://bit.ly/90lMK9 reviews a new, free book on probability and
statistics with R (included with the IPSUR package).

http://bit.ly/9Ni1ZO links to an analysis of the Wikileaks Afghanistan
data done with R.

There are new R user groups in Slovenia (http://bit.ly/8YnoUj) and
Melbourne (http://bit.ly/cI19w8).

Other non-R-related stories in the past month included: using
statistics to detect fraud in polling data (http://bit.ly/dDfWPt), an
IEEE contest to predict traffic (http://bit.ly/aC9bxZ), a new website
for questions about Statistics (http://bit.ly/97quRx), and (on a
lighter note), double rainbows (http://bit.ly/cJg4OD).

The R Community Calendar has also been updated at:
http://blog.revolutionanalytics.com/calendar.html

If you're looking for more articles about R, you can find summaries
from previous months at http://blog.revolutionanalytics.com/roundups/.
Join the Revolution mailing list at
http://revolutionanalytics.com/newsletter to be alerted to new
articles on a monthly basis.

As always, thanks for the comments and please keep sending suggestions
to me at da...@revolutionanalytics.com . Don't forget you can also
follow the blog using an RSS reader like Google Reader, or by
following me on Twitter (I'm @revodavid).

Cheers,
# David

--
David M Smith 
VP of Marketing, Revolution Analytics  http://blog.revolutionanalytics.com
Tel: +1 (650) 330-0553 x205 (Palo Alto, CA, USA)

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


Re: [R] conditional selection of dataframe rows

2010-08-12 Thread David Winsemius


On Aug 12, 2010, at 6:15 PM, David Winsemius wrote:



On Aug 12, 2010, at 5:20 PM, Toby Gass wrote:


Hi,

I do want to look only at slope.
If there is one negative slope measurement  for a given day and a
given chamber, I would like to remove all other slope measurements
for that day and that chamber, even if they are positive.

On one day, I will have 20 slope measurements for each chamber.  If
one is negative, I would like to delete the other 19 for that chamber
on that day, even if they are positive.  I have measurements for
every day of the year, for 4 years and multiple chambers.

I know I could make some awful nested loop with a vector of day and
chamber numbers for each occurrence of a negative slope and then run
that against the whole data set but I hope not to have to do that.

Here is the rationale, if that helps.  These are unattended outdoor
chambers that measure soil carbon efflux.  When the numbers go
negative during part of the day but otherwise look normal, it usually
means a plant has sprouted in the chamber and is using the carbon
dioxide.  That means the measurements are all lower than they should
be and I need to discard all measurements collected on that day,
whether positive or negative.

It might have been a little clearer if I'd make the toy dataframe a
bit larger.


I think the fault was all mine. Failure to read for meaning. Here's  
an alternate strategy, although I think Schwartz's might be cleaner:


> toy$ch.day.cat <- with(toy, paste(CH, DAY, sep="."))
> negs.idxs <- tapply(toy$SLOPE , toy$ch.day.cat, function (x) any(x  
<0) )

> negs.idxs
 3.4   3.5   4.4   4.5   5.4   5.5
FALSE FALSE FALSE FALSE FALSE  TRUE
> toy[-which(negs.idxs), ]
 CH DAY SLOPE ch.day.cat
1  3   4   0.23.4
2  4   4   0.34.4
3  5   4   0.45.4
4  3   4   0.53.4
5  4   4   0.64.4
7  3   5   0.13.5
8  4   5   0.04.5
9  5   5  -0.15.5



I think I should give up today. I saw that the above code eliminates  
#6 and only after posting saw that #9 was left in:


require(rms)   # for %nin%  .. or use the %w/o% operator defined on  
match help page:


> toy[toy$ch.day.cat %nin% names(negs.idxs[negs.idxs]), ]
  CH DAY SLOPE ch.day.cat
1  3   4   0.23.4
2  4   4   0.34.4
3  5   4   0.45.4
4  3   4   0.53.4
5  4   4   0.64.4
7  3   5   0.13.5
8  4   5   0.04.5

Now I am really sure that the ave(  , , any)  strategy is superior.



--
David


Thanks again for the assistance.

Toby



On 12 Aug 2010 at 16:39, David Winsemius wrote:



On Aug 12, 2010, at 4:06 PM, Toby Gass wrote:


Thank you all for the quick responses.  So far as I've checked,
Marc's solution works perfectly and is quite speedy.  I'm still
trying to figure out what it is doing. :)

Henrique's solution seems to need some columns somewhere.  David's
solution does not find all the other measurements, possibly with
positive values, taken on the same day.


I assumed you only wanted to look at what appeared to be a data
column, SLOPE. If you want to look at all columns for negatives then
try:

toy[ which( apply(toy, 1, function(x) all(x >= 0)) ), ]  # or
toy[ apply(toy, 1, function(x) all(x >= 0)) , ]

This is how they differ w,r,t, their handling of NA's.


toy[3,2] <- NA
toy[ apply(toy, 1, function(x) all(x >= 0)) , ]

  CH DAY SLOPE
1   3   4   0.2
2   4   4   0.3
NA NA  NANA
4   3   4   0.5
5   4   4   0.6
6   5   5   0.2
7   3   5   0.1
8   4   5   0.0

toy[ which(apply(toy, 1, function(x) all(x >= 0)) ), ]

 CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
4  3   4   0.5
5  4   4   0.6
6  5   5   0.2
7  3   5   0.1
8  4   5   0.0




Thank you again for your efforts.

Toby

On 12 Aug 2010 at 14:32, Marc Schwartz wrote:


On Aug 12, 2010, at 2:24 PM, Marc Schwartz wrote:


On Aug 12, 2010, at 2:11 PM, Toby Gass wrote:


Dear helpeRs,

I have a dataframe (14947 x 27) containing measurements  
collected

every 5 seconds at several different sampling locations.  If one
measurement at a given location is less than zero on a given  
day, I

would like to delete all measurements from that location on that
day.

Here is a toy example:

toy <- data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)),
SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1)))

In this example, row 9 has a negative measurement for Chamber 5,
so I
would like to delete row 6, which is the same Chamber on the  
same

day, but not row 3, which is the same chamber on a different
day.  In
the full dataframe, there are, of course, many more days.

Is there a handy R way to do this?

Thank you for the assistance.

Toby




Not fully tested, but here is one possibility:


toy

CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
3  5   4   0.4
4  3   4   0.5
5  4   4   0.6
6  5   5   0.2
7  3   5   0.1
8  4   5   0.0
9  5   5  -0.1


subset(toy, ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0))  
== 0)

CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
3  5   4   0.4
4  3   4   0.5
5  4   4  

Re: [R] conditional selection of dataframe rows

2010-08-12 Thread David Winsemius


On Aug 12, 2010, at 5:20 PM, Toby Gass wrote:


Hi,

I do want to look only at slope.
If there is one negative slope measurement  for a given day and a
given chamber, I would like to remove all other slope measurements
for that day and that chamber, even if they are positive.

On one day, I will have 20 slope measurements for each chamber.  If
one is negative, I would like to delete the other 19 for that chamber
on that day, even if they are positive.  I have measurements for
every day of the year, for 4 years and multiple chambers.

I know I could make some awful nested loop with a vector of day and
chamber numbers for each occurrence of a negative slope and then run
that against the whole data set but I hope not to have to do that.

Here is the rationale, if that helps.  These are unattended outdoor
chambers that measure soil carbon efflux.  When the numbers go
negative during part of the day but otherwise look normal, it usually
means a plant has sprouted in the chamber and is using the carbon
dioxide.  That means the measurements are all lower than they should
be and I need to discard all measurements collected on that day,
whether positive or negative.

It might have been a little clearer if I'd make the toy dataframe a
bit larger.


I think the fault was all mine. Failure to read for meaning. Here's an  
alternate strategy, although I think Schwartz's might be cleaner:


> toy$ch.day.cat <- with(toy, paste(CH, DAY, sep="."))
> negs.idxs <- tapply(toy$SLOPE , toy$ch.day.cat, function (x) any(x  
<0) )

> negs.idxs
  3.4   3.5   4.4   4.5   5.4   5.5
FALSE FALSE FALSE FALSE FALSE  TRUE
> toy[-which(negs.idxs), ]
  CH DAY SLOPE ch.day.cat
1  3   4   0.23.4
2  4   4   0.34.4
3  5   4   0.45.4
4  3   4   0.53.4
5  4   4   0.64.4
7  3   5   0.13.5
8  4   5   0.04.5
9  5   5  -0.15.5

--
David


Thanks again for the assistance.

Toby



On 12 Aug 2010 at 16:39, David Winsemius wrote:



On Aug 12, 2010, at 4:06 PM, Toby Gass wrote:


Thank you all for the quick responses.  So far as I've checked,
Marc's solution works perfectly and is quite speedy.  I'm still
trying to figure out what it is doing. :)

Henrique's solution seems to need some columns somewhere.  David's
solution does not find all the other measurements, possibly with
positive values, taken on the same day.


I assumed you only wanted to look at what appeared to be a data
column, SLOPE. If you want to look at all columns for negatives then
try:

toy[ which( apply(toy, 1, function(x) all(x >= 0)) ), ]  # or
toy[ apply(toy, 1, function(x) all(x >= 0)) , ]

This is how they differ w,r,t, their handling of NA's.


toy[3,2] <- NA
toy[ apply(toy, 1, function(x) all(x >= 0)) , ]

   CH DAY SLOPE
1   3   4   0.2
2   4   4   0.3
NA NA  NANA
4   3   4   0.5
5   4   4   0.6
6   5   5   0.2
7   3   5   0.1
8   4   5   0.0

toy[ which(apply(toy, 1, function(x) all(x >= 0)) ), ]

  CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
4  3   4   0.5
5  4   4   0.6
6  5   5   0.2
7  3   5   0.1
8  4   5   0.0




Thank you again for your efforts.

Toby

On 12 Aug 2010 at 14:32, Marc Schwartz wrote:


On Aug 12, 2010, at 2:24 PM, Marc Schwartz wrote:


On Aug 12, 2010, at 2:11 PM, Toby Gass wrote:


Dear helpeRs,

I have a dataframe (14947 x 27) containing measurements collected
every 5 seconds at several different sampling locations.  If one
measurement at a given location is less than zero on a given  
day, I

would like to delete all measurements from that location on that
day.

Here is a toy example:

toy <- data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)),
SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1)))

In this example, row 9 has a negative measurement for Chamber 5,
so I
would like to delete row 6, which is the same Chamber on the same
day, but not row 3, which is the same chamber on a different
day.  In
the full dataframe, there are, of course, many more days.

Is there a handy R way to do this?

Thank you for the assistance.

Toby




Not fully tested, but here is one possibility:


toy

CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
3  5   4   0.4
4  3   4   0.5
5  4   4   0.6
6  5   5   0.2
7  3   5   0.1
8  4   5   0.0
9  5   5  -0.1


subset(toy, ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0))  
== 0)

CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
3  5   4   0.4
4  3   4   0.5
5  4   4   0.6
7  3   5   0.1
8  4   5   0.0



This can actually be slightly shortened to:


subset(toy, !ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0)))

CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
3  5   4   0.4
4  3   4   0.5
5  4   4   0.6
7  3   5   0.1
8  4   5   0.0


HTH,

Marc



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

Re: [R] Plotting one dot in a graph

2010-08-12 Thread David Winsemius
OK, looks sensible, although I said either abs() OR squared  
differences. I don't think it makes sense to use both the L1 and the  
L2 metric at the same time.


--
David.
On Aug 12, 2010, at 4:58 PM, TGS wrote:

# just to clean it up for my own understanding, the "difference"  
approach as you had suggested would be


x <- seq(.2, .3, by = .1)
f1 <- function(x){
x*cos(x)-2*x**2+3*x-1
}
plot(x,f1(x), type = "l")
abline(h = -.1)
abline(v = x[which.min(abs(diff((f1(x) - (-.1))**2)))], lty =  
'dotted')

points(x = x[which.min(abs(diff((f1(x) - (-.1))**2)))], y = -.1)

# and the uniroot approach is:

x <- seq(.2, .3, by = .01)
f1 <- function(x){
x*cos(x)-2*x**2+3*x-1
}
f2 <- function(x){
-.1
}
f3 <- function(x){
f1(x) - f2(x)
}
plot(x,f1(x), type = "l")
abline(h = -.1)
abline(v = uniroot(f = f3, interval = c(.2, .3))$root, lty = 'dotted')
points(x = uniroot(f = f3, interval = c(.2, .3))$root, y = -.1)

# Thanks David!


On Aug 12, 2010, at 1:33 PM, David Winsemius wrote:


On Aug 12, 2010, at 4:15 PM, TGS wrote:

David, I was expecting this to work but how would I specify the  
vector in "diff()" in order for the following to work?


x <- seq(.2, .3, by = .01)
f <- function(x){
x*cos(x)-2*x**2+3*x-1
}
plot(x,f(x), type = "l")
abline(h = -.1)
abline(v = x[which.min(abs(diff(c(-.1, f(x)], lty = 'dotted')


f2 <- function(x) -0.1
f3 <- function(x) f(x) -f2(x)
abline(v=uniroot(f3, c(0.2, 0.3) )$root)
points(x=uniroot(f3, c(0.2, 0.3) )$root, y= -0.1)

If you are going to use the differences, then you probably want to  
minimize either the abs() or the square of the differences.


--
David.


On Aug 12, 2010, at 1:00 PM, David Winsemius wrote:


On Aug 12, 2010, at 3:54 PM, TGS wrote:


Actually I spoke too soon David.

I'm looking for a function that will either tell me which point is  
the intersection so that I'd be able to plot a point there.


Or, if I have to solve for the roots in the ways which were  
demonstrated yesterday, then would I be able to specify what the  
horizontal line is, for instance in the case where y (is-not) 0?


Isn't the abline h=0 represented mathematically by the equation y=0  
and therefore you are solving just for the zeros of "f" (whaich are  
the same as for (f-0)? If it were something more interesting, like  
solving the intersection of two polynomials, you would be solving  
for the  zeros of the difference of the equations. Or maybe I have  
not understood what you were requesting?





On Aug 12, 2010, at 12:47 PM, David Winsemius wrote:


On Aug 12, 2010, at 3:43 PM, TGS wrote:

I'd like to plot a point at the intersection of these two curves.  
Thanks


x <- seq(.2, .3, by = .01)
f <- function(x){
x*cos(x)-2*x**2+3*x-1
}

plot(x,f(x), type = "l")
abline(h = 0)


Would this just be the uniroot strategy applied to "f"? You then  
plot the x and y values with points()








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] Fiting a trend + periodic signal

2010-08-12 Thread Carl Witthoft

Use nls().

But you should also take the time to learn a bit about data fits in 
general.  I'm far from expert, but it sure looks like that P(t) is 
overconstrained.  Since cos(wt) = sin(wt+pi/2),  why do you have all 
those different terms?






Dear all,
I have a time series and I like to fit S(t) = T(t) + P(t)

 T(t) = Linear Trend = a + bt
 P(t) = Periodic Signal = sum(Ai*cos(wt) + Bi*sin(wt) ) for i=1,...,3.


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


Re: [R] storing the results of an apply call

2010-08-12 Thread Marc Schwartz
On Aug 12, 2010, at 4:07 PM, Greg Snow wrote:

>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
>> project.org] On Behalf Of Joshua Wiley
>> Sent: Wednesday, August 11, 2010 6:31 PM
>> To: Lorenzo Cattarino
>> Cc: r-help@r-project.org
>> Subject: Re: [R] storing the results of an apply call
> 
> 
>> 
>> What follows is not really an example.  There is no real data, which
>> while annoying could be overcome, but we also do not have your
>> function.  Last I heard, present or future Greg (I mix them up) is
>> working on a ESP package, but I am pretty certain it has not been
>> released yet.
>> 
> 
> Well, past me had hoped that someone (not necessarily any of me) would right 
> the ESP package, then future me would be able to get a copy and also a copy 
> of the TimeTravel package and use it to send a copy of the ESP package back 
> in time to past (or present) me to use.  However, that has not happened yet 
> (at least not to past or present me, there still is possibility for near 
> future me to get a copy from far future me).  Possible reasons include that 
> possibly future me is punishing past and present me for something that we did 
> or did not do (gotta stick to that diet, maybe that will help) or maybe even 
> something that near future me will do that has not occurred to present me as 
> yet.  Or possibly future me procrastinates just as bad as present me and 
> expects far distant future me to do it while far distant future me has 
> completed the journey into senility far enough to have forgotten that 
> moderate distant future me did not get around to doing it yet.
> 
> While I don't know the exact reasons why I have not yet received a copy of 
> the future working ESP package, it appears that I have created somewhat of an 
> expectation for the package, so I have made a crude start.  I have a function 
> to try, be warned it is very pre-alpha (possible aleph from the Phonecian 
> alphabet which was a predecessor of the Greek, indicating that it needs 
> improvements at least through the Phonecian before even being considered 
> alpha level).  I ran the esp function to see if it could shed some light on 
> this problem and the result was:
> 
> [1] "headline rightly silver foolishness insincerely culpability tuba 
> streptomycin hit clean-cut chateau aerospace diffusely"
> 
> I then ran the function again hoping for some clarification and received the 
> short but insightful:
> 
> [1] "metacarpal sit-down unfriendliness chapel ME"
> 
> Wanting further detail I ran it one more time and was told:
> 
> [1] "hemophiliac phonics dumdum secondary helpfulness proximity strychnine 
> nighthawk waive veggie"
> 
> 
> So you can see the current implementation is still less helpful than if 
> people with questions follow the posting guidelines in providing minimal self 
> contained working code (and the other advice in the guide).
> 
> Sorry this is not more helpful.
> 
> P.S.  I have also started on the TimeTravel package, but so far it only 
> allows for travel in one direction and that at a fairly predictable constant 
> rate.  I have been working on the "Subjective" section of the code, but so 
> far it is pretty boring and only makes the time seem to pass slower.


Two comments:

1. Isn't there a risk of the Grandfather Paradox here? (astrophysics is coming 
back to haunt me...)

2. I don't know if the fortunes package is the right place, but this exchange 
needs to be captured...


Regards,

Marc Schwartz

P.S. Pardon me while I go visit with the Emacs Psychotherapist (version 23 of 
course...)

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


Re: [R] conditional selection of dataframe rows

2010-08-12 Thread Toby Gass
Hi,

I do want to look only at slope.
If there is one negative slope measurement  for a given day and a 
given chamber, I would like to remove all other slope measurements 
for that day and that chamber, even if they are positive.  

On one day, I will have 20 slope measurements for each chamber.  If 
one is negative, I would like to delete the other 19 for that chamber 
on that day, even if they are positive.  I have measurements for 
every day of the year, for 4 years and multiple chambers.  

I know I could make some awful nested loop with a vector of day and 
chamber numbers for each occurrence of a negative slope and then run 
that against the whole data set but I hope not to have to do that.

Here is the rationale, if that helps.  These are unattended outdoor 
chambers that measure soil carbon efflux.  When the numbers go 
negative during part of the day but otherwise look normal, it usually 
means a plant has sprouted in the chamber and is using the carbon 
dioxide.  That means the measurements are all lower than they should 
be and I need to discard all measurements collected on that day, 
whether positive or negative.

It might have been a little clearer if I'd make the toy dataframe a 
bit larger.  

Thanks again for the assistance.

Toby



On 12 Aug 2010 at 16:39, David Winsemius wrote:

> 
> On Aug 12, 2010, at 4:06 PM, Toby Gass wrote:
> 
> > Thank you all for the quick responses.  So far as I've checked,
> > Marc's solution works perfectly and is quite speedy.  I'm still
> > trying to figure out what it is doing. :)
> >
> > Henrique's solution seems to need some columns somewhere.  David's
> > solution does not find all the other measurements, possibly with
> > positive values, taken on the same day.
> 
> I assumed you only wanted to look at what appeared to be a data  
> column, SLOPE. If you want to look at all columns for negatives then  
> try:
> 
> toy[ which( apply(toy, 1, function(x) all(x >= 0)) ), ]  # or
> toy[ apply(toy, 1, function(x) all(x >= 0)) , ]
> 
> This is how they differ w,r,t, their handling of NA's.
> 
>  > toy[3,2] <- NA
>  > toy[ apply(toy, 1, function(x) all(x >= 0)) , ]
> CH DAY SLOPE
> 1   3   4   0.2
> 2   4   4   0.3
> NA NA  NANA
> 4   3   4   0.5
> 5   4   4   0.6
> 6   5   5   0.2
> 7   3   5   0.1
> 8   4   5   0.0
>  > toy[ which(apply(toy, 1, function(x) all(x >= 0)) ), ]
>CH DAY SLOPE
> 1  3   4   0.2
> 2  4   4   0.3
> 4  3   4   0.5
> 5  4   4   0.6
> 6  5   5   0.2
> 7  3   5   0.1
> 8  4   5   0.0
> 
> 
> >
> > Thank you again for your efforts.
> >
> > Toby
> >
> > On 12 Aug 2010 at 14:32, Marc Schwartz wrote:
> >
> >> On Aug 12, 2010, at 2:24 PM, Marc Schwartz wrote:
> >>
> >>> On Aug 12, 2010, at 2:11 PM, Toby Gass wrote:
> >>>
>  Dear helpeRs,
> 
>  I have a dataframe (14947 x 27) containing measurements collected
>  every 5 seconds at several different sampling locations.  If one
>  measurement at a given location is less than zero on a given day, I
>  would like to delete all measurements from that location on that  
>  day.
> 
>  Here is a toy example:
> 
>  toy <- data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)),
>  SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1)))
> 
>  In this example, row 9 has a negative measurement for Chamber 5,  
>  so I
>  would like to delete row 6, which is the same Chamber on the same
>  day, but not row 3, which is the same chamber on a different  
>  day.  In
>  the full dataframe, there are, of course, many more days.
> 
>  Is there a handy R way to do this?
> 
>  Thank you for the assistance.
> 
>  Toby
> >>>
> >>>
> >>>
> >>> Not fully tested, but here is one possibility:
> >>>
>  toy
> >>> CH DAY SLOPE
> >>> 1  3   4   0.2
> >>> 2  4   4   0.3
> >>> 3  5   4   0.4
> >>> 4  3   4   0.5
> >>> 5  4   4   0.6
> >>> 6  5   5   0.2
> >>> 7  3   5   0.1
> >>> 8  4   5   0.0
> >>> 9  5   5  -0.1
> >>>
> >>>
>  subset(toy, ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0)) == 0)
> >>> CH DAY SLOPE
> >>> 1  3   4   0.2
> >>> 2  4   4   0.3
> >>> 3  5   4   0.4
> >>> 4  3   4   0.5
> >>> 5  4   4   0.6
> >>> 7  3   5   0.1
> >>> 8  4   5   0.0
> >>
> >>
> >> This can actually be slightly shortened to:
> >>
> >>> subset(toy, !ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0)))
> >>  CH DAY SLOPE
> >> 1  3   4   0.2
> >> 2  4   4   0.3
> >> 3  5   4   0.4
> >> 4  3   4   0.5
> >> 5  4   4   0.6
> >> 7  3   5   0.1
> >> 8  4   5   0.0
> >>
> >>
> >> HTH,
> >>
> >> Marc
> >>
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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.

Re: [R] Scatterplot - Overlap Frequency

2010-08-12 Thread Greg Snow
If you want a grid of hexagons, look at the examples in the my.symbols function 
(TeachingDemos package), one of those gives a way to create the grid of 
hexagons (not as efficient as the hexbin package, but allows you to set your 
own colors).

For choosing colors you may want to look at the RColorBrewer package or do a 
search for colorramp (several packages have functions for color ramps).  The 
findInterval function may also be of help if you do not want a 1 to 1 color 
match.

Hope this helps,

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


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Mestat
> Sent: Thursday, August 12, 2010 2:20 PM
> To: r-help@r-project.org
> Subject: [R] Scatterplot - Overlap Frequency
> 
> 
> Hi listers...
> I am working o a scatterplot where I would like to plot the variables
> according with another frequency variable.
> Another friend here proposed this code...
> x <- rnorm(10)
> y <- rnorm(10)
> ind <- c(1,0,1,0,1,0,1,1,0,0)
> plot(x, y, col = ind + 1, pch = 16)  # 1 is black, 2 is red
> 
> But in my case I would like to identify with different colors according
> with
> a frequency variable.
> x <- rnorm(10)
> y <- rnorm(10)
> ind <- c(3,0,1,0,3,0,2,2,0,0)
> 
> I made some research and I would like to do something like the function
> HEXBIN does:
> source("http://bioconductor.org/biocLite.R";)
> biocLite("hexbin")
> library(hexbin)
> x <- rnorm(1000)
> y <- rnorm(1000)
> bin<-hexbin(x, y, xbins=50)
> plot(bin, main="Hexagonal Binning")
> 
> But in my case I have another variable with the frequency and not high
> density frequency according the two plotted variables...
> Any suggestions, thanks...
> Marcio
> 
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Scatterplot-Overlap-Frequency-
> tp2323322p2323322.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] storing the results of an apply call

2010-08-12 Thread David Winsemius


On Aug 12, 2010, at 5:07 PM, Greg Snow wrote:



[1] "metacarpal sit-down unfriendliness chapel ME"



My wife gives "ME"  the "middle phalangeal unfriendliness" message  
about once a week.


--

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] conditional selection of dataframe rows

2010-08-12 Thread Marc Schwartz

On Aug 12, 2010, at 3:06 PM, Toby Gass wrote:

> Thank you all for the quick responses.  So far as I've checked, 
> Marc's solution works perfectly and is quite speedy.  I'm still 
> trying to figure out what it is doing. :)
> 
> Henrique's solution seems to need some columns somewhere.  David's 
> solution does not find all the other measurements, possibly with 
> positive values, taken on the same day.
> 
> Thank you again for your efforts.
> 
> Toby



Toby,

Working from the inside out:

The ave() function splits (sub-groups) the data frame by one or more factors, 
internally using split() and then passing the desired column from each 
sub-group to the function defined by using lapply(). By default, that is 
mean(). 

The great thing about using ave(), is that it will replicate the scalar 
sub-group based result of the function, once for each row in the sub-group. In 
addition, the result vector will be sorted in the order of the rows in the 
original data frame, rather than in the order of the sub-group rows. So in this 
case, if any of the rows in the sub-group has a SLOPE with negative value, all 
rows in the sub-group get a TRUE.


You can get an initial feel for the internal data organizing process by using:

> split(toy, list(toy$CH, toy$DAY))
$`3.4`
  CH DAY SLOPE
1  3   4   0.2
4  3   4   0.5

$`4.4`
  CH DAY SLOPE
2  4   4   0.3
5  4   4   0.6

$`5.4`
  CH DAY SLOPE
3  5   4   0.4

$`3.5`
  CH DAY SLOPE
7  3   5   0.1

$`4.5`
  CH DAY SLOPE
8  4   5 0

$`5.5`
  CH DAY SLOPE
6  5   5   0.2
9  5   5  -0.1



So the first step is:

> with(toy, ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0)))
[1] 0 0 0 0 0 1 0 0 1


Note that I use with() to define that SLOPE, CH and DAY are all to be evaluated 
(found) within the 'toy' data frame. That is easier than using:

> ave(toy$SLOPE, toy$CH, toy$DAY, FUN = function(x) any(x < 0))
[1] 0 0 0 0 0 1 0 0 1


This returns a vector of 0's and 1's (FALSE and TRUE coerced to a numeric). 
Note that the returned vector does not correspond to the sequence of rows in 
the result of split() above, but to the sequence of rows in the original 'toy' 
data frame. That is, rows 6 and 9 are 1 (TRUE):

> cbind(toy, flag = with(toy, ave(SLOPE, CH, DAY, 
  FUN = function(x) any(x < 0
  CH DAY SLOPE flag
1  3   4   0.20
2  4   4   0.30
3  5   4   0.40
4  3   4   0.50
5  4   4   0.60
6  5   5   0.21
7  3   5   0.10
8  4   5   0.00
9  5   5  -0.11


The next step is to remove those rows. You could do that by using regular 
indexing, but by using subset(), I can replicate the behavior of having used 
with() above, since the arguments in subset() are evaluated within the data 
frame defined. Thus, I can eliminate the use of with() and have a shorter 
solution. Then, by negating the result of ave() so that 0 (FALSE) becomes TRUE, 
retain only those rows where the ave() result was 0:

> subset(toy, !ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0)))
  CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
3  5   4   0.4
4  3   4   0.5
5  4   4   0.6
7  3   5   0.1
8  4   5   0.0


I hope that clarifies the process.

Marc

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


Re: [R] storing the results of an apply call

2010-08-12 Thread Greg Snow
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Joshua Wiley
> Sent: Wednesday, August 11, 2010 6:31 PM
> To: Lorenzo Cattarino
> Cc: r-help@r-project.org
> Subject: Re: [R] storing the results of an apply call


> 
> What follows is not really an example.  There is no real data, which
> while annoying could be overcome, but we also do not have your
> function.  Last I heard, present or future Greg (I mix them up) is
> working on a ESP package, but I am pretty certain it has not been
> released yet.
> 

Well, past me had hoped that someone (not necessarily any of me) would right 
the ESP package, then future me would be able to get a copy and also a copy of 
the TimeTravel package and use it to send a copy of the ESP package back in 
time to past (or present) me to use.  However, that has not happened yet (at 
least not to past or present me, there still is possibility for near future me 
to get a copy from far future me).  Possible reasons include that possibly 
future me is punishing past and present me for something that we did or did not 
do (gotta stick to that diet, maybe that will help) or maybe even something 
that near future me will do that has not occurred to present me as yet.  Or 
possibly future me procrastinates just as bad as present me and expects far 
distant future me to do it while far distant future me has completed the 
journey into senility far enough to have forgotten that moderate distant future 
me did not get around to doing it yet.

While I don't know the exact reasons why I have not yet received a copy of the 
future working ESP package, it appears that I have created somewhat of an 
expectation for the package, so I have made a crude start.  I have a function 
to try, be warned it is very pre-alpha (possible aleph from the Phonecian 
alphabet which was a predecessor of the Greek, indicating that it needs 
improvements at least through the Phonecian before even being considered alpha 
level).  I ran the esp function to see if it could shed some light on this 
problem and the result was:

[1] "headline rightly silver foolishness insincerely culpability tuba 
streptomycin hit clean-cut chateau aerospace diffusely"

I then ran the function again hoping for some clarification and received the 
short but insightful:

[1] "metacarpal sit-down unfriendliness chapel ME"

Wanting further detail I ran it one more time and was told:

[1] "hemophiliac phonics dumdum secondary helpfulness proximity strychnine 
nighthawk waive veggie"


So you can see the current implementation is still less helpful than if people 
with questions follow the posting guidelines in providing minimal self 
contained working code (and the other advice in the guide).

Sorry this is not more helpful.

P.S.  I have also started on the TimeTravel package, but so far it only allows 
for travel in one direction and that at a fairly predictable constant rate.  I 
have been working on the "Subjective" section of the code, but so far it is 
pretty boring and only makes the time seem to pass slower.




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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] send and receiving objects with Rmpi

2010-08-12 Thread Remi Gagne
Hi all,

I'm having difficulties passing data from the master to the children. I 
haven't seen any complete tutorial, all the tutorial broadcast data where 
I would like to send parts of my big tablechip list. 
Everytime I run this, the last line always jams. I even tried to reduce 
the number of rows in data to 10 and still doesn't work. I even tried to 
do a remote.exec(ls()) and doesn't work.

Any tips?

#sending my function
mpi.bcast.Robj2slave(forSlaves)

#sending a message to all children so they wait for data
mpi.bcast.cmd(cmd={data = mpi.recv.Robj(mpi.any.source(),mpi.any.tag())}) 

# Now, send the data to the children
for( i in 1:nrow(adds)){
 print(paste("sending part:",i))
 data = 
data.frame(tablechip[[1]][adds[i,1]:adds[i,2]],tablechip[[2]][adds[i,1]:adds[i,2]],tablechip[[3]][adds[i,1]:adds[i,2]])
 mpi.isend.Robj(data,i,i)
}

#next line jams
results = mpi.remote.exec(forSlaves())

Thanks,

Remi
[[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] reading fixed width format data with 2 types of lines

2010-08-12 Thread Charles C. Berry

On Thu, 12 Aug 2010, Tim Gruene wrote:


I don't know if it's elegant enough for you, but you could split the file into
two files with 'grep "^3" file > file_3' and 'grep "^4" file > file_4'
and then read them in separately.



along the same lines, but all in R (untested)

original.lines <- readLines( filename )

tcon.3 <- textConnection( grep( "^3", original.lines, value=T ))
res.3 <- read.fwf( tcon.3,  )
close(tcon.3)

tcon.4 <- textConnection( grep( "^4", original.lines, value=T ))
res.4 <- read.fwf( tcon.4,  )
close(tcon.4)

rm( original.lines )

Or skip the readLines() step and use

tcon.3 <- pipe(paste("grep '^3'",filename))

...

I think you can use 'findstr.exe' on windows in lieu of grep.

HTH,

Chuck





Tim

On Thu, Aug 12, 2010 at 01:57:19PM -0400, Denis Chabot wrote:

Hi,

I know how to read fixed width format data with read.fwf, but suddenly I need to read in a large 
number of old fwf files with 2 types of lines. Lines that begin with "3" in first column 
carry one set of variables, and lines that begin with "4" carry another set, like this:

???
3A00206546L07004901609004599  1015002  001001008010004002004007003   001
3A00206546L07004900609003099  1029001002001001006014002
3A00206546L07004900229000499  1015001001
3A00206546L070049001692559049033  1015 018036024
3A00206546L07004900229000499  1001   002
4A00176546L06804709001011100060651640015001001501063   065914
4A00176546L068047090010111000407616 1092   095614
4A00196546L098000100010111001706214450151062   065914
4A00176546L068047090010111000505913 1062   065914
4A00196546L09800010001011100260472140002001000201042   046114
4A00196546L0980001000101110025042214501200051042   046114
4A00196546L09800010001011100290372140005001220501032   036214
???

I have searched for tricks to do this but I must not have used the right 
keywords, I found nothing.

I suppose I could read the entire file as a single character variable for each 
line, then subset for lines that begin with 3 and save this in an ascii file 
that will then be reopened with a read.fwf call, and do the same with lines 
that begin with 4. But this does not appear to me to be very elegant nor 
efficient??? Is there a better method?

Thanks in advance,


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


--
--
Tim Gruene
Institut fuer anorganische Chemie
Tammannstr. 4
D-37077 Goettingen

GPG Key ID = A46BEE1A




Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

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


Re: [R] Plotting one dot in a graph

2010-08-12 Thread TGS
# just to clean it up for my own understanding, the "difference" approach as 
you had suggested would be

x <- seq(.2, .3, by = .1)
f1 <- function(x){
x*cos(x)-2*x**2+3*x-1
}
plot(x,f1(x), type = "l")
abline(h = -.1)
abline(v = x[which.min(abs(diff((f1(x) - (-.1))**2)))], lty = 'dotted')
points(x = x[which.min(abs(diff((f1(x) - (-.1))**2)))], y = -.1)

# and the uniroot approach is:

x <- seq(.2, .3, by = .01)
f1 <- function(x){
x*cos(x)-2*x**2+3*x-1
}
f2 <- function(x){
-.1
}
f3 <- function(x){
f1(x) - f2(x)
}
plot(x,f1(x), type = "l")
abline(h = -.1)
abline(v = uniroot(f = f3, interval = c(.2, .3))$root, lty = 'dotted')
points(x = uniroot(f = f3, interval = c(.2, .3))$root, y = -.1)

# Thanks David!


On Aug 12, 2010, at 1:33 PM, David Winsemius wrote:


On Aug 12, 2010, at 4:15 PM, TGS wrote:

> David, I was expecting this to work but how would I specify the vector in 
> "diff()" in order for the following to work?
> 
> x <- seq(.2, .3, by = .01)
> f <- function(x){
>   x*cos(x)-2*x**2+3*x-1
> }
> plot(x,f(x), type = "l")
> abline(h = -.1)
> abline(v = x[which.min(abs(diff(c(-.1, f(x)], lty = 'dotted')

f2 <- function(x) -0.1
f3 <- function(x) f(x) -f2(x)
abline(v=uniroot(f3, c(0.2, 0.3) )$root)
points(x=uniroot(f3, c(0.2, 0.3) )$root, y= -0.1)

If you are going to use the differences, then you probably want to minimize 
either the abs() or the square of the differences.

-- 
David.
> 
> On Aug 12, 2010, at 1:00 PM, David Winsemius wrote:
> 
> 
> On Aug 12, 2010, at 3:54 PM, TGS wrote:
> 
>> Actually I spoke too soon David.
>> 
>> I'm looking for a function that will either tell me which point is the 
>> intersection so that I'd be able to plot a point there.
>> 
>> Or, if I have to solve for the roots in the ways which were demonstrated 
>> yesterday, then would I be able to specify what the horizontal line is, for 
>> instance in the case where y (is-not) 0?
> 
> Isn't the abline h=0 represented mathematically by the equation y=0 and 
> therefore you are solving just for the zeros of "f" (whaich are the same as 
> for (f-0)? If it were something more interesting, like solving the 
> intersection of two polynomials, you would be solving for the  zeros of the 
> difference of the equations. Or maybe I have not understood what you were 
> requesting?
> 
> 
>> 
>> On Aug 12, 2010, at 12:47 PM, David Winsemius wrote:
>> 
>> 
>> On Aug 12, 2010, at 3:43 PM, TGS wrote:
>> 
>>> I'd like to plot a point at the intersection of these two curves. Thanks
>>> 
>>> x <- seq(.2, .3, by = .01)
>>> f <- function(x){
>>> x*cos(x)-2*x**2+3*x-1
>>> }
>>> 
>>> plot(x,f(x), type = "l")
>>> abline(h = 0)
>> 
>> Would this just be the uniroot strategy applied to "f"? You then plot the x 
>> and y values with points()
>> 
> 
>> 
> 
> 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] Scatterplot - Overlap Frequency

2010-08-12 Thread Wu Gong

Hi Marcio,

Your friend has given the answer.

x <- rnorm(10)
y <- rnorm(10)
ind <- c(3,0,1,0,3,0,2,2,0,0) 

plot(x, y, col = grey(0:max(ind)/max(ind))[ind], pch = 16)



Mestat wrote:
> 
> I am working o a scatterplot where I would like to plot the variables
> according with another frequency variable.
> 

Regards,

Wu

-
A R learner.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Scatterplot-Overlap-Frequency-tp2323322p2323349.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] conditional selection of dataframe rows

2010-08-12 Thread David Winsemius


On Aug 12, 2010, at 4:06 PM, Toby Gass wrote:


Thank you all for the quick responses.  So far as I've checked,
Marc's solution works perfectly and is quite speedy.  I'm still
trying to figure out what it is doing. :)

Henrique's solution seems to need some columns somewhere.  David's
solution does not find all the other measurements, possibly with
positive values, taken on the same day.


I assumed you only wanted to look at what appeared to be a data  
column, SLOPE. If you want to look at all columns for negatives then  
try:


toy[ which( apply(toy, 1, function(x) all(x >= 0)) ), ]  # or
toy[ apply(toy, 1, function(x) all(x >= 0)) , ]

This is how they differ w,r,t, their handling of NA's.

> toy[3,2] <- NA
> toy[ apply(toy, 1, function(x) all(x >= 0)) , ]
   CH DAY SLOPE
1   3   4   0.2
2   4   4   0.3
NA NA  NANA
4   3   4   0.5
5   4   4   0.6
6   5   5   0.2
7   3   5   0.1
8   4   5   0.0
> toy[ which(apply(toy, 1, function(x) all(x >= 0)) ), ]
  CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
4  3   4   0.5
5  4   4   0.6
6  5   5   0.2
7  3   5   0.1
8  4   5   0.0




Thank you again for your efforts.

Toby

On 12 Aug 2010 at 14:32, Marc Schwartz wrote:


On Aug 12, 2010, at 2:24 PM, Marc Schwartz wrote:


On Aug 12, 2010, at 2:11 PM, Toby Gass wrote:


Dear helpeRs,

I have a dataframe (14947 x 27) containing measurements collected
every 5 seconds at several different sampling locations.  If one
measurement at a given location is less than zero on a given day, I
would like to delete all measurements from that location on that  
day.


Here is a toy example:

toy <- data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)),
SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1)))

In this example, row 9 has a negative measurement for Chamber 5,  
so I

would like to delete row 6, which is the same Chamber on the same
day, but not row 3, which is the same chamber on a different  
day.  In

the full dataframe, there are, of course, many more days.

Is there a handy R way to do this?

Thank you for the assistance.

Toby




Not fully tested, but here is one possibility:


toy

CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
3  5   4   0.4
4  3   4   0.5
5  4   4   0.6
6  5   5   0.2
7  3   5   0.1
8  4   5   0.0
9  5   5  -0.1



subset(toy, ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0)) == 0)

CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
3  5   4   0.4
4  3   4   0.5
5  4   4   0.6
7  3   5   0.1
8  4   5   0.0



This can actually be slightly shortened to:


subset(toy, !ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0)))

 CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
3  5   4   0.4
4  3   4   0.5
5  4   4   0.6
7  3   5   0.1
8  4   5   0.0


HTH,

Marc



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

2010-08-12 Thread Henrique Dallazuanna
Try this:

setdiff(list, s)

On Thu, Aug 12, 2010 at 5:32 PM, André de Boer  wrote:

> Hi,
>
> I want to eliminate an element of a list:
>
> list <- seq(1,5,1)
> s <- sample(list,1)
>
> lets say s=3
> Now I want to remove 3 from the list: list2 = {1,2,4,5}
>
> Can someone give me a tip?
>
> Thanks,
> André
>
>[[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] how to eliminate an element of a list

2010-08-12 Thread André de Boer
Hi,

I want to eliminate an element of a list:

list <- seq(1,5,1)
s <- sample(list,1)

lets say s=3
Now I want to remove 3 from the list: list2 = {1,2,4,5}

Can someone give me a tip?

Thanks,
André

[[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] Scatterplot - Overlap Frequency

2010-08-12 Thread Mestat

Hi listers...
I am working o a scatterplot where I would like to plot the variables
according with another frequency variable.
Another friend here proposed this code...
x <- rnorm(10)
y <- rnorm(10)
ind <- c(1,0,1,0,1,0,1,1,0,0)
plot(x, y, col = ind + 1, pch = 16)  # 1 is black, 2 is red 

But in my case I would like to identify with different colors according with
a frequency variable.
x <- rnorm(10)
y <- rnorm(10)
ind <- c(3,0,1,0,3,0,2,2,0,0)

I made some research and I would like to do something like the function
HEXBIN does:
source("http://bioconductor.org/biocLite.R";)
biocLite("hexbin")
library(hexbin)
x <- rnorm(1000)
y <- rnorm(1000)
bin<-hexbin(x, y, xbins=50)
plot(bin, main="Hexagonal Binning")

But in my case I have another variable with the frequency and not high
density frequency according the two plotted variables...
Any suggestions, thanks...
Marcio

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Scatterplot-Overlap-Frequency-tp2323322p2323322.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] build.pl in building library with Rtools211

2010-08-12 Thread Uwe Ligges

What did you try?
R CMD build (build all lower case) does work for me

Uwe Ligges




On 09.08.2010 22:30, Hintzen, Niels wrote:

Dear all,

As I couldn't find any thread on the internet I hope the help-list might help 
me out.

I've tried to update Rtools from R210 used in combination with R2.9.1 to R211 
in combination with R2.11.1. However, I do not succeed.

I have R2.11.1 running, as well as Inno Setup 5, HTML help and MikTex. A 
version of Perl is installed too. Environment variable paths are set to link to 
these directories too.

However, when I try to build a library using: R CMD BUILD mypackage it 
immediately crashes as apparently it cannot find the file 'build' in 
R-2.11.1/bin. Indeed, this file is not present there (only build.pl) while this 
file is present in the R-2.9.1/bin directory.

What obvious thing am I doing wrong.

Your help is much appreciated.

With regards,

Niels Hintzen



[[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] conditional selection of dataframe rows

2010-08-12 Thread Toby Gass
Thank you all for the quick responses.  So far as I've checked, 
Marc's solution works perfectly and is quite speedy.  I'm still 
trying to figure out what it is doing. :)

Henrique's solution seems to need some columns somewhere.  David's 
solution does not find all the other measurements, possibly with 
positive values, taken on the same day.

Thank you again for your efforts.

Toby

On 12 Aug 2010 at 14:32, Marc Schwartz wrote:

> On Aug 12, 2010, at 2:24 PM, Marc Schwartz wrote:
> 
> > On Aug 12, 2010, at 2:11 PM, Toby Gass wrote:
> > 
> >> Dear helpeRs,
> >> 
> >> I have a dataframe (14947 x 27) containing measurements collected 
> >> every 5 seconds at several different sampling locations.  If one 
> >> measurement at a given location is less than zero on a given day, I 
> >> would like to delete all measurements from that location on that day.
> >> 
> >> Here is a toy example:
> >> 
> >> toy <- data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)), 
> >> SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1)))
> >> 
> >> In this example, row 9 has a negative measurement for Chamber 5, so I 
> >> would like to delete row 6, which is the same Chamber on the same 
> >> day, but not row 3, which is the same chamber on a different day.  In 
> >> the full dataframe, there are, of course, many more days.
> >> 
> >> Is there a handy R way to do this?
> >> 
> >> Thank you for the assistance.
> >> 
> >> Toby
> > 
> > 
> > 
> > Not fully tested, but here is one possibility:
> > 
> >> toy
> >  CH DAY SLOPE
> > 1  3   4   0.2
> > 2  4   4   0.3
> > 3  5   4   0.4
> > 4  3   4   0.5
> > 5  4   4   0.6
> > 6  5   5   0.2
> > 7  3   5   0.1
> > 8  4   5   0.0
> > 9  5   5  -0.1
> > 
> > 
> >> subset(toy, ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0)) == 0)
> >  CH DAY SLOPE
> > 1  3   4   0.2
> > 2  4   4   0.3
> > 3  5   4   0.4
> > 4  3   4   0.5
> > 5  4   4   0.6
> > 7  3   5   0.1
> > 8  4   5   0.0
> 
> 
> This can actually be slightly shortened to:
> 
> > subset(toy, !ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0)))
>   CH DAY SLOPE
> 1  3   4   0.2
> 2  4   4   0.3
> 3  5   4   0.4
> 4  3   4   0.5
> 5  4   4   0.6
> 7  3   5   0.1
> 8  4   5   0.0
> 
> 
> HTH,
> 
> Marc
>

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


Re: [R] Plotting one dot in a graph

2010-08-12 Thread TGS
I was meaning something like the following:

x <- seq(.2, .3, by = .01)
f <- function(x){
x*cos(x)-2*x**2+3*x-1
}
plot(x,f(x), type = "l")
abline(h = -.1)

But I'm guessing "uniroot" will do this?---I haven't looked far into the 
uniroot function to see if it will solve this.

On Aug 12, 2010, at 1:00 PM, David Winsemius wrote:


On Aug 12, 2010, at 3:54 PM, TGS wrote:

> Actually I spoke too soon David.
> 
> I'm looking for a function that will either tell me which point is the 
> intersection so that I'd be able to plot a point there.
> 
> Or, if I have to solve for the roots in the ways which were demonstrated 
> yesterday, then would I be able to specify what the horizontal line is, for 
> instance in the case where y (is-not) 0?

Isn't the abline h=0 represented mathematically by the equation y=0 and 
therefore you are solving just for the zeros of "f" (whaich are the same as for 
(f-0)? If it were something more interesting, like solving the intersection of 
two polynomials, you would be solving for the  zeros of the difference of the 
equations. Or maybe I have not understood what you were requesting?


> 
> On Aug 12, 2010, at 12:47 PM, David Winsemius wrote:
> 
> 
> On Aug 12, 2010, at 3:43 PM, TGS wrote:
> 
>> I'd like to plot a point at the intersection of these two curves. Thanks
>> 
>> x <- seq(.2, .3, by = .01)
>> f <- function(x){
>>  x*cos(x)-2*x**2+3*x-1
>> }
>> 
>> plot(x,f(x), type = "l")
>> abline(h = 0)
> 
> Would this just be the uniroot strategy applied to "f"? You then plot the x 
> and y values with points()
> 

> 

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] reading fixed width format data with 2 types of lines

2010-08-12 Thread Tim Gruene
I don't know if it's elegant enough for you, but you could split the file into
two files with 'grep "^3" file > file_3' and 'grep "^4" file > file_4'
and then read them in separately.

Tim

On Thu, Aug 12, 2010 at 01:57:19PM -0400, Denis Chabot wrote:
> Hi,
> 
> I know how to read fixed width format data with read.fwf, but suddenly I need 
> to read in a large number of old fwf files with 2 types of lines. Lines that 
> begin with "3" in first column carry one set of variables, and lines that 
> begin with "4" carry another set, like this:
> 
> …
> 3A00206546L07004901609004599  1015002  001001008010004002004007003   
> 001
> 3A00206546L07004900609003099  1029001002001001006014002   
>   
> 3A00206546L07004900229000499  1015001001  
>   
> 3A00206546L070049001692559049033  1015 
> 018036024
> 3A00206546L07004900229000499  1001   
> 002
> 4A00176546L06804709001011100060651640015001001501063   065914 
>   
> 4A00176546L068047090010111000407616 1092   095614 
>   
> 4A00196546L098000100010111001706214450151062   065914 
>   
> 4A00176546L068047090010111000505913 1062   065914 
>   
> 4A00196546L09800010001011100260472140002001000201042   046114 
>   
> 4A00196546L0980001000101110025042214501200051042   046114 
>   
> 4A00196546L09800010001011100290372140005001220501032   036214 
>   
> …
> 
> I have searched for tricks to do this but I must not have used the right 
> keywords, I found nothing.
> 
> I suppose I could read the entire file as a single character variable for 
> each line, then subset for lines that begin with 3 and save this in an ascii 
> file that will then be reopened with a read.fwf call, and do the same with 
> lines that begin with 4. But this does not appear to me to be very elegant 
> nor efficient… Is there a better method?
> 
> Thanks in advance,
> 
> 
> Denis Chabot
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
--
Tim Gruene
Institut fuer anorganische Chemie
Tammannstr. 4
D-37077 Goettingen

GPG Key ID = A46BEE1A



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


Re: [R] Plotting one dot in a graph

2010-08-12 Thread David Winsemius


On Aug 12, 2010, at 3:54 PM, TGS wrote:


Actually I spoke too soon David.

I'm looking for a function that will either tell me which point is  
the intersection so that I'd be able to plot a point there.


Or, if I have to solve for the roots in the ways which were  
demonstrated yesterday, then would I be able to specify what the  
horizontal line is, for instance in the case where y (is-not) 0?


Isn't the abline h=0 represented mathematically by the equation y=0  
and therefore you are solving just for the zeros of "f" (whaich are  
the same as for (f-0)? If it were something more interesting, like  
solving the intersection of two polynomials, you would be solving for  
the  zeros of the difference of the equations. Or maybe I have not  
understood what you were requesting?





On Aug 12, 2010, at 12:47 PM, David Winsemius wrote:


On Aug 12, 2010, at 3:43 PM, TGS wrote:

I'd like to plot a point at the intersection of these two curves.  
Thanks


x <- seq(.2, .3, by = .01)
f <- function(x){
x*cos(x)-2*x**2+3*x-1
}

plot(x,f(x), type = "l")
abline(h = 0)


Would this just be the uniroot strategy applied to "f"? You then  
plot the x and y values with points()








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] help usin scan on large matrix (caveats to what has been discussed before)

2010-08-12 Thread Martin Tomko
I did. Did not work. Did you try your code? The matrix did not result into
integer numbers as expected. MY approach resulted in a correct scan
result, at least.

M.
> Martin Tomko wrote:
>> Hi Peter,
>> apologies, too fast copying and pasting.
>> So, here is the explanation:
>> f<-"C:/test/mytab.txt";
>> R<-readLines(con=f);
>>
>> where mytab.txt is a table formatted as noted in previous post (space
>> delimited, with header, rownames, containing integers).
>>
>> Now, my understandign of scan was that I have to specify the FULL number
>> of values in it (examples specify things like 200*2000 for a matrix
>> etc). That's why I thought that I need to do cols*rows as well. Avoiding
>> the first line with headers is simple, avoiding the first column is not
>> - hence my questions.
>> Sorry, the corrected, matching parentheses are here - why did the
>> previous execute is a wonder...
>> c<-scan(file=f,what=rep(c(list(NULL),rep(list(0L),cols-1)),rows-1),
>> skip=1)
>> here, my reasoning was:
>>
>> * c(list(NULL),rep(list(0L),cols-1)) specifies a template for any line
>> (first elelement to be ignored => NULL, it is a string in the table
>> specified, and then a repetition of integers - I am still not sure how
>> you derived 0L, and what it means and where to find a doc for that.);
>> * the previous needs to be repeated rows-1 times, hence
>> what=rep(c(list(NULL),rep(list(0L),cols-1)),rows-1)
>>
>> I do nto understand the following:
>>
>>   You need an unlist(c). And more than likely NOT byrow=TRUE. However, I
>> think do.call(cbind,c) should do the trick more easily.
>>
>> what will unlist(c) do; why should it not be bywrow=TRUE, and how would
>> you go about integrating do.call(cbind,c) with matrix. Apologies to
>> naive questions, I am a newbie, in principle.
>>
>
> At this point I think you need to actually try my suggestions, and maybe
> read the documentation again. Explaining how you have misunderstood the
> documentation is not going to help...
>
> --
> Peter Dalgaard
> Center for Statistics, Copenhagen Business School
> Phone: (+45)38153501
> Email: pd@cbs.dk  Priv: pda...@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] Plotting one dot in a graph

2010-08-12 Thread TGS
Actually I spoke too soon David.

I'm looking for a function that will either tell me which point is the 
intersection so that I'd be able to plot a point there.

Or, if I have to solve for the roots in the ways which were demonstrated 
yesterday, then would I be able to specify what the horizontal line is, for 
instance in the case where y (is-not) 0?

On Aug 12, 2010, at 12:47 PM, David Winsemius wrote:


On Aug 12, 2010, at 3:43 PM, TGS wrote:

> I'd like to plot a point at the intersection of these two curves. Thanks
> 
> x <- seq(.2, .3, by = .01)
> f <- function(x){
>   x*cos(x)-2*x**2+3*x-1
> }
> 
> plot(x,f(x), type = "l")
> abline(h = 0)

Would this just be the uniroot strategy applied to "f"? You then plot the x and 
y values with points()

-- 

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] Plotting one dot in a graph

2010-08-12 Thread TGS
Yes, I'm playing around with other things but the "points()" function is what I 
was looking for. Thanks

On Aug 12, 2010, at 12:47 PM, David Winsemius wrote:


On Aug 12, 2010, at 3:43 PM, TGS wrote:

> I'd like to plot a point at the intersection of these two curves. Thanks
> 
> x <- seq(.2, .3, by = .01)
> f <- function(x){
>   x*cos(x)-2*x**2+3*x-1
> }
> 
> plot(x,f(x), type = "l")
> abline(h = 0)

Would this just be the uniroot strategy applied to "f"? You then plot the x and 
y values with points()

-- 

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] x-axis label print in 45 degree

2010-08-12 Thread array chip
I searched with "print x-axis label in 45 degree" which didn't return useful 
links. Apparently I used poor search keywords.






- Original Message 
From: David Winsemius 
To: Marc Schwartz 
Cc: array chip ; r-help@r-project.org
Sent: Thu, August 12, 2010 12:34:16 PM
Subject: Re: [R] x-axis label print in 45 degree


On Aug 12, 2010, at 3:17 PM, Marc Schwartz wrote:

> On Aug 12, 2010, at 2:14 PM, array chip wrote:
> 
>> Hi how can print x-axis labels in 45 degree in boxplot() (or plot in 
>> general)? 
>>I
>> can use las=2 to print in 90 degree, but it looks ugly. Is there a simple 
>>option
>> to do 45 degree easily?
>> 
>> Thanks
>> 
>> John
> 
> 
> John,
> 
> See R FAQ 7.27 How can I create rotated axis labels?
> 
>  
>http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f
>
> 

Although several of the hits in a search on "rotate axis labels" did point to 
the FAQ, there are probably other worked examples you could easily have found 
in 
the other 130+ hits at Baron's search page (including it appears on a cursory 
examination one from Marc in  each of the last 7 years).

> HTH,
> 
> Marc Schwartz
--
> .

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] x-axis label print in 45 degree

2010-08-12 Thread array chip
Than you Marc.

John



- Original Message 
From: Marc Schwartz 
To: array chip 
Cc: r-help@r-project.org
Sent: Thu, August 12, 2010 12:17:12 PM
Subject: Re: [R] x-axis label print in 45 degree

On Aug 12, 2010, at 2:14 PM, array chip wrote:

> Hi how can print x-axis labels in 45 degree in boxplot() (or plot in 
> general)? 
>I 
>
> can use las=2 to print in 90 degree, but it looks ugly. Is there a simple 
>option 
>
> to do 45 degree easily?
> 
> Thanks
> 
> John


John,

See R FAQ 7.27 How can I create rotated axis labels?

  
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f


HTH,

Marc Schwartz

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


[R] Plotting one dot in a graph

2010-08-12 Thread TGS
I'd like to plot a point at the intersection of these two curves. Thanks

x <- seq(.2, .3, by = .01)
f <- function(x){
x*cos(x)-2*x**2+3*x-1
}

plot(x,f(x), type = "l")
abline(h = 0)

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


Re: [R] rpart package

2010-08-12 Thread Boris Reiss

Hi Olga,
not directly related to your question. We have also a server 
installation and subsequently our IT department determines which version 
and packages I can use on R.
A few days ago I have switched to R-portable. Works without any problems 
from my USB stick on any locked-for-installation Windows PC or open PC. 
I am not sure, but I have the feeling that my scripts are also faster 
executed.


Good luck,

Boris


On 2010-08-12 8:18 PM, Erik Iverson wrote:



Olga Shaganova wrote:

Hi,

I am a brand new user and may be my question is too simple. I have R on
our (not Unix) server. I am trying to build a decision tree and the error
message says "couldn't find function rpart". Does it mean I have to
ask our
server guy to install an additional package?


You have to load the "rpart" package

 > library(rpart)

If that succeeds, you should have the rpart function available. I think
rpart is a recommended package, so you should be OK.

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




No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.851 / Virus Database: 271.1.1/3066 - Release Date: 08/12/10 
08:34:00



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


Re: [R] x-axis label print in 45 degree

2010-08-12 Thread David Winsemius


On Aug 12, 2010, at 3:17 PM, Marc Schwartz wrote:


On Aug 12, 2010, at 2:14 PM, array chip wrote:

Hi how can print x-axis labels in 45 degree in boxplot() (or plot  
in general)? I
can use las=2 to print in 90 degree, but it looks ugly. Is there a  
simple option

to do 45 degree easily?

Thanks

John



John,

See R FAQ 7.27 How can I create rotated axis labels?

 
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f



Although several of the hits in a search on "rotate axis labels" did  
point to the FAQ, there are probably other worked examples you could  
easily have found in the other 130+ hits at Baron's search page  
(including it appears on a cursory examination one from Marc in  each  
of the last 7 years).



HTH,

Marc Schwartz

--

.


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] conditional selection of dataframe rows

2010-08-12 Thread Marc Schwartz
On Aug 12, 2010, at 2:24 PM, Marc Schwartz wrote:

> On Aug 12, 2010, at 2:11 PM, Toby Gass wrote:
> 
>> Dear helpeRs,
>> 
>> I have a dataframe (14947 x 27) containing measurements collected 
>> every 5 seconds at several different sampling locations.  If one 
>> measurement at a given location is less than zero on a given day, I 
>> would like to delete all measurements from that location on that day.
>> 
>> Here is a toy example:
>> 
>> toy <- data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)), 
>> SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1)))
>> 
>> In this example, row 9 has a negative measurement for Chamber 5, so I 
>> would like to delete row 6, which is the same Chamber on the same 
>> day, but not row 3, which is the same chamber on a different day.  In 
>> the full dataframe, there are, of course, many more days.
>> 
>> Is there a handy R way to do this?
>> 
>> Thank you for the assistance.
>> 
>> Toby
> 
> 
> 
> Not fully tested, but here is one possibility:
> 
>> toy
>  CH DAY SLOPE
> 1  3   4   0.2
> 2  4   4   0.3
> 3  5   4   0.4
> 4  3   4   0.5
> 5  4   4   0.6
> 6  5   5   0.2
> 7  3   5   0.1
> 8  4   5   0.0
> 9  5   5  -0.1
> 
> 
>> subset(toy, ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0)) == 0)
>  CH DAY SLOPE
> 1  3   4   0.2
> 2  4   4   0.3
> 3  5   4   0.4
> 4  3   4   0.5
> 5  4   4   0.6
> 7  3   5   0.1
> 8  4   5   0.0


This can actually be slightly shortened to:

> subset(toy, !ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0)))
  CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
3  5   4   0.4
4  3   4   0.5
5  4   4   0.6
7  3   5   0.1
8  4   5   0.0


HTH,

Marc

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


Re: [R] conditional selection of dataframe rows

2010-08-12 Thread Marc Schwartz
On Aug 12, 2010, at 2:11 PM, Toby Gass wrote:

> Dear helpeRs,
> 
> I have a dataframe (14947 x 27) containing measurements collected 
> every 5 seconds at several different sampling locations.  If one 
> measurement at a given location is less than zero on a given day, I 
> would like to delete all measurements from that location on that day.
> 
> Here is a toy example:
> 
> toy <- data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)), 
> SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1)))
> 
> In this example, row 9 has a negative measurement for Chamber 5, so I 
> would like to delete row 6, which is the same Chamber on the same 
> day, but not row 3, which is the same chamber on a different day.  In 
> the full dataframe, there are, of course, many more days.
> 
> Is there a handy R way to do this?
> 
> Thank you for the assistance.
> 
> Toby



Not fully tested, but here is one possibility:

> toy
  CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
3  5   4   0.4
4  3   4   0.5
5  4   4   0.6
6  5   5   0.2
7  3   5   0.1
8  4   5   0.0
9  5   5  -0.1


> subset(toy, ave(SLOPE, CH, DAY, FUN = function(x) any(x < 0)) == 0)
  CH DAY SLOPE
1  3   4   0.2
2  4   4   0.3
3  5   4   0.4
4  3   4   0.5
5  4   4   0.6
7  3   5   0.1
8  4   5   0.0


See ?ave and ?subset


HTH,

Marc Schwartz

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


Re: [R] conditional selection of dataframe rows

2010-08-12 Thread Henrique Dallazuanna
Try this:

subset(toy, !rowSums(mapply(is.element, toy[c('CH', 'DAY')], subset(toy,
SLOPE < 0, CH:DAY))) > 1 | SLOPE < 0)


On Thu, Aug 12, 2010 at 4:11 PM, Toby Gass  wrote:

> Dear helpeRs,
>
> I have a dataframe (14947 x 27) containing measurements collected
> every 5 seconds at several different sampling locations.  If one
> measurement at a given location is less than zero on a given day, I
> would like to delete all measurements from that location on that day.
>
> Here is a toy example:
>
> toy <- data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)),
> SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1)))
>
> In this example, row 9 has a negative measurement for Chamber 5, so I
> would like to delete row 6, which is the same Chamber on the same
> day, but not row 3, which is the same chamber on a different day.  In
> the full dataframe, there are, of course, many more days.
>
> Is there a handy R way to do this?
>
> Thank you for the assistance.
>
> Toby
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] conditional selection of dataframe rows

2010-08-12 Thread David Winsemius


On Aug 12, 2010, at 3:11 PM, Toby Gass wrote:


Dear helpeRs,

I have a dataframe (14947 x 27) containing measurements collected
every 5 seconds at several different sampling locations.  If one
measurement at a given location is less than zero on a given day, I
would like to delete all measurements from that location on that day.

Here is a toy example:

toy <- data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)),
SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1)))

In this example, row 9 has a negative measurement for Chamber 5, so I
would like to delete row 6, which is the same Chamber on the same
day, but not row 3, which is the same chamber on a different day.  In
the full dataframe, there are, of course, many more days.

Is there a handy R way to do this?


toy[ - which(toy$SLOPE <0 ) , ]



Thank you for the assistance.

Toby

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] x-axis label print in 45 degree

2010-08-12 Thread Marc Schwartz
On Aug 12, 2010, at 2:14 PM, array chip wrote:

> Hi how can print x-axis labels in 45 degree in boxplot() (or plot in 
> general)? I 
> can use las=2 to print in 90 degree, but it looks ugly. Is there a simple 
> option 
> to do 45 degree easily?
> 
> Thanks
> 
> John


John,

See R FAQ 7.27 How can I create rotated axis labels?

  
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f

HTH,

Marc Schwartz

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


[R] x-axis label print in 45 degree

2010-08-12 Thread array chip
Hi how can print x-axis labels in 45 degree in boxplot() (or plot in general)? 
I 
can use las=2 to print in 90 degree, but it looks ugly. Is there a simple 
option 
to do 45 degree easily?

Thanks

John

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


[R] conditional selection of dataframe rows

2010-08-12 Thread Toby Gass
Dear helpeRs,

I have a dataframe (14947 x 27) containing measurements collected 
every 5 seconds at several different sampling locations.  If one 
measurement at a given location is less than zero on a given day, I 
would like to delete all measurements from that location on that day.

Here is a toy example:

toy <- data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)), 
SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1)))

In this example, row 9 has a negative measurement for Chamber 5, so I 
would like to delete row 6, which is the same Chamber on the same 
day, but not row 3, which is the same chamber on a different day.  In 
the full dataframe, there are, of course, many more days.

Is there a handy R way to do this?

Thank you for the assistance.

Toby

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


Re: [R] shrout & fleiss ICC´s with varying numbers o f judges

2010-08-12 Thread aleahmad

hi Peter,

There's no single function for ICC with variable number of judges. To
estimate the variances in that case you need hierarchical linear modeling. I
posted code for this at Stackoverflow in answer to your question there:

  http://stackoverflow.com/questions/3205176/

Stats questions get answered rarely on Stackoverflow but you may want to try
the new site focused on statistics:
  http://area51.stackexchange.com/proposals/33/statistical-analysis


hope that helps,
Turadg Aleahmad

-- 
View this message in context: 
http://r.789695.n4.nabble.com/shrout-fleiss-ICC-s-with-varying-numbers-of-judges-tp2257858p2323230.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Error in rowSums

2010-08-12 Thread Peter Ehlers

Another suggestion: compare

 -1:4

with

 -(1:4)


  -Peter Ehlers

On 2010-08-12 12:28, Amit Patel wrote:

Hi

I am trying to calculate the row sums of a matrix i have created
The matrix ( FeaturePresenceMatrix) has been created by

1) Read csv
2) Removing unnecesarry data using [-1:4,] command
3) replacing all the NA values with as.numeric(0) and all others with as.numeric
(1)

When I carry out the command

TotalFeature<- rowrowSums(FeaturePresenceMatrix, na.rm = TRUE)

I get the following error.

Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) :
   'x' must be numeric

Any tips onhow I can get round this?

Thanks in Advance
Amit


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


Re: [R] Error in rowSums

2010-08-12 Thread TGS
Yes, please do as Erik said in the future but here's one way to do it.

(A <- matrix(data = rnorm(n = 9, mean = 0, sd = 1), nrow = 3, ncol = 3, byrow = 
FALSE, dimnames = NULL))
matrix(rowSums(A))

On Aug 12, 2010, at 11:28 AM, Amit Patel wrote:

Hi 

I am trying to calculate the row sums of a matrix i have created
The matrix ( FeaturePresenceMatrix) has been created by

1) Read csv
2) Removing unnecesarry data using [-1:4,] command
3) replacing all the NA values with as.numeric(0) and all others with 
as.numeric 
(1)

When I carry out the command

TotalFeature <- rowrowSums(FeaturePresenceMatrix, na.rm = TRUE)

I get the following error. 

Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) : 
 'x' must be numeric

Any tips onhow I can get round this?

Thanks in Advance
Amit





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

2010-08-12 Thread Erik Iverson



Amit Patel wrote:
Hi 


I am trying to calculate the row sums of a matrix i have created
The matrix ( FeaturePresenceMatrix) has been created by

1) Read csv
2) Removing unnecesarry data using [-1:4,] command
3) replacing all the NA values with as.numeric(0) and all others with as.numeric 
(1)


When I carry out the command

TotalFeature <- rowrowSums(FeaturePresenceMatrix, na.rm = TRUE)

I get the following error. 

Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) : 
  'x' must be numeric


Any tips onhow I can get round this?


Yes, follow the posting guide and give the list a reproducible
example. We don't know a critical piece of information,
the class of your data. We know it's *not* numeric though,
which is what it needs to be.  Use ?class, ?str, and
possibly give us a small sample with ?dput. That way, we can
reproduce the error.

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

2010-08-12 Thread Amit Patel
Hi 

I am trying to calculate the row sums of a matrix i have created
The matrix ( FeaturePresenceMatrix) has been created by

1) Read csv
2) Removing unnecesarry data using [-1:4,] command
3) replacing all the NA values with as.numeric(0) and all others with 
as.numeric 
(1)

When I carry out the command

TotalFeature <- rowrowSums(FeaturePresenceMatrix, na.rm = TRUE)

I get the following error. 

Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) : 
  'x' must be numeric

Any tips onhow I can get round this?

Thanks in Advance
Amit





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


Re: [R] drawing dot plots with size, shape affecting dot characteristics

2010-08-12 Thread Hadley Wickham
On Wed, Aug 11, 2010 at 10:14 PM, Brian Tsai  wrote:
> Hi all,
>
> I'm interested in doing a dot plot where *both* the size and color (more
> specifically, shade of grey) change with the associated value.
>
> I've found examples online for ggplot2 where you can scale the size of the
> dot with a value:
>
> http://had.co.nz/ggplot2/graphics/6a053f23cf5bdfe5155ab53d345a5e0b.png
>
> Or scale the color with the value:
>
> http://had.co.nz/ggplot2/graphics/b17bf93530ff6695afb366e65677c17f.png
>
> both of which are from here:
> http://had.co.nz/ggplot2/geom_point.html
>
> but I've been playing around with ggplot2 and couldn't figure out how to do
> both at the same time - ideally i want size to increase with a value, and
> the shade of grey to get lighter with increasing value.

qplot(mpg, wt, data = mtcars, colour = qsec, size = qsec) + scale_colour_grey()

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] rpart package

2010-08-12 Thread Erik Iverson



Olga Shaganova wrote:

Hi,

I am a brand new user and may be my question is too simple. I have R on
our (not Unix) server. I am trying to build a decision tree and the error
message says "couldn't find function rpart". Does it mean I have to ask our
server guy to install an additional package?


You have to load the "rpart" package

> library(rpart)

If that succeeds, you should have the rpart function available. I think
rpart is a recommended package, so you should be OK.

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


Re: [R] multicore mclapply error

2010-08-12 Thread Jarrett Byrnes
Ah.  Indeed, this is from the glmulti.  I had not realized there would be 
problems using Java.  Is there a way around this to still use a multicore 
approach?  For what other packages that use multiple cores will this not be a 
problem?

-Jarrett

On Aug 12, 2010, at 11:02 AM, Thomas Lumley wrote:

> On Thu, 12 Aug 2010, Jarrett Byrnes wrote:
> 
>> I'm running r 2. on a mac running 10.6.4 and a dual-core macbook pro.  I'm 
>> having a funny time with multicore.  When I run it with 2 cores, mclapply, R 
>> borks with the following error.
>> 
>> The process has forked and you cannot use this CoreFoundation functionality 
>> safely. You MUST exec().
>> Break on 
>> __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__()
>>  to debug.
>> 
>> 
>> If, however, I crank the # of cores back to 1, it runs just fine.
>> 
>> The code looks as follows:
>> 
>> 
>> mmi_fits<-mclapply(responses, function(a_response){
>>  gmult<-glmulti(glm(make_formula(a_response, sp), 
>> data=df, family=binomial))
>>  return(gmult)
>>  },
>>  mc.cores=2)
> 
> You don't say what glmulti() is. If you mean the function from glmulti 
> package, that package uses Java and rjava, and it wouldn't be altogether 
> surprising if the connection to Java or the Java environment reacted badly to 
> being forked.
> 
>   -thomas
> 
> Thomas Lumley
> Professor of Biostatistics
> University of Washington, Seattle
> 

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


Re: [R] Creating vectors

2010-08-12 Thread JesperHybel

You can use following scriptI think



#create a vector of random numbers on which to test script

v<-sample(1:3,size=90,replace=TRUE)

#creates two matrixes out of vector v which can be assigned to M to test
script
M2<-matrix(v,ncol=2)
M3<-matrix(v,ncol=3)

M<-   #Assign you're matrix or a testmatrix to M and run script



result<-numeric()
imaks<-length(M[,1])
jmaks<-length(unique(M)[,1])

for (i in 1:imaks){

for (j in 1:jmaks){
if (sum(M[i,]==unique(M)[j,])==length(M[1,]))  {
result[i]<-j
}
}
}

result




## The script uses loops so its not efficient - in other words its slow and
might be too slow for larger matrixes.

BR

Jesper




-- 
View this message in context: 
http://r.789695.n4.nabble.com/Creating-vectors-tp2321440p2323090.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Creating vectors

2010-08-12 Thread clips10

I think your code will work but only for the two columns I gave. I used those
as an example but my actual data is 200 in length with two columns and I
need code that will give a label to each unique pair but still have the
original length for instance, one that will turn  something such as 

  [,1]   [,2]
[1,] 12
[2,] 23
[3,] 12
[4,] 46
[5,] 23  1

into one vector of length 5, giving a number for each unique pair
(1,2,1,3,4) so that the same pairs get the same number.

but my actual data is of length 200 with two columns

Thanks.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Creating-vectors-tp2321440p2322933.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] rpart package

2010-08-12 Thread Olga Shaganova
Hi,

I am a brand new user and may be my question is too simple. I have R on
our (not Unix) server. I am trying to build a decision tree and the error
message says "couldn't find function rpart". Does it mean I have to ask our
server guy to install an additional package?

Thank you,
Olga

[[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] multicore mclapply error

2010-08-12 Thread Thomas Lumley

On Thu, 12 Aug 2010, Jarrett Byrnes wrote:


I'm running r 2. on a mac running 10.6.4 and a dual-core macbook pro.  I'm 
having a funny time with multicore.  When I run it with 2 cores, mclapply, R 
borks with the following error.

The process has forked and you cannot use this CoreFoundation functionality 
safely. You MUST exec().
Break on 
__THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__()
 to debug.


If, however, I crank the # of cores back to 1, it runs just fine.

The code looks as follows:


mmi_fits<-mclapply(responses, function(a_response){
gmult<-glmulti(glm(make_formula(a_response, sp), 
data=df, family=binomial))
return(gmult)
},
mc.cores=2)


You don't say what glmulti() is. If you mean the function from glmulti package, 
that package uses Java and rjava, and it wouldn't be altogether surprising if 
the connection to Java or the Java environment reacted badly to being forked.

   -thomas

Thomas Lumley
Professor of Biostatistics
University of Washington, Seattle

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] reading fixed width format data with 2 types of lines

2010-08-12 Thread Denis Chabot
Hi,

I know how to read fixed width format data with read.fwf, but suddenly I need 
to read in a large number of old fwf files with 2 types of lines. Lines that 
begin with "3" in first column carry one set of variables, and lines that begin 
with "4" carry another set, like this:

…
3A00206546L07004901609004599  1015002  001001008010004002004007003   001
3A00206546L07004900609003099  1029001002001001006014002 
3A00206546L07004900229000499  1015001001
3A00206546L070049001692559049033  1015 018036024
3A00206546L07004900229000499  1001   002
4A00176546L06804709001011100060651640015001001501063   065914   
4A00176546L068047090010111000407616 1092   095614   
4A00196546L098000100010111001706214450151062   065914   
4A00176546L068047090010111000505913 1062   065914   
4A00196546L09800010001011100260472140002001000201042   046114   
4A00196546L0980001000101110025042214501200051042   046114   
4A00196546L09800010001011100290372140005001220501032   036214   
…

I have searched for tricks to do this but I must not have used the right 
keywords, I found nothing.

I suppose I could read the entire file as a single character variable for each 
line, then subset for lines that begin with 3 and save this in an ascii file 
that will then be reopened with a read.fwf call, and do the same with lines 
that begin with 4. But this does not appear to me to be very elegant nor 
efficient… Is there a better method?

Thanks in advance,


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

2010-08-12 Thread Jarrett Byrnes
I'm running r 2. on a mac running 10.6.4 and a dual-core macbook pro.  I'm 
having a funny time with multicore.  When I run it with 2 cores, mclapply, R 
borks with the following error.

The process has forked and you cannot use this CoreFoundation functionality 
safely. You MUST exec().
Break on 
__THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__()
 to debug.


If, however, I crank the # of cores back to 1, it runs just fine.

The code looks as follows:


mmi_fits<-mclapply(responses, function(a_response){
gmult<-glmulti(glm(make_formula(a_response, sp), 
data=df, family=binomial))
return(gmult)
}, 
mc.cores=2)


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


Re: [R] Running something without a loop when the result from the previous iteration is require for the current iteration

2010-08-12 Thread Adrienne Wootten
Thanks everyone for your help and advice.  For the R-help archives, here is
what I ended up doing.

First creating a separate function to handle one day at a time -

byrow.gen2 <- function(genmat,rownum,use1,use2,num,ortho_obs_used){
prev = rownum-1
ran = runif(length(rownum),0,1)
if(genmat[rownum,use1]==0 & genmat[rownum,use2]==0 & genmat[prev,num]==0) {
if(ran wrote:

> Not quite what I was trying to say.  The process generates a random uniform
> number between 0 and 1 and compares to a specific conditional probability.
> It is looking for this in particular:
>
> random number < Pr( rain(station=i,day=d)=1 | rain(station=i,day=d-1)=0 &
> rain(station=j,day=d)=0 & rain(station=k,day=d)=0)
>
> In this particular example, if the random number is less than the
> probability the value for station i and day d will be given as 1, otherwise
> it will be zero.
>
> There are 8 possible combinations.  i is the station to be generated, j and
> k are the two stations most strongly correlated with station i.  Stations j
> and k have already been generated in the example I gave previously.  So I
> want to know given what is going on at stations j and k during day d and at
> station i for day d-1 if the value for station i day d will be 1 or 0.
>
> Hope this provides some clarification.
> A
>
>
> On Thu, Aug 12, 2010 at 3:21 AM, Petr PIKAL wrote:
>
>> Hi
>>
>> without toy example it is rather complicated to check your function. So
>> only few remarks:
>>
>> Instead of generating 1 random number inside a loop generate whole vector
>> of random numbers outside a loop and choose a number
>>
>> Do not mix ifelse with if. ifelse is intended to work with whole vector.
>>
>> Work with matrices instead of data frames whenever possible if speed is an
>> issue.
>>
>> If I understand correctly you want to put 1 or 0 into one column based on:
>>
>> previous value in the same column
>> comparison of some random number with predefined probabilities in vector
>> of 6 values
>>
>> So here is vectorised version of your 4 ifs based on assumption
>>
>> 0 in col1 0 in col 2 = 5
>> 0 in col1 1 in col 2 = 9
>> 1 in col1 0 in col 2 = 6
>> 1 in col1 1 in col 2 =10
>>
>>
>> col1<-sample(1:2, 20, replace=T)
>> col2<-sample(c(4,8), 20, replace=T)
>>
>> col1+col2
>>  [1]  5  6  9  6  6  5  9 10  9  9  6  9 10  6 10  9 10  9  5  5
>> cols<-as.numeric(as.factor(col1+col2))
>>
>> cols
>>  [1] 1 2 3 2 2 1 3 4 3 3 2 3 4 2 4 3 4 3 1 1
>>
>>
>> And here is computed comparison of six values p (ortho obs used) with 20
>> generated random values
>>
>> ran<-runif(20)
>> p<-runif(8)
>> comparison <- outer(ran,p, "<")
>>   [,1]  [,2]  [,3] [,4]  [,5]  [,6]  [,7]  [,8]
>>  [1,] FALSE  TRUE FALSE TRUE  TRUE  TRUE  TRUE  TRUE
>>  [2,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
>>  [3,] FALSE  TRUE FALSE TRUE FALSE  TRUE  TRUE FALSE
>>  [4,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
>>  [5,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
>>  [6,] FALSE  TRUE FALSE TRUE FALSE  TRUE FALSE FALSE
>>  [7,] FALSE  TRUE FALSE TRUE FALSE  TRUE FALSE FALSE
>>  [8,] FALSE  TRUE FALSE TRUE  TRUE  TRUE  TRUE  TRUE
>>  [9,] FALSE  TRUE FALSE TRUE  TRUE  TRUE  TRUE  TRUE
>> [10,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
>> [11,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
>> [12,] FALSE  TRUE FALSE TRUE  TRUE  TRUE  TRUE  TRUE
>> [13,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
>> [14,] FALSE  TRUE FALSE TRUE  TRUE  TRUE  TRUE  TRUE
>> [15,]  TRUE  TRUE  TRUE TRUE  TRUE  TRUE  TRUE  TRUE
>> [16,] FALSE  TRUE FALSE TRUE  TRUE  TRUE  TRUE  TRUE
>> [17,] FALSE  TRUE FALSE TRUE FALSE  TRUE FALSE FALSE
>> [18,] FALSE  TRUE FALSE TRUE  TRUE  TRUE  TRUE  TRUE
>> [19,] FALSE  TRUE FALSE TRUE  TRUE  TRUE  TRUE  TRUE
>> [20,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
>>
>>
>> Now the only what you need to put in loop is to select appropriate column
>> from matrix comparison based on value on cols vector and 0 or 1 in
>> previous row of station column.
>>
>> Something like (untested)
>>
>> gen.log<-rep(NA, nrow(genmat)-1)
>>
>> for (i in 2:nrow(genmat)) {
>>
>> gen.log[i] <- if( genmat[i-1, num] ==0)  comparison[i, cols[i]] else
>> comparison[i,cols[i+5]]
>>
>> }
>>
>> genmat[2:nrow(genmat), num] <- gen.log*1
>>
>> Regards
>> Petr
>>
>>
>> r-help-boun...@r-project.org napsal dne 11.08.2010 18:35:37:
>>
>> > Hello Everyone!
>> >
>> > Here's what I'm trying to do.  I'm working on generating occurrences of
>> > precipitation based upon precipitation occurrence for a station during
>> the
>> > previous day and two stations that have already been generated by joint
>> > probablities and 1st order Markov chains or by the same generation
>> process.
>> > This has to be done for each remaining stations for each month.
>> >
>> > > genmat # 7 stations in this example, line_before is the climatology of
>> the
>> > last day of the previous month. Stations 4 and 6 have been generated
>> already
>> > in this example
>> > [,1] [,2] [,3] [,4] [,5] [,6] [,7]
>> >

Re: [R] help usin scan on large matrix (caveats to what has been discussed before)

2010-08-12 Thread Peter Dalgaard
Martin Tomko wrote:
> Hi Peter,
> apologies, too fast copying and pasting.
> So, here is the explanation:
> f<-"C:/test/mytab.txt";
> R<-readLines(con=f);
> 
> where mytab.txt is a table formatted as noted in previous post (space 
> delimited, with header, rownames, containing integers).
> 
> Now, my understandign of scan was that I have to specify the FULL number 
> of values in it (examples specify things like 200*2000 for a matrix 
> etc). That's why I thought that I need to do cols*rows as well. Avoiding 
> the first line with headers is simple, avoiding the first column is not 
> - hence my questions.
> Sorry, the corrected, matching parentheses are here - why did the 
> previous execute is a wonder...
> c<-scan(file=f,what=rep(c(list(NULL),rep(list(0L),cols-1)),rows-1), skip=1)
> here, my reasoning was:
> 
> * c(list(NULL),rep(list(0L),cols-1)) specifies a template for any line 
> (first elelement to be ignored => NULL, it is a string in the table 
> specified, and then a repetition of integers - I am still not sure how 
> you derived 0L, and what it means and where to find a doc for that.);
> * the previous needs to be repeated rows-1 times, hence 
> what=rep(c(list(NULL),rep(list(0L),cols-1)),rows-1)
> 
> I do nto understand the following:
> 
>   You need an unlist(c). And more than likely NOT byrow=TRUE. However, I 
> think do.call(cbind,c) should do the trick more easily.
> 
> what will unlist(c) do; why should it not be bywrow=TRUE, and how would 
> you go about integrating do.call(cbind,c) with matrix. Apologies to 
> naive questions, I am a newbie, in principle.
> 

At this point I think you need to actually try my suggestions, and maybe
read the documentation again. Explaining how you have misunderstood the
documentation is not going to help...

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@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 install: documentation

2010-08-12 Thread Duncan Murdoch

On 12/08/2010 12:10 PM, Tim Gruene wrote:

Hello,

when I ran "R CMD INSTALL circular_0.4.tar.gz" on a machine with Debian stable,
the command also created the documentation in various fomrats (latex, html,
online).

The same command on Debian testing only provides the online documentation.

How can I persuade R to create the different formats also on Debian testing?
  


Install an obsolete version of R.  By default current versions only 
install one format, and generate the others on request.


Duncan Murdoch

Both machines have texinfo installed.

Cheers, Tim

  



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

2010-08-12 Thread Duncan Murdoch

On 12/08/2010 10:35 AM, szisziszilvi wrote:

I've tried lm, but something is wrong.
I've made a test dataset of 599 data points, my original equation is

zz = 1 +0.5*xx -3.2*xx*xx -1*yy +4.2*yy*yy

but the R gives this result:
---
> mp <- read.csv(file="sample.csv",sep=";",header=TRUE)
> lm(zz ~ poly(xx,2) + poly(yy,2), data=mp)

Call:
lm(formula = zz ~ poly(xx, 2) + poly(yy, 2), data = mp)

Coefficients:
 (Intercept)  poly(xx, 2)1  poly(xx, 2)2  poly(yy, 2)1  poly(yy, 2)2  
   25.86  -2239.86   -595.01   2875.54776.84

---
which is definitely not the original. :(



I don't think you are interpreting the coefficients properly.  The basis 
functions are orthogonal polynomials, not xx and xx^2, so the 
coefficients won't match the ones you used in your definition.  You 
should compare the predictions of the model, e.g. by looking at


range(predict(lm(zz ~ poly(xx,2) + poly(yy,2), data=mp)) - zz)

If you insist on the power basis, just fit the model as

lm(zz ~ xx + I(xx^2) + yy + I(yy^2), data=mp)

but you might get less accurate predictions due to increased collinearity.

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] R install: documentation

2010-08-12 Thread Tim Gruene
Hello,

when I ran "R CMD INSTALL circular_0.4.tar.gz" on a machine with Debian stable,
the command also created the documentation in various fomrats (latex, html,
online).

The same command on Debian testing only provides the online documentation.

How can I persuade R to create the different formats also on Debian testing?

Both machines have texinfo installed.

Cheers, Tim

-- 
--
Tim Gruene
Institut fuer anorganische Chemie
Tammannstr. 4
D-37077 Goettingen

GPG Key ID = A46BEE1A



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


Re: [R] Regression Error: Otherwise good variable causes singularity. Why?

2010-08-12 Thread asdir

@JLucke:
As for the africa variable: I took it out of the model, so that we can
exclude this variable itself and collinearity between the africa and the
litrate variable as causes for the litrate-problem.  This also removed the
singularity remark at the top. However, the problem with litrate-variable
seen as many factors remains.

Just to clarify: The second results table is fictional to explain where I
was headed with my regression.

Anyway, thanks for the quick answer.

@David:
Thanks for the pointer. It was in fact a bad variable, but I created it
myself. I changed the set halfway in between my calculations and thought I
had adjusted everything. It turns out, that I forgot to adjust the
set-length which is re-set in between the two steps of my Heckman-procedure.
In any case: Thanks for the quick and helpful reply. :-)
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Regression-Error-Otherwise-good-variable-causes-singularity-Why-tp2322780p2322925.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] Where the data file is stored?

2010-08-12 Thread Barry Rowlingson
On Thu, Aug 12, 2010 at 4:51 PM, Stephen Liu  wrote:
> Hi Barry,
>
>
> Following 2 commands are useful to me;
>> row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir))
> showing directories.
>
>> row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),!isdir))
> showing files
>
>
> What is "!" for?  TIA

 It means 'not'. So TRUE becomes FALSE and FALSE becomes TRUE. And NA stays NA.

 Use it when you need to invert logical values.

Barry

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


Re: [R] Where the data file is stored?

2010-08-12 Thread David Winsemius


On Aug 12, 2010, at 11:51 AM, Stephen Liu wrote:


Hi Barry,


Following 2 commands are useful to me;

row
.names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir))

showing directories.

row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),! 
isdir))

showing files


What is "!" for?  TIA


?"!"

(learn to use R help facilities!)




B.R.
Stephen L




- Original Message 
From: Barry Rowlingson 
To: Stephen Liu 
Cc: r-help@r-project.org
Sent: Thu, August 12, 2010 8:05:10 PM
Subject: Re: [R] Where the data file is stored?

On Thu, Aug 12, 2010 at 12:37 PM, Stephen Liu   
wrote:

- Original Message 

From: Alain Guillet 
To: Stephen Liu 
Cc: r-help@r-project.org
Sent: Thu, August 12, 2010 5:28:32 PM
Subject: Re: [R] Where the data file is stored?

You can find your current working directory with the getwd()  
function.



Hi Alain,


Thanks for your advice.



getwd()

[1] "/home/userA"



list.files(getwd())

[1] "Desktop"   "Documents" "Downloads"
[4] "examples.desktop"  "last-packages.txt" "Music"
[7] "myR"   "petdrug.csv"   "Pictures"
[10] "Public""R" "Templates"
[13] "Videos"



list.files(getwd(),full.name=TRUE)

[1] "/home/userA/Desktop"
[2] "/home/userA/Documents"
[3] "/home/userA/Downloads"
[4] "/home/userA/examples.desktop"
[5] "/home/userA/last-packages.txt"
[6] "/home/userA/Music"
[7] "/home/userA/myR"
[8] "/home/userA/petdrug.csv"
[9] "/home/userA/Pictures"
[10] "/home/userA/Public"
[11] "/home/userA/R"
[12] "/home/userA/Templates"
[13] "/home/userA/Videos"


How to show on the printout which is directory?  TIA


Use file.info and check the $isdir part of the returned data frame.
For example, to get names of only directories in your working dir, do:

row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir))

a quick modification gets you not-directories (which will be plain
files plus special files):

row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),! 
isdir))


see ?file.info and ?files

Barry




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


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] Median abline how-to ?

2010-08-12 Thread David martin

thanks !!!
On 12/08/10 17:49, William Dunlap wrote:

segments(x0=ix-w, x1=ix+w, y0=mediansByGroup, col=ix)



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] XML file from scratch using XML package

2010-08-12 Thread Mark Heckmann
I would like to build an XML file from scratch using the XML package.
I would like to save the following vector in it:

1:10

Could someone help me by briefly outlining how I go about it ?
And maybe provide a few lines of code?

Thanks!

Mark
–––
Mark Heckmann
Dipl. Wirt.-Ing. cand. Psych.
Vorstraße 93 B01
28359 Bremen
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com





[[alternative HTML version deleted]]

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


Re: [R] Where the data file is stored?

2010-08-12 Thread Stephen Liu
Hi Barry,


Following 2 commands are useful to me;
> row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir))
showing directories.

> row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),!isdir))
showing files


What is "!" for?  TIA


B.R.
Stephen L




- Original Message 
From: Barry Rowlingson 
To: Stephen Liu 
Cc: r-help@r-project.org
Sent: Thu, August 12, 2010 8:05:10 PM
Subject: Re: [R] Where the data file is stored?

On Thu, Aug 12, 2010 at 12:37 PM, Stephen Liu  wrote:
> - Original Message 
>
> From: Alain Guillet 
> To: Stephen Liu 
> Cc: r-help@r-project.org
> Sent: Thu, August 12, 2010 5:28:32 PM
> Subject: Re: [R] Where the data file is stored?
>
>> You can find your current working directory with the getwd() function.
>
>
> Hi Alain,
>
>
> Thanks for your advice.
>
>
>> getwd()
> [1] "/home/userA"
>
>
>> list.files(getwd())
>  [1] "Desktop"   "Documents" "Downloads"
>  [4] "examples.desktop"  "last-packages.txt" "Music"
>  [7] "myR"   "petdrug.csv"   "Pictures"
> [10] "Public""R" "Templates"
> [13] "Videos"
>
>
>> list.files(getwd(),full.name=TRUE)
>  [1] "/home/userA/Desktop"
>  [2] "/home/userA/Documents"
>  [3] "/home/userA/Downloads"
>  [4] "/home/userA/examples.desktop"
>  [5] "/home/userA/last-packages.txt"
>  [6] "/home/userA/Music"
>  [7] "/home/userA/myR"
>  [8] "/home/userA/petdrug.csv"
>  [9] "/home/userA/Pictures"
> [10] "/home/userA/Public"
> [11] "/home/userA/R"
> [12] "/home/userA/Templates"
> [13] "/home/userA/Videos"
>
>
> How to show on the printout which is directory?  TIA

Use file.info and check the $isdir part of the returned data frame.
For example, to get names of only directories in your working dir, do:

row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir))

a quick modification gets you not-directories (which will be plain
files plus special files):

row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),!isdir))

see ?file.info and ?files

Barry




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


Re: [R] Median abline how-to ?

2010-08-12 Thread William Dunlap
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of David martin
> Sent: Thursday, August 12, 2010 7:42 AM
> To: r-h...@stat.math.ethz.ch
> Subject: [R] Median abline how-to ?
> 
> Hi,
> I'm newbie with R and don't really know how to add a median 
> line to each 
> of the groups that is not all the plot long.
> 
> Here is a small working code that i have adapted for my purpose. If 
> somebody could tell me how to draw median lines on each group and not 
> all plot long.
> 
>   ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
>   trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
>   group <- gl(2,10,20, labels=c("Ctl","Trt"))
> weight <- c(ctl, trt)
> 
> ctlmed <- median(weight[which(group == "Ctl")])
> trtmed <- median(weight[which(group == "Trt")])
> plot.default(weight ~ group,axes=F)
>   axis(2,col.axis = "blue",las=1,cex.axis=0.7,xpd=TRUE)
>   axis(1, 
> labels=levels(group),at=1:length(unique(group)),las=2,cex.axis=0.7) 

You can use segments(), along with par("cxy"), which gives
the size of a typical plotting character in user units.  E.g.,
  w <- par("cxy")[1] * 1.5 # width of pch times 1.5, half-width of
median line
  ix <- seq_len(nlevels(group))
  mediansByGroup <- tapply(weight, group, median)
  segments(x0=ix-w, x1=ix+w, y0=mediansByGroup, col=ix)


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> -Original Message-
> #horizontal
> abline(h = ctlmed, col = "blue", lwd = 2) # ?? how to make 
> abline shorter ?
> abline(h = trtmed, col = "red", lwd = 2)
> box(bty="c")
> 
> ps: At this stage the boxplot is not interesting for me.
> thanks,
> david
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] normality tests

2010-08-12 Thread Bert Gunter
?RsiteSearch

or consult package sos.

Learn how to use R's search resources!

-- 
Bert Gunter
Genentech Nonclinical Statistics

On Wed, Aug 11, 2010 at 8:21 PM, Geoffrey Smith  wrote:
> Hello, does anyone know how to compute the following two normality tests
> using R:
>
> (1) the Kiefer-Salmon (1983) statistic, Economics Letters 11, p. 123-127
> (2) the modified Shapiro-Wilk statistic?
>
> Thank you very much.  Geoff
>
>        [[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] Creating vectors

2010-08-12 Thread TGS
I think I understand your question and the following would produce the result 
you've posted.

(x <- matrix(c(1, 2, 2, 3, 1, 2, 1, 2, 3, 4), nrow=5, byrow=TRUE))

On Aug 12, 2010, at 5:41 AM, clips10 wrote:


Thanks for the help,

I tried to apply this to a vector with two columns, well I suppose it is not
a vector but for instance like this:

   [,1]  [,2]
[1,]1  2
[2,]2  3
[3,]1  2
[4,]1  2
[5,]3 4

and return a vector :

1,2,1,1,3, so that it recognises both columns together.

I tried match(x, unique(x)) as earlier suggested but this returns a vector
of length 10 as opposed to 5, even though unique(x) does remove the repeated
rows.
Sorry if this is confusing, I am trying to do as originally posted but with
2 columns

Thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Creating-vectors-tp2321440p2322646.html
Sent from the R help mailing list archive at Nabble.com.

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

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


Re: [R] Where the data file is stored?

2010-08-12 Thread Stephen Liu

> You're not seeing the .Rdata file containing the data objects. Try:

> list.files(getwd(),full.name=TRUE, all.files=TRUE)


Hi Keith,

Thanks for your advice

On R console running
> list.files(getwd(),full.name=TRUE,all.files=TRUE)



The output is similar to running following command on Ubuntu terminal;

> ls -al /home/userA/


Except the latter showing which are files and which are directories


B.R.
satimis




- Original Message 
From: Keith Jewell 
To: r-h...@stat.math.ethz.ch
Sent: Thu, August 12, 2010 8:47:03 PM
Subject: Re: [R] Where the data file is stored?

You're not seeing the .Rdata file containing the data objects. Try:

list.files(getwd(),full.name=TRUE, all.files=TRUE)


"Stephen Liu"  wrote in message 
news:961426.85478...@web113203.mail.gq1.yahoo.com...
- Original Message 

From: Alain Guillet 
To: Stephen Liu 
Cc: r-help@r-project.org
Sent: Thu, August 12, 2010 5:28:32 PM
Subject: Re: [R] Where the data file is stored?

> You can find your current working directory with the getwd() function.


Hi Alain,


Thanks for your advice.


> getwd()
[1] "/home/userA"


> list.files(getwd())
[1] "Desktop"   "Documents" "Downloads"
[4] "examples.desktop"  "last-packages.txt" "Music"
[7] "myR"   "petdrug.csv"   "Pictures"
[10] "Public""R" "Templates"
[13] "Videos"


> list.files(getwd(),full.name=TRUE)
[1] "/home/userA/Desktop"
[2] "/home/userA/Documents"
[3] "/home/userA/Downloads"
[4] "/home/userA/examples.desktop"
[5] "/home/userA/last-packages.txt"
[6] "/home/userA/Music"
[7] "/home/userA/myR"
[8] "/home/userA/petdrug.csv"
[9] "/home/userA/Pictures"
[10] "/home/userA/Public"
[11] "/home/userA/R"
[12] "/home/userA/Templates"
[13] "/home/userA/Videos"


How to show on the printout which is directory?  TIA

B.R.
Stephen L


On 12-Aug-10 11:22, Stephen Liu wrote:
> - Original Message 
>
> From: Philipp Pagel
> To: r-help@r-project.org
> Sent: Thu, August 12, 2010 3:54:53 PM
> Subject: Re: [R] Where the data file is stored?
>
>> You dont't tell us what you did to "create a datafile" - to me it
>> sounds like you created an object (probably a data frame) in your R
>> workspace. If that's  the case it is stored in a file called .RData in
>> your current work directory (together with other variables in your
>> workspace). If that is not what you did please give us mre
>> information.
>
> Hi Philipp,
>
> Yes, it is "data frame".
>
> I have run the step
> write.csv ...
>
> Other advice noted.  Thanks
>
>
> B.R.
> Stephen L
>
>
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Alain Guillet
Statistician and Computer Scientist

SMCS - IMMAQ - Université catholique de Louvain
Bureau c.316
Voie du Roman Pays, 20
B-1348 Louvain-la-Neuve
Belgium

tel: +32 10 47 30 50

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Regression Error: Otherwise good variable causes singularity. Why?

2010-08-12 Thread David Winsemius


On Aug 12, 2010, at 10:35 AM, asdir wrote:



This command


cdmoutcome<- glm(log(value)~factor(year)

 +log(gdppcpppconst)+log(gdppcpppconstAII)
 +log(co2eemisspc)+log(co2eemisspcAII)
 +log(dist)
 +fdiboth
 +odapartnertohost
 +corrupt
 +log(infraindex)
 +litrate
 +africa
 +imr
, data=cdmdata2, subset=zero==1, gaussian(link =
"identity"))


results in this table


Coefficients: (1 not defined because of singularities)

   Estimate Std. Error t value Pr(>|t|)
(Intercept)1.216e+01  5.771e+01   0.211   0.8332
factor(year)2006  -1.403e+00  5.777e-01  -2.429   0.0157 *
factor(year)2007  -2.799e-01  7.901e-01  -0.354   0.7234
log(gdppcpppconst) 2.762e-01  5.517e+00   0.050   0.9601
log(gdppcpppconstAII) -1.344e-01  9.025e-01  -0.149   0.8817
log(co2eemisspc)   5.655e+00  2.903e+00   1.948   0.0523 .
log(co2eemisspcAII)   -1.411e-01  4.245e-01  -0.332   0.7399
log(dist) -2.938e-01  4.023e-01  -0.730   0.4658
fdiboth1.326e-04  1.133e-04   1.171   0.2425
odapartnertohost   2.319e-03  1.437e-03   1.613   0.1078
corrupt1.875e+00  3.313e+00   0.566   0.5718
log(infraindex)4.783e+00  1.091e+01   0.438   0.6615


You have probably created litrate as a factor without realizing it.  
That can easily happen if you just use read.table and one of the  
values cannot be gracefully interpreted as a numeric. Either read in  
with stringsAsFactors=FALSE or asIs=TRUE and then coerce it to  
numeric. or if you want to fix an existing factor f%^&-up,  then the  
FAQ tells you to use something like:
cdmdata2$f_ed_variable <-  
as.numeric(as.character(cdmdata2$f_ed_variable)




litrate0.47   -2.485e+01  3.190e+01  -0.779   0.4365
litrate0.499  -1.657e+01  2.591e+01  -0.639   0.5230
litrate0.523  -2.440e+01  3.427e+01  -0.712   0.4769
litrate0.528  -9.184e+00  1.379e+01  -0.666   0.5060
litrate0.595  -2.309e+01  2.776e+01  -0.832   0.4062
litrate0.66   -1.451e+01  2.734e+01  -0.531   0.5961
litrate0.675  -1.707e+01  2.813e+01  -0.607   0.5444
litrate0.68   -6.346e+00  1.063e+01  -0.597   0.5509
litrate0.699   2.717e+00  3.541e+00   0.768   0.4434
litrate0.706  -1.960e+01  2.933e+01  -0.668   0.5046
litrate0.714  -2.586e+01  4.002e+01  -0.646   0.5186
litrate0.736   5.641e+00  1.561e+01   0.361   0.7181
litrate0.743  -2.692e+01  4.253e+01  -0.633   0.5273
litrate0.762  -2.208e+01  3.100e+01  -0.712   0.4767
litrate0.802  -2.325e+01  3.766e+01  -0.617   0.5375
litrate0.847  -2.620e+01  3.948e+01  -0.664   0.5075
litrate0.86   -3.576e+01  4.950e+01  -0.722   0.4707
litrate0.864  -4.482e+01  6.274e+01  -0.714   0.4755
litrate0.872  -1.946e+01  2.715e+01  -0.717   0.4739
litrate0.877  -2.710e+01  3.702e+01  -0.732   0.4646
litrate0.879  -3.460e+01  5.147e+01  -0.672   0.5020
litrate0.886  -3.276e+01  4.860e+01  -0.674   0.5008
litrate0.889  -4.120e+01  5.755e+01  -0.716   0.4746
litrate0.904  -2.282e+01  2.985e+01  -0.764   0.4453
litrate0.91   -3.478e+01  5.037e+01  -0.691   0.4904
litrate0.923  -1.762e+01  2.551e+01  -0.691   0.4902
litrate0.925  -2.445e+01  3.611e+01  -0.677   0.4990
litrate0.926  -2.995e+01  4.565e+01  -0.656   0.5123
litrate0.928  -2.839e+01  3.933e+01  -0.722   0.4710
litrate0.937  -2.571e+01  3.795e+01  -0.677   0.4986
litrate0.94   -2.109e+01  3.051e+01  -0.691   0.4900
litrate0.959  -2.078e+01  2.895e+01  -0.718   0.4735
litrate0.96   -3.403e+01  4.798e+01  -0.709   0.4787
litrate0.962  -4.084e+01  5.755e+01  -0.710   0.4785
litrate0.971  -3.743e+01  5.247e+01  -0.713   0.4761
litrate0.98   -3.709e+01  5.170e+01  -0.717   0.4737
litrate0.986  -2.663e+01  4.437e+01  -0.600   0.5488
litrate0.991  -3.045e+01  4.166e+01  -0.731   0.4654
litrate1  -2.732e+01  4.459e+01  -0.613   0.5405
africaNA NA  NA   NA
imr2.160e+00  9.357e-01   2.309   0.0216 *


although it should result in something similar to this:


Coefficients: (1 not defined because of singularities)

   Estimate Std. Error t value Pr(>|t|)
(Intercept)1.216e+01  5.771e+01   0.211   0.8332
factor(year)2006  -1.403e+00  5.777e-01  -2.429   0.0157 *
factor(year)2007  -2.799e-01  7.901e-01  -0.354   0.7234
log(gdppcpppconst) 2.762e-01  5.517e+00   0.050   0.9601
log(gdppcpppconstAII) -1.344e-01  9.025e-01  -0.149   0.8817
log(co2eemisspc)   5.655e+00  2.903e+00   1.948   0.0523 .
log(co2eemisspcAII)   -1.411e-01  4.245e-01  -0.332   0.7399
log(dist) -2.938e-01  4.023e-01  -0.730   0.4658
fdiboth 

[R] Median abline how-to ?

2010-08-12 Thread David martin

Hi,
I'm newbie with R and don't really know how to add a median line to each 
of the groups that is not all the plot long.


Here is a small working code that i have adapted for my purpose. If 
somebody could tell me how to draw median lines on each group and not 
all plot long.


 ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
 trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
 group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)

ctlmed <- median(weight[which(group == "Ctl")])
trtmed <- median(weight[which(group == "Trt")])
plot.default(weight ~ group,axes=F)
 axis(2,col.axis = "blue",las=1,cex.axis=0.7,xpd=TRUE)
 axis(1, 
labels=levels(group),at=1:length(unique(group)),las=2,cex.axis=0.7) 
#horizontal

abline(h = ctlmed, col = "blue", lwd = 2) # ?? how to make abline shorter ?
abline(h = trtmed, col = "red", lwd = 2)
box(bty="c")

ps: At this stage the boxplot is not interesting for me.
thanks,
david

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

2010-08-12 Thread JesperHybel

I have a simple dataset of a numerical dependent Y, a numerical independent X
and a categorial variable Z with three levels. I want to do linear
regression Y~X for each level of Z. How can I do this in a single command
that is without using lm() applied three isolated times?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Linear-regression-on-several-groups-tp2322835p2322835.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] non-linear regression for 3D data

2010-08-12 Thread szisziszilvi

right. How does it come that if I devide the result vector with
10*interception, I get a much better result?

> zz2 <- 25.86 -2239.86*mp$xx -595.01*mp$xx*mp$xx + 2875.54*mp$yy +
> 776.84*mp$yy*mp$yy
> mp$zz2 <- zz2
> library(lattice)
> cloud(zz2/258.6 + zz ~ xx * yy, data=mp)


looks quite pretty.

http://r.789695.n4.nabble.com/file/n2322812/output.jpeg 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/non-linear-regression-for-3D-data-tp2320982p2322812.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] Error: evaluation nested too deeply

2010-08-12 Thread abotaha

Hi guys, 
I have a code in R and it was work well but when I decrease the epsilon
value (indicated in the code) , then I am getting this error
Error: evaluation nested too deeply: infinite recursion /
options(expressions=)? 
any help please 


y = 6.8; 
w = 7.4;
z = 5.7;
muy = 7; 
muw = 7; 
muz = 6; 
sigmay = 0.8; 
sigmaz = 0.76; 
sigmaw = 0.3;
betayx = 0.03; 
betayz = 0.3; 
betayw = 0.67

s = c(3.2,0.8)

em = function(W,s) {
a= 1/2*(1/s[2]^2+betayx^2/sigmay^2); 
b=
(y-muy+betayx*s[1]-betayz*(z-muz)-betayw*(w-muw))*betayx/sigmay^2+s[1]/s[2]^2; 
c=(1/2)*((y-muy+betayx*s[1]-betayz*(z-muz)-betayw*(w-muw))*betayx/sigmay^2+s[1]/s[2]^2)^2/(1/s[2]^2+betayx^2/sigmay^2);
V = exp(-c+b^2/(4*a))/sqrt(pi/(1/(2*s[2]^2)+(1/2)*betayx^2/sigmay^2)); 
Omega = V*sqrt(pi/a);

A = 4*a^2*Omega*betayx^2/sigmay^2; 
B = 4*a^2; 
C = 2*a*b*Omega; 
d =
(2*a*b*Omega*betayx^2/sigmay^2)-(4*a^2*Omega*(y-muy-betayz*(z-muz)-betayw*(w-muw))*betayx/sigmay^2);
E = 2*a*Omega+b^2*Omega;
lambda = A*B; 
alpha = 2*A*C+d*B; 
delta = A*E+B^2+2*d*C; 
eta = C*B+d*E;
s[1]=(1/6)*(-36*delta*alpha*lambda+108*eta*lambda^2+8*alpha^3+12*sqrt(3)*sqrt(4*delta^3*lambda-delta^2*alpha^2-18*delta*alpha*lambda*eta+27*eta^2*lambda^2+4*eta*alpha^3)*lambda)^(1/3)/lambda+(2/3)*(-3*delta*lambda+alpha^2)/(lambda*(-36*delta*alpha*lambda+108*eta*lambda^2+8*alpha^3+12*sqrt(3)*sqrt(4*delta^3*lambda-delta^2*alpha^2-18*delta*alpha*lambda*eta+27*eta^2*lambda^2+4*eta*alpha^3)*lambda)^(1/3))+(1/3)*alpha/lambda;
s[2]=sqrt((B*s[1]^2-2*C*s[1]+E)/B);
 s
 }
epsilon =0.0005
iter = function(W, s) {
 s1 = em(W,s)
 for (i in 1:2) {
 if (abs(s[i]-s1[i]) > epsilon) {
 s=s1
 iter(W,s)
 }
 else s1
 }
 s1
 }

iter(W,s)

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Error-evaluation-nested-too-deeply-tp2322701p2322701.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] non-linear regression for 3D data

2010-08-12 Thread szisziszilvi

I've tried lm, but something is wrong.
I've made a test dataset of 599 data points, my original equation is

zz = 1 +0.5*xx -3.2*xx*xx -1*yy +4.2*yy*yy

but the R gives this result:
---
> mp <- read.csv(file="sample.csv",sep=";",header=TRUE)
> lm(zz ~ poly(xx,2) + poly(yy,2), data=mp)

Call:
lm(formula = zz ~ poly(xx, 2) + poly(yy, 2), data = mp)

Coefficients:
 (Intercept)  poly(xx, 2)1  poly(xx, 2)2  poly(yy, 2)1  poly(yy, 2)2  
   25.86  -2239.86   -595.01   2875.54776.84
---
which is definitely not the original. :(

(In case of interest the test dataset is available here:
szisziszilvi.lima-city.de/r)
-- 
View this message in context: 
http://r.789695.n4.nabble.com/non-linear-regression-for-3D-data-tp2320982p2322779.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Creating vectors

2010-08-12 Thread clips10

Thanks for the help,

I tried to apply this to a vector with two columns, well I suppose it is not
a vector but for instance like this:

[,1]  [,2]
[1,]1  2
[2,]2  3
[3,]1  2
[4,]1  2
[5,]3 4

and return a vector :

1,2,1,1,3, so that it recognises both columns together.

I tried match(x, unique(x)) as earlier suggested but this returns a vector
of length 10 as opposed to 5, even though unique(x) does remove the repeated
rows.
Sorry if this is confusing, I am trying to do as originally posted but with
2 columns

Thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Creating-vectors-tp2321440p2322646.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] help to polish plot in ggplot2

2010-08-12 Thread Mahbubul Majumder
baptiste,

I have two more questions. How can I get the category labels right
justified? It seems that I need to change the size of the text too. Since in
my real data the text size are big and they appears to be even bigger than
my plot area. So, my second question is how can I change the text size?

Thanks again for your help.

On Thu, Aug 12, 2010 at 8:02 AM, baptiste Auguié <
baptiste.aug...@googlemail.com> wrote:

> you just need to remove the rectGrob() from ylab, as in
>
> ylab <- gTree(children=gList(my.labels), cl="mylabels" )
>
> baptiste
>
> On Aug 12, 2010, at 2:59 PM, Mahbubul Majumder wrote:
>
> > baptiste,
> >
> > This is exactly what I wanted. Many thanks for this. I have one problem
> though. How can I get rid of the boundary box of y axis title?
> >
> >
> > On Thu, Aug 12, 2010 at 2:47 AM, baptiste auguie <
> baptiste.aug...@googlemail.com> wrote:
> > To illustrate the second option I proposed,
> >
> > library(ggplot2)
> > library(gridExtra)
> >
> > category <- paste("Geographical Category", 1:10)
> >
> > grp1 <- rnorm(10, mean=10, sd=10)
> > grp2 <- rnorm(10, mean=20, sd=10)
> > grp3 <- rnorm(10, mean=15, sd=10)
> > grp4 <- rnorm(10, mean=12, sd=10)
> >
> > mydat <- data.frame(category,grp1,grp2,grp3,grp4)
> >
> > dat.m <- melt(mydat)
> >
> > p <- qplot(1,value, data=dat.m, geom="bar",  xlab="",ylab="Percentage of
> eco
> > change",stat="identity",fill=variable, position="dodge") +
> > coord_flip()+ facet_grid(category ~ .,
> > space="free")+scale_x_discrete(breaks=c(2,4))+opts(strip.text.y =
> > theme_text(hjust = 0))
> >
> > labs <- llply(category, textGrob)
> >
> > ## add a blank grob below as the y title is aligned with the full
> > ggplot2 height,
> > ## not just the panel
> > my.labels <- do.call(arrangeGrob, c(labs, list(ncol=1, left="My y
> > title", sub=" ")))
> > # grid.draw(my.labels)
> >
> > ## hack: define the width of my.labels
> > ylab <- gTree(children=gList(my.labels, rectGrob()), cl="mylabels" )
> >
> > widthDetails.mylabels <- function(x)
> >  max(stringWidth(category)) + unit(1, "line")
> >
> > ## hack: tweak ggplot2's axis.title.y option to use our gTree
> > foo <- function()
> >  function(label, x, y)
> >  ylab
> >
> > p + opts(strip.text.y =theme_blank(),
> > strip.background=theme_blank()) +
> > opts(  axis.title.y = foo())
> >
> > HTH,
> >
> > baptiste
> >
> >
> > On 12 August 2010 07:44, baptiste auguie 
> wrote:
> > > Hi,
> > >
> > > One way you could do it is to create a separate graph for each
> > > category. The y axis labels would replace the strip labels. You could
> > > then stack the graphs on the page, and add a common legend. The tricky
> > > part would be to make sure the different panels have the same width
> > > and height.
> > >
> > > Another option might be to hack a custom Grob (gTree) for the y-axis
> > > title so that it would draw the current y-axis title and also the
> > > labels for the facets next to it. Of course you'd also get rid of the
> > > strips in this case.
> > >
> > > Best,
> > >
> > > baptiste
> > >
> > >
> > >
> > > On 11 August 2010 15:39, Mahbubul Majumder  wrote:
> > >> Hi,
> > >>
> > >> I wanted to generate a plot which is almost like the plot generated by
> the
> > >> following codes.
> > >>
> > >> category <- paste("Geographical Category", 1:10)
> > >> grp1 <- rnorm(10, mean=10, sd=10)
> > >> grp2 <- rnorm(10, mean=20, sd=10)
> > >> grp3 <- rnorm(10, mean=15, sd=10)
> > >> grp4 <- rnorm(10, mean=12, sd=10)
> > >>
> > >> mydat <- data.frame(category,grp1,grp2,grp3,grp4)
> > >>
> > >> dat.m <- melt(mydat)
> > >>
> > >> p <- qplot(1,value, data=dat.m, geom="bar",  xlab="",ylab="Percentage
> of eco
> > >> change",stat="identity",fill=variable, position="dodge")
> > >> p + coord_flip()+ facet_grid(category ~ .,
> > >> space="free")+scale_x_discrete(breaks=c(2,4))+opts(strip.text.y =
> > >> theme_text(hjust = 0))
> > >>
> > >>
> > >> Now the only modification I need from this plot is that I want the
> grid
> > >> labels (text) on the left hand side with right justification and white
> > >> background. My prospective plot should have labels like the the plot
> > >> generated by the codes below. The reason why I don't like the plot
> below is
> > >> that it does not show separate grid for each category.
> > >>
> > >> p <- qplot(category,value, data=dat.m, geom="bar",  ylab="Percentage
> of eco
> > >> change",stat="identity",fill=variable, position="dodge")
> > >> p + coord_flip()
> > >>
> > >> Can you help me generate my vision plot?
> > >>
> > >> --
> > >> Mahbub Majumder
> > >> Graduate Student
> > >> Dept. of Statistics
> > >> Iowa State University
> > >>
> > >>[[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 commente

  1   2   >