Re: [R] summation coding

2012-10-19 Thread Rainer Schuermann
Assuming that you actually mean
a1(b2+b3+b4) + a2(b1+b3+b4) + a3(b1+b2+b4) + a4(b1+b2+b3)
^  ^  ^

this might give you what you want:

x <- data.frame( a = sample( 1:10, 4 ), b = sample( 11:20, 4 ) )
x   
 
  a  b  
   
1 1 16  
   
2 7 15  
   
3 8 19  
   
4 4 13

for( i in 1 : length( x$a ) ) 
x$c[i] <- x$a[i] * ( sum( x$b ) - x$b[i] ) 
x   
 
  a  b   c  
   
1 1 16  47  
   
2 7 15 336  
   
3 8 19 352  
   
4 4 13 200


Rgds,
Rainer


On Thursday 18 October 2012 12:33:39 djbanana wrote:
> I would like to code the following in R: a1(b1+b2+b3) + a2(b1+b3+b4) +
> a3(b1+b2+b4) + a4(b1+b2+b3)
> 
> or in summation notation: sum_{i=1, j\neq i}^{4} a_i * b_i
> 
> I realise this is the same as: sum_{i=1, j=1}^{4} a_i * b_i - sum_{i=j} a_i
> * b_i
> 
> would appreciate some help.
> 
> Thank you.
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/summation-coding-tp4646678.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Memory issue with svm modeling in R

2012-10-19 Thread Vignesh Prajapati
As I found the memory problem with local machine/micro instance(amazon) for
building SVM model in R on large dataset(2,01,478 rows with 11 variables),
then I have migrated our micro instance to large instance at Amazon. Still
I have memory issue with large amazon instance while developing R model for
this dataset due to large size. I have attached the snap of error with
local machine(localmachine_error.bmp) and amazon instance(crash.png ) with
this post.

Issue on local Machine ::

 [image: enter image description here]

Issue on Amazon large Instance ::

[image: enter image description here]

Can any one suggest me for the solution of this issue.?

Thanks

Vignesh

[[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] summation coding

2012-10-19 Thread Rainer Schuermann
You asked for a loop, you got one...

Vectorized is easier and faster:
x$c <- x$a * ( sum( x$b ) - x$b )

Rgds,
Rainer



On Friday 19 October 2012 09:38:35 you wrote:
> Hi,
> 
> I think I solved it myself by writing loops.
> 
> What I meant is: are there in-built functions in R that calculate the
> following:
> 
> a1(b2+...+b190) + a2(b1+b3+...+b190) + ...
> 
> I managed to solve it, quite similar to what you just emailed.
> 
> Thanks!
> 
> On 19 October 2012 09:20, Rainer Schuermann wrote:
> 
> > Is it possible that you mean
> > a1(b2+b3+b4) + a2(b1+b3+b4) + a3(b1+b2+b4) + a4(b1+b2+b3)
> > ^  ^  ^
> >
> >
> > On Thursday 18 October 2012 12:33:39 djbanana wrote:
> > > I would like to code the following in R: a1(b1+b2+b3) + a2(b1+b3+b4) +
> > > a3(b1+b2+b4) + a4(b1+b2+b3)
> > >
> > > or in summation notation: sum_{i=1, j\neq i}^{4} a_i * b_i
> > >
> > > I realise this is the same as: sum_{i=1, j=1}^{4} a_i * b_i - sum_{i=j}
> > a_i
> > > * b_i
> > >
> > > would appreciate some help.
> > >
> > > Thank you.
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > http://r.789695.n4.nabble.com/summation-coding-tp4646678.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] summation coding

2012-10-19 Thread Berend Hasselman

On 18-10-2012, at 21:33, djbanana wrote:

> I would like to code the following in R: a1(b1+b2+b3) + a2(b1+b3+b4) +
> a3(b1+b2+b4) + a4(b1+b2+b3)
> 
> or in summation notation: sum_{i=1, j\neq i}^{4} a_i * b_i
> 
> I realise this is the same as: sum_{i=1, j=1}^{4} a_i * b_i - sum_{i=j} a_i
> * b_i
> 

This is partly TeX notation not summation notation, whatever that may be.
And these "sums" make no sense: where is index j used in the first? where is it 
used in the second?

Solutions starting from you explicit formula, from slowest to fastest

sum( outer(a,b,"*") ) - sum(a*b)
sum(sapply(1:length(a),function(k) a[k]*sum(b[-k])))
sum(convolve(a,b)) - sum(a*b)   # sum(convolve(a,rev(b), type="o")) - sum(a*b)

Berend


> would appreciate some help.
> 
> Thank you.
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/summation-coding-tp4646678.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] summation coding

2012-10-19 Thread Berend Hasselman

On 19-10-2012, at 10:38, Berend Hasselman wrote:

> 
> On 18-10-2012, at 21:33, djbanana wrote:
> 
>> I would like to code the following in R: a1(b1+b2+b3) + a2(b1+b3+b4) +
>> a3(b1+b2+b4) + a4(b1+b2+b3)
>> 
>> or in summation notation: sum_{i=1, j\neq i}^{4} a_i * b_i
>> 
>> I realise this is the same as: sum_{i=1, j=1}^{4} a_i * b_i - sum_{i=j} a_i
>> * b_i
>> 
> 
> This is partly TeX notation not summation notation, whatever that may be.
> And these "sums" make no sense: where is index j used in the first? where is 
> it used in the second?
> 
> Solutions starting from you explicit formula, from slowest to fastest
> 
> sum( outer(a,b,"*") ) - sum(a*b)
> sum(sapply(1:length(a),function(k) a[k]*sum(b[-k])))
> sum(convolve(a,b)) - sum(a*b)   # sum(convolve(a,rev(b), type="o")) - sum(a*b)
> 

And from Nabble another solution (not posted to the R-help list (yet?) ) which 
turns out to be the quickest (obviously)

sum(a*(sum(b)-b)) 

Berend

> Berend
> 
> 
>> would appreciate some help.
>> 
>> Thank you.
>> 
>> 
>> 
>> --
>> View this message in context: 
>> http://r.789695.n4.nabble.com/summation-coding-tp4646678.html
>> Sent from the R help mailing list archive at Nabble.com.
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] likelihood function involving integration, error in nlm

2012-10-19 Thread Berend Hasselman

On 19-10-2012, at 04:40, stats12 wrote:

> Dear R users,
> 
> I am trying to find the mle that involves integration. 
> 
> I am using the following code and get an error when I use the nlm function
> 
> d<-matrix(c(1,1,0,0,0,0,0,0,2,1,0,0,1,1,0,1,2,2,1,0),nrow=10,ncol=2)
> h<-matrix(runif(20,0,1),10)
> 
> integ<-matrix(c(0),nrow=10, ncol=2)
> ll<-function(p){
> for (k in 1:2){
> for(s in 1:10){
> integrand<-function(x)
> x^d[s,k]*exp(-x*gamma(1+1/p))^p*p*x^(p-1)*exp(-x*h[s,k]) 
> integ[s,k]<-integrate(integrand,0,Inf)$value
> }
> }
> lik<-colSums(integ)
> -lik
> }
> initial<-c(1)
> t<-nlm(ll,initial)
> Error in nlm(ll, initial) : invalid function value in 'nlm' optimizer

Before the call of nlm you should insert

ll(initial)

to check. You'll see that your function returns a vector and not a scalar as it 
should.
I guess that ll() should return sum(-lik) or better -sum(integ)

Berend

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] grid(Base): How to avoid "Figure region too small and/or viewport too large" by specifying 'relative' units?

2012-10-19 Thread Marius Hofert
Dear grid-expeRts,

The goal: 
I would like to construct a plot (matrix) with grid and gridBase,
which consists of four "sub-plots". The sub-plots should have a square plotting
region as one would force with par(pty="s") in base graphics.

The problem: 
I don't get a square plotting region, not even by specifying
pty="s" in par(). Indeed, if you display the grid layout by commenting in
"grid.show.layout(gl)" below, you'll see that the grid layout is fine, but the
plot does not seem to respect the layout measurements.

The initial quick-and-dirty hack: 
Use absolute measurements, i.e., specify all
units in inches. This worked perfectly fine for me initially. However, when the
device width and height are not set accordingly (and one can never know what
others specify here -- indeed the problem arose this way), this produces errors
of type "Error in gridPLT() : Figure region too small and/or viewport too
large".

I also found this issue in this post
(https://stat.ethz.ch/pipermail/r-help/2008-December/181993.html), but I am
wondering what's the correct approach towards this problem / how can one specify
"relative" units but guarantee that the grid layout is respected when plotting
is done? [We use this plot in a quite complicated setup and the quick solution
to specify inches and a large enough width/height for the device fails.]


Cheers,

Marius


require(grid)
require(gridBase)

## setup
strg <- LETTERS[1:2] # row variables
t <- c(0.2, 0.8) # column variables

## plot variables (spaces)
pspc <- c(3,3)
spc <- c(0.3, 0.3)
axlabspc <- c(1.2, 0.75)
labspc <- c(0.3, 0.3)

## save plot settings
par. <- par(no.readonly=TRUE)

## set up the grid layout
nx <- 2 # number of sub-plots per column
nx. <- 5 # number of grid rectangles per column
ny <- 2 # number of sub-plots per row
ny. <- 5 # number of grid rectangles per row
plot.new() # start (empty) new page with 'graphics'
gl <- grid.layout(nx., ny., # "2 x 2" grid together with spaces => 5 x 5 grid
  widths=c(axlabspc[1], rep(c(pspc[1], spc[1]), nx-1), pspc[1], 
labspc[1]),
  heights=c(labspc[2], rep(c(pspc[2], spc[2]), ny-1), pspc[2], 
axlabspc[2]))
## grid.show.layout(gl) # display the layout; use this to see that the 
sub-plots do not match the layout specification
pushViewport(viewport(layout=gl)) # use this layout in a viewport

## generate dummy data to plot in the four sub-plots
n <- 10
x <- array(NA, dim=c(nx, ny, n))
for(i in 1:2) for(j in 1:2) x[i,j,] <- rep(i,n)+rep(j,n)+runif(n)

## go through the "panels"
set.seed(1)
for(i in 1:nx) { # rows
i. <- 2*i # column index in layout (for jumping over gaps)
yran <- range(x[i,,]) # for forcing the same y-axis within a row
for(j in 1:ny) { # columns
j. <- 2*j # row index in layout (for jumping over gaps)
pushViewport(viewport(layout.pos.row=i., layout.pos.col=j.))

## plot
par(plt=gridPLT()) # start a 'graphics' plot
par(new=TRUE) # always do this before each new 'graphics' plot
plot(range(1:n), yran, type="n", ann=FALSE, axes=FALSE) # set up 
coordinate axes
points(1:n, x[i,j,], type="b") # actual plot
grid.rect()

## axes
if(i==nx) axis(1) # x axis
if(j==1) axis(2) # y axes
upViewport()

## column labels
if(i==1){
pushViewport(viewport(layout.pos.row=1, layout.pos.col=j.))
grid.rect()
grid.text(t[j], x=0.5, y=0.5)
upViewport()
}

## row labels
if(j==2){
pushViewport(viewport(layout.pos.row=i., layout.pos.col=nx.))
grid.rect()
grid.text(strg[i], x=0.5, y=0.5, rot=-90)
upViewport()
}
}
}

## x axis label
pushViewport(viewport(layout.pos.row=ny., layout.pos.col=2:(ny.-1)))
grid.text(expression(gamma), y=unit(0.5, "null"))
upViewport()

## y axis label
pushViewport(viewport(layout.pos.row=2:(nx.-1), layout.pos.col=1))
grid.text(expression(f[gamma]), rot=90, x=unit(0.5, "null"))
upViewport()

## restore plot settings
par(par.)

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


Re: [R] Keep loop running after webpage times out?

2012-10-19 Thread R. Michael Weylandt
?tryCatch()

Michael

On Thursday, October 18, 2012, Cess wrote:

> Hi
> I have created a loop to obtain data from several webpages
> but the loop keeps crashing with the error
> "Error in function (type, msg, asError = TRUE)  :
>   Operation timed out after 5000 milliseconds with 9196 bytes received"
>
>   Page = getURLContent(page[i], followlocation=TRUE, curl =
> curl,.opts=list(
> verbose = TRUE, timeout=5))
>
>   I am not sure how to keep the loop running after that error, so any help
> would be appreciated
> ps: I have played with the timeout option but it eventually crashes..
> Thanks
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Keep-loop-running-after-webpage-times-out-tp4646689.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] Post Hoc tests for ANOVA

2012-10-19 Thread Amartya
Hi,

I was trying to figure out how to do  post-hoc tests for Two Way ANOVAs and
found the following 2 approaches:

a. Do pairwise t-tests (bonferroni corrected) if one finds significance with
the ANOVA.
Link-
http://rtutorialseries.blogspot.com/2011/01/r-tutorial-series-two-way-anova-with.html

b. Do TukeyHSD  on an aov model 
Link-
http://www.r-bloggers.com/post-hoc-pairwise-comparisons-of-two-way-anova/

Running the data set given in the first example in SPSS gives significant
pairwise difference for Treatment and Age (Treatmen and Age were the
independent variables) , while using the directions given in the first link
didn't give me significant pairwise different for Treatment (only gave for
Age). 

I have a few questions:

a. Is the first method completely incorrect as hinted in the second link? 
b. What is the right way to do Bonferroni corrected post hoc tests for Two
Way ANOVA in R? 
c. Does anyone know how post hoc tests for SPSS work in the case of Two Way
ANOVAs (Univariate analysis)? Especially for Bonferroni corrected tests.

I am new to R, so please let me know if I made a mistake in framing the
question; I will try to elucidate as much as I personally can. Thanks for
your help.





--
View this message in context: 
http://r.789695.n4.nabble.com/Post-Hoc-tests-for-ANOVA-tp4646710.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] quantile regression using copulas

2012-10-19 Thread indu jaya
Hi all,

Has anyone used the qua.regressCOP2 function from the copBasic package???
The default copula function used in this function is plackett copula and I
wanted to use archimedean copula. Attached below is my code:

mycop<-frankCopula
V=seq(0.001,0.99,by=0.000217)
R<-qua.regressCOP2(0.25,V,cop=mycop,para=c(3.504))

And this is the error I get:
Warning messages:
1: In qua.regressCOP2(0.25, V, cop = mycop, para = c(3.504)) :
  could not uniroot in derCOPinv2, skipping sample for i=4558 having
V=0.989869
2: In qua.regressCOP2(0.25, V, cop = mycop, para = c(3.504)) : 3.504


Would really appreciate if anyone could tell me what is causing the problem
and
how I should solve it.

indu

[[alternative HTML version deleted]]

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


[R] Question about survdiff in for-loop.

2012-10-19 Thread Sando

Hi everyone!!

I have dataset composed of a numbers of survival analyses. 
( for batch survival analyses by using for-loop) . 
Here are code !!

###
dim(svsv)
Num_t<-dim(svsv)
Num<-Num_t[2]   # These are predictors !!

names=colnames(svsv)

for (i in 1:Num  )
{
name_tt=names[i]
survdiff(Surv(survival.m, survival) ~ names[i], data=svsv)
fit.Group<-survfit(Surv(survival.m, survival) ~ names[i] , data=svsv)
plot(fit.Group, col=2:1, xlab="Survival", ylab="Prob")
}

#

names[i] is not working in the survdiff. 
According to help R , the predictor must be single subset. 

And, names[i] is also single character, I think. 

But, it do NOT work. 

How I can solve this problem ? 



Thank you. 

 




--
View this message in context: 
http://r.789695.n4.nabble.com/Question-about-survdiff-in-for-loop-tp4646707.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] summation coding

2012-10-19 Thread djbanana
Hi,

I think I solved it myself by writing loops.

What I meant is: are there in-built functions in R that calculate the
following:

a1(b2+...+b190) + a2(b1+b3+...+b190) + ...
 
I managed to solve it, quite similar to what you just emailed.

Thanks anyway!



--
View this message in context: 
http://r.789695.n4.nabble.com/summation-coding-tp4646678p4646712.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] impute multilevel data in MICE

2012-10-19 Thread ya
 Dear list,

Is there any one use MICE package deal with multilevel missing values here?  I 
have a question about the 2lonly.pmm() and 2lonly.norm(), I get the following 
error quite often. Here is the code the error, could you give me some advice 
please? Am I using it in the right way? 

> ini=mice(bhrm,maxit=0)
> pred=ini$pred
> pred
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18
V1   0  1  1  1  1  1  1  1  1   1   1   1   1   1   1   1   1   0
V2   1  0  1  1  1  1  1  1  1   1   1   1   1   1   1   1   1   0
V3   1  1  0  1  1  1  1  1  1   1   1   1   1   1   1   1   1   0
V4   1  1  1  0  1  1  1  1  1   1   1   1   1   1   1   1   1   0
V5   1  1  1  1  0  1  1  1  1   1   1   1   1   1   1   1   1   0
V6   0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0
V7   0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0
V8   0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0
V9   0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0
V10  0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0
V11  0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0
V12  0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0
V13  0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0
V14  1  1  1  1  1  1  1  1  1   1   1   1   1   0   1   1   1   0
V15  1  1  1  1  1  1  1  1  1   1   1   1   1   1   0   1   1   0
V16  0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0
V17  0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0
V18  0  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0
> for(i in 1:5)pred[i,]=c(rep(0,5),rep(2,8),0,0,-2,1,2)
> imp=mice(bhrm,meth=c(rep("2l.norm",5),rep("",8),rep("2lonly.norm",2),"","",""),pred=pred,maxit=10,print=F)
Error in .imputation.level2(y = y, ry = ry, x = x, type = type, 
imputationMethod = "norm",  : 
  define for 2lonly imputation one and only grouping variable with type=-2
> imp=mice(bhrm,meth=c(rep("2l.norm",5),rep("",8),rep("2lonly.pmm",2),"","",""),pred=pred,maxit=10,print=F)
Error in .imputation.level2(y = y, ry = ry, x = x, type = type, 
imputationMethod = "pmm",  : 
  define for 2lonly imputation one and only grouping variable with type=-2

In this code, V1-V5 are first level variables with missing values, v6-v13 are 
first level random variables without any missing values, v14-v15 are second 
level variables with missing values, v16 is the grouping variable, v17 is the 
fixed effect without any missing values, v18 is the intercept. There are 30 
groups with at least 1 response in the target variable for each group, and more 
than 1000 cases. The data were mainly from the "bhr2000" data set in the 
multilevel package. I made the two second level data myself, the value of them 
ranges from 1 to 3.  My purpose was to impute the v1-v5 and v14-v15. I can 
succeed in imputing the v1-v5 if v14 and v15 were not in the model, but I could 
not impute the missing values in v14 and v15.

Thank you very much.

Best regards,

ya
[[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] R2HTML giving "NULL" in output

2012-10-19 Thread ul_nabble
Had the same prob and did not work out the reason why. However, a workaround
is to add:

.character {
display:none;
}

to the file R2HTML.css or your css file respectively.

Cheers

UL



--
View this message in context: 
http://r.789695.n4.nabble.com/R2HTML-giving-NULL-in-output-tp2309776p4646719.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] to.yearly()

2012-10-19 Thread sheenmaria
v="IBM"
library(quantmod)
v
v1=getSymbols(v)
to.yearly(v1)
===
when i pass the value through a variable in to.yearly() function it shows
the error msg like 
"Error in try.xts(x) : 
  Error in UseMethod("as.xts") :   no applicable method for 'as.xts' applied
to an object of class "character""

i need the result of OHLC value of the ticker .(and i need to pass the
ticker name through a variable name too)
-
anyone can help me . 
Thank you 



--
View this message in context: 
http://r.789695.n4.nabble.com/to-yearly-tp4646723.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] Upper limit in nlsLM not working as expected

2012-10-19 Thread Martin Hehn
Thanks for the reply Berend,

I am aware that I do not have to define the limits to Inf or -Inf, I just did 
this
to make sure all other variables (besides 'w') in 'upper' have no limits.

I can tolerate no upper limit as my peak is fitted well, but my actual data is 
a time series where the peak disappears from time to time. Once disappeared, 
the algorithm is still fitting to the noise of the experimental dataset. 

I thought that it would be handy to suppress this by simply specifying a limit 
for how wide I allow the peak to be as it becomes very broad when fitting to 
noise. Any ideas on how to avoid fitting to the noise?

Regards 

From: Berend Hasselman [b...@xs4all.nl]
Sent: 18 October 2012 17:45
To: Martin Hehn
Cc: r-help@R-project.org
Subject: Re: [R] Upper limit in nlsLM not working as expected

On 18-10-2012, at 14:16, Martin Hehn wrote:

> Dear all,
>
> I am using the nlsLM function to fit a Lorentzian function to my experimental 
> data.
> The LM algorithm should allow to specify limits, but the upper limit appears 
> not to work as expected in my code.
> The parameter 'w', which is peak width at half maximuim always hits the upper 
> limit if the limit is specified. I would expect the value to be in-between 
> the upper and lower limit with maybe hitting either limit occasionally.
>
> The code below calculates a lorentzian curve with some noise added that looks 
> like a typical experimental spectrum. Then a fit is made to this data. Note 
> that if 'w' in the upper limit is set to e.g 0.6, 0.7, or 0.8 the fit always 
> hits this limit. If 'w'=Inf, the fit calculates to something around 0.06, 
> which is correct.
>
> Why does the fit go wrong if 'w' is not Inf?
>

The upper limit for 'w' does not need to be set to Inf. It needs to be set high 
enough for LM to 'work'.
If you set the upper limit for 'w' to 10 the algorithm  will also estimate 'w' 
at 0.06..

When you set the upper limit to low values as you have done, you are not giving 
LM enough room to manoeuvre.
If you set trace to TRUE (please don't use F and T) you'll see that 'w' hits 
the upper limit and that it stays there.

Berend


> library(minpack.lm)
> #Create x axis
> x<-seq(from=0.1,to=0.6,by=0.5/150)
> #Simulate a function with noise
> fu<-function(y0,A,w,xc,x){
>  eq<-y0 + 2*A/pi*w/(4*(x-xc)^2+w^2)
>  eq<-jitter(eq,factor=200)
>  }
> #Evaluate function aka Measured data
> y<-fu(0,0.01,0.06,0.23,x)
> data<-as.data.frame(cbind(x,y))
>
> #Start values for fitting
> st2<-data.frame(
>  y0=0,
>  A=0.0001,
>  w=0.055,
>  xc=0.28
> )
> #Fit function to data
> fit<-nlsLM(y ~ y0 + 2*(A/pi)*w/(4*(x-xc)^2+w^2),
>control=nls.lm.control(
>  factor=100,
>  maxiter=1024,
>  ftol = .Machine$double.eps,
>  ptol = .Machine$double.eps
>),
>data=data,
>na.action=na.exclude,
>start=st2,
>algorith='LM',
>lower=c(-0.0001,-1e-8,0.05,0.2),
>#upper=c(1e-6,0.003,0.08,0.35),
>upper=c(Inf,Inf,0.07,Inf),
>trace=F
> )
> #Predict fitting values
> fity<-predict(fit,data$x)
>
> plot(data$x,data$y)
> lines(data$x,fity,col=2)
> text(0.4,0.08,coef(fit)['y0'])
> text(0.4,0.07,coef(fit)['A'])
> text(0.4,0.06,coef(fit)['w'])
> text(0.4,0.05,coef(fit)['xc'])
>
> Best regard
> Martin
>
>   [[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] to.yearly()

2012-10-19 Thread R. Michael Weylandt
Take a look at ?getSymbols which does not returne te time series by
default.

You want either

to.yearly(IBM)

or

v1 = getSymbols(v, auto.assign = FALSE)
to.yearly(v1)

Michael

On Friday, October 19, 2012, sheenmaria wrote:

> v="IBM"
> library(quantmod)
> v
> v1=getSymbols(v)
> to.yearly(v1)
> ===
> when i pass the value through a variable in to.yearly() function it shows
> the error msg like
> "Error in try.xts(x) :
>   Error in UseMethod("as.xts") :   no applicable method for 'as.xts'
> applied
> to an object of class "character""
>
> i need the result of OHLC value of the ticker .(and i need to pass the
> ticker name through a variable name too)
>
> -
> anyone can help me .
> Thank you
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/to-yearly-tp4646723.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org  mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Mapping

2012-10-19 Thread Duncan Murdoch

On 12-10-18 6:11 PM, dorothy borowy wrote:

I am a new user of R and am crunching through the system.  I have reached an 
impasse with mapping; I want to make a bubble map and lay it over a grid that  
is composed of a standard x,y axis.  Within this, are 16 (4x4) gridded blocks, 
numbered 1-16.  And, within these individual hectares(1-16) it is further 
subdivided into individual x,y plots ( in accordance with the overall x,y 
axes).  I have a general idea of how to make the bubble map but the background 
map is giving me a lot if trouble...HELP


You might get help on this if it rings a bell with someone, but you'll 
probably do better to post some simplified code that does something 
close to what you want, and explain what changes you don't know how to 
do.  It's easier to help to modify something than to write it from scratch.


Duncan Murdoch

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


Re: [R] looping survdiff?

2012-10-19 Thread Andrews, Chris
> sapply(seq(4,ncol(dat)), function(i) 
> survdiff(Surv(time,completion=="2")~dat[,i], data=dat, 
> subset=group=="3")$chisq)
[1] 0.0944 4.4854 3.4990

Chris

-Original Message-
From: Charles Determan Jr [mailto:deter...@umn.edu] 
Sent: Thursday, October 18, 2012 3:04 PM
To: r-help@r-project.org
Subject: [R] looping survdiff?

Hello,

I am trying to set up a loop that can run the survdiff function with the 
ultimate goal to generate a csv file with the p-values reported.  However, 
whenever I try a loop I get an error such as "invalid type (list) for variable 
'survival_data_variables[i]".

This is a subset of my data:

structure(list(time = c(1.516667, 72, 72, 25.78333, 72, 72, 72, 
72, 72, 72, 1.18, 0.883, 1.15, 0.867, 72, 
1.03, 72, 1.05, 72, 22.76667), group = c(2L, 1L, 3L, 3L, 
3L, 4L, 4L, 1L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 4L, 3L, 4L, 3L, 4L), completion = 
structure(c(2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 
2L, 1L, 2L), .Label = c("1", "2"), class = "factor"), var1 = structure(c(2L, 
2L, 3L, 1L, 1L, 3L, 1L, 1L, 1L, 3L, 2L, 2L, 4L, 3L, 2L, 4L, 2L, 4L, 2L, 4L), 
.Label = c("1", "2", "3", "4"), class = "factor"),
var2 = structure(c(3L, 3L, 1L, 1L, 2L, 4L, 3L,
3L, 2L, 4L, 2L, 1L, 2L, 1L, 2L, 2L, 4L, 4L, 2L, 3L), .Label = c("1",
"2", "3", "4"), class = "factor"), var3 = structure(c(4L,
2L, 3L, 1L, 3L, 4L, 4L, 2L, 2L, 4L, 2L, 2L, 1L, 2L, 2L, 2L,
1L, 3L, 4L, 1L), .Label = c("1", "2", "3", "4"), class = "factor")), .Names 
= c("time", "group", "completion", "var1", "var2", "var3"), row.names = c(NA, 
20L), class = "data.frame")


The loop I have been trying for just group 3 is:

d=data.frame()
for(i in 4:6){
a=assign(paste("p-value",i,sep=""),
survdiff(Surv(time, completion=="2")~dat[i],
data=dat[group=="3",],
rho=0))
b=as.matrix(a$chisq)
d=rbind(d, b)
write.csv(d, file="C:/.../junk.csv", quote=FALSE)}

Perhaps I am making this more difficult than it needs to be.  Thanks for any 
help,

Charles

[[alternative HTML version deleted]]


**
Electronic Mail is not secure, may not be read every day, and should not be 
used for urgent or sensitive issues 

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

2012-10-19 Thread Rui Barradas

Hello,

You should give a reproducible example showing us what you have tried, 
with an example dataset.

Try the following.

# A graph I've just drawn
v <- c(1,2,1,3,1,4,2,5,2,4,3,5,3,6,5,7,5,8,5,10,6,8,6,10,7,8,7,9,8,9)
g <- graph(v, directed = FALSE)
plot(g, layout=layout.fruchterman.reingold)
E(g)$weight <- 1:15

# This is what you want
E(g)[5 %--% 10]$weight


See the help for

?igraph::iterators


Hope this helps,

Rui Barradas
Em 18-10-2012 23:05, dha...@mit.edu escreveu:

I'm new to R and igraph and I was wondering if anybody can help me with the
following.

I want to find the edge weight between two vertices in a graph. My graph
structure is defined by the normal ego (node1), alter (node2) and the weight
of the edge between them.

I know that I can get the weight for each of the edges in the list of edges
that originate from node number 5 using E(igraph_friendship) [ from(5)
]$weight And that I can find the weight for each of the edges in the list of
edges that end onto node number 10 using E(igraph_friendship) [ to(10)
]$weight

But what if I simply want to find the weight of the edge that simple
connects just node 5 and node 10?

Alternatively, if I can get the identifier of the edge that connects node 5
and 10 in the list of all edges, E(igraph_friendship), that would work too.

Thanks a lot for your help, I've been looking around a lot for it and I
really appreciate your help!



--
View this message in context: 
http://r.789695.n4.nabble.com/help-finding-edge-connecting-two-nodes-tp4646688.html
Sent from the R help mailing list archive at Nabble.com.

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


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


[R] Which packages are incompatible with 64-bit R?

2012-10-19 Thread Alexander Shenkin
Hi folks, 

Despite the pain of migrating to 64-bit R (I have to install 64-bit Office also 
due to RODBC), I'm considering making the leap due to memory issues. Is there 
any place that lists packages that are 64-bit incompatible? Or, will I just 
have to march through all my packages and check them one-by-one on CRAN?

Thanks,
Allie



[[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] Which packages are incompatible with 64-bit R?

2012-10-19 Thread Duncan Murdoch

On 19/10/2012 8:10 AM, Alexander Shenkin wrote:

Hi folks,

Despite the pain of migrating to 64-bit R (I have to install 64-bit Office also 
due to RODBC), I'm considering making the leap due to memory issues. Is there 
any place that lists packages that are 64-bit incompatible? Or, will I just 
have to march through all my packages and check them one-by-one on CRAN?


An approximation to that is to call 
available.packages(type="win.binary") on both versions, and compare the 
lists.  Packages may fail to appear for reasons other than 
incompatibility, but incompatible packages won't be available in binary 
versions.


Duncan Murdoch

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


Re: [R] Assessing overdispersion and using quasi model with lmer, possible?

2012-10-19 Thread Ben Bolker
swertie  voila.fr> writes:

> I am trying to model data on species abundance (count data) with a poisson
> error distribution. I have a fixed and a random variables and thus needs a
> mixed model. I strongly doubt that my model is overdispersed but I don't
> know how to get the overdispersion parameter in a mixed model. Maybe someone
> can help me on this point. Secondly, it seems that quasi models cannot be
> implemented with the function lmer, is there an option? If not, I certainly
> should go to variable transformation and use a gaussian error distribution,
> but it is not optimal.

  You should read the section in http://glmm.wikidot.com/faq on
overdispersion, and address further questions to the
r-sig-mixed-models  r-project.org mailing list ...

  Ben Bolker

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


Re: [R] speeding read.table

2012-10-19 Thread Gabor Grothendieck
On Thu, Oct 18, 2012 at 10:14 AM, Fisher Dennis  wrote:
> Jason
>
> Are you suggesting grep in R or grep in the system?  If the latter, this 
> won't work because I need to implement this same procedure in Windows (sorry 
> about not mentioning this), in which grep does not exist.  If in R, the 
> syntax is not obvious -- could you provide an example?
>

Windows does have find and findstr which are similar to grep.

   if (.Platform$OS.type == "windows") # use findstr
   else # use grep

>From the Windows console (not from the R console):

  help findstr


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

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


Re: [R] Upper limit in nlsLM not working as expected

2012-10-19 Thread nashjc


I think this might be what you want.  Kate Mullen and I have been in
correspondence over some edge cases where minpack.LM may not handle bounds
appropriately. However, though nlmrt seems to do the job here, readers
should note that R benefits hugely if we maintain some friendly
competition (and collaboration) to both offer methods with different
performance profiles (e.g., handling different classes/sizes of problems
better) and in
helping to root out bugs. So I want minpack.LM to be there for comparison
and use when itdoes a better job. It should, for example, be much faster.
nlmrt is designed to be aggressive and also modifiable, so that the
algorithm can be explored.

John Nash


library(nlmrt)
#Fit function to data
fitn<-nlxb(y ~ y0 + 2*(A/pi)*w/(4*(x-xc)^2+w^2),
control=nls.lm.control(
  factor=100,
  maxiter=1024,
  ftol = .Machine$double.eps,
  ptol = .Machine$double.eps
),
data=data,
na.action=na.exclude,
start=st2,
algorith='LM',
lower=c(-0.0001,-1e-8,0.05,0.2),
#upper=c(1e-6,0.003,0.08,0.35),
upper=c(Inf,Inf,0.07,Inf),
trace=F
)
# > str(fitn)
# List of 6
#  $ resid   : num [1:151] 0.00265 0.00124 -0.00222 -0.00239 0.00148 ...
#  $ jacobian: num [1:151, 1:4] 1 1 1 1 1 1 1 1 1 1 ...
#   ..- attr(*, "dimnames")=List of 2
#   .. ..$ : NULL
#   .. ..$ : chr [1:4] "y0" "A" "w" "xc"
#  $ feval   : num 24
#  $ jeval   : num 16
#  $ coeffs  : num [1:4] 0.00014 0.0099 0.05939 0.22975
#  $ ssquares: num 0.000857




On 10/19/2012 06:00 AM, r-help-requ...@r-project.org wrote:
> Message: 11
> Date: Thu, 18 Oct 2012 12:16:17 +
> From: Martin Hehn 
> To: "r-help@R-project.org" 
> Subject: [R] Upper limit in nlsLM not working as expected
> Message-ID:
>   <17f41a7342eeb6409bda31c3acdbac1005a...@mbxp07.ds.man.ac.uk>
> Content-Type: text/plain
>
> Dear all,
>
> I am using the nlsLM function to fit a Lorentzian function to my
experimental data.
> The LM algorithm should allow to specify limits, but the upper limit
appears not to work as expected in my code.
> The parameter 'w', which is peak width at half maximuim always hits the
upper limit if the limit is specified. I would expect the value to be
in-between the upper and lower limit with maybe hitting either limit
occasionally.
>
> The code below calculates a lorentzian curve with some noise added that
looks like a typical experimental spectrum. Then a fit is made to this
data. Note that if 'w' in the upper limit is set to e.g 0.6, 0.7, or 0.8
the fit always hits this limit. If 'w'=Inf, the fit calculates to
something around 0.06, which is correct.
>
> Why does the fit go wrong if 'w' is not Inf?
>
> library(minpack.lm)
> #Create x axis
> x<-seq(from=0.1,to=0.6,by=0.5/150)
> #Simulate a function with noise
> fu<-function(y0,A,w,xc,x){
>   eq<-y0 + 2*A/pi*w/(4*(x-xc)^2+w^2)
>   eq<-jitter(eq,factor=200)
>   }
> #Evaluate function aka Measured data
> y<-fu(0,0.01,0.06,0.23,x)
> data<-as.data.frame(cbind(x,y))
>
> #Start values for fitting
> st2<-data.frame(
>   y0=0,
>   A=0.0001,
>   w=0.055,
>   xc=0.28
> )
> #Fit function to data
> fit<-nlsLM(y ~ y0 + 2*(A/pi)*w/(4*(x-xc)^2+w^2),
> control=nls.lm.control(
>   factor=100,
>   maxiter=1024,
>   ftol = .Machine$double.eps,
>   ptol = .Machine$double.eps
> ),
> data=data,
> na.action=na.exclude,
> start=st2,
> algorith='LM',
> lower=c(-0.0001,-1e-8,0.05,0.2),
> #upper=c(1e-6,0.003,0.08,0.35),
> upper=c(Inf,Inf,0.07,Inf),
> trace=F
> )
> #Predict fitting values
> fity<-predict(fit,data$x)
>
> plot(data$x,data$y)
> lines(data$x,fity,col=2)
> text(0.4,0.08,coef(fit)['y0'])
> text(0.4,0.07,coef(fit)['A'])
> text(0.4,0.06,coef(fit)['w'])
> text(0.4,0.05,coef(fit)['xc'])
>
> Best regard
> Martin

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


Re: [R] Which packages are incompatible with 64-bit R?

2012-10-19 Thread Alexander Shenkin
Thanks Duncan.  Here's what I come up with.  Anything obviously missing?
 I'd think there'd be more incompatibilities than just these few...

In 32-bit: > pkgs32 = available.packages(type="win.binary")
In 64-bit: > pkgs64 = available.packages(type="win.binary")

> pkgnames32 = pkgs32[,"Package"]
> pkgnames64 = pkgs64[,"Package"]

> as.character(pkgnames32[which(is.na(match(pkgnames32, pkgnames64)))])
[1] "RSVGTipsDevice" "RSvgDevice" "eco""rcqp"
"sparsenet"  "hdf5"


On 10/19/2012 8:22 AM, Duncan Murdoch wrote:
> On 19/10/2012 8:10 AM, Alexander Shenkin wrote:
>> Hi folks,
>>
>> Despite the pain of migrating to 64-bit R (I have to install 64-bit
>> Office also due to RODBC), I'm considering making the leap due to
>> memory issues. Is there any place that lists packages that are 64-bit
>> incompatible? Or, will I just have to march through all my packages
>> and check them one-by-one on CRAN?
> 
> An approximation to that is to call
> available.packages(type="win.binary") on both versions, and compare the
> lists.  Packages may fail to appear for reasons other than
> incompatibility, but incompatible packages won't be available in binary
> versions.
> 
> 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] Converting character values to time values when no date information is present XXXX

2012-10-19 Thread Dan Abner
Hi everyone,

I am familiar with using the chron package to work with date/time
values, but what about just time values with no date info present?
What is the best tool to convert character values to time values when
no date info is present?

Thanks!

Dan

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


Re: [R] Converting character values to time values when no date information is present XXXX

2012-10-19 Thread Gabor Grothendieck
On Fri, Oct 19, 2012 at 8:55 AM, Dan Abner  wrote:
> Hi everyone,
>
> I am familiar with using the chron package to work with date/time
> values, but what about just time values with no date info present?
> What is the best tool to convert character values to time values when
> no date info is present?
>

The "times" class in the chron package handles times.

> library(chron)
> times(.5)
[1] 12:00:00
> times(.5) + times("01:00:00")
[1] 13:00:00
> times("01:00:00") + 1
Time in days:
[1] 1.041667


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

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


Re: [R] Looping survdiff

2012-10-19 Thread Terry Therneau

The number of recent questions from umn.edu makes me wonder if there's homework 
involved

Simpler for your example is to use get and subset.
dat <- structure(.as found below
var.to.test <- names(dat)[4:6]   #variables of interest
nvar <- length(var.to.test)
chisq <- double(nvar)
for (i in 1:nvar) {
tfit <- survdiff(Surv(time, completion==2) ~ get(var.to.test[i]), data=dat, 
subset=(group==3))

chisq[i] <- tfit$chisq
}
write.csv(data.frame(var.to.test, chisq))

On 10/19/2012 05:00 AM, r-help-requ...@r-project.org wrote:

Hello,

I am trying to set up a loop that can run the survdiff function with the
ultimate goal to generate a csv file with the p-values reported.  However,
whenever I try a loop I get an error such as "invalid type (list) for
variable 'survival_data_variables[i]".

This is a subset of my data:

structure(list(time = c(1.516667, 72, 72, 25.78333,
72, 72, 72, 72, 72, 72, 1.18, 0.883,
1.15, 0.867, 72, 1.03, 72, 1.05, 72,
22.76667), group = c(2L, 1L, 3L, 3L, 3L, 4L, 4L,
1L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 4L, 3L, 4L, 3L, 4L), completion =
structure(c(2L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L,
2L, 1L, 2L), .Label = c("1", "2"), class = "factor"), var1 =
structure(c(2L,
2L, 3L, 1L, 1L, 3L, 1L, 1L, 1L, 3L, 2L, 2L, 4L, 3L, 2L, 4L, 2L,
4L, 2L, 4L), .Label = c("1", "2", "3", "4"), class = "factor"),
 var2 = structure(c(3L, 3L, 1L, 1L, 2L, 4L, 3L,
 3L, 2L, 4L, 2L, 1L, 2L, 1L, 2L, 2L, 4L, 4L, 2L, 3L), .Label = c("1",
 "2", "3", "4"), class = "factor"), var3 = structure(c(4L,
 2L, 3L, 1L, 3L, 4L, 4L, 2L, 2L, 4L, 2L, 2L, 1L, 2L, 2L, 2L,
 1L, 3L, 4L, 1L), .Label = c("1", "2", "3", "4"), class = "factor")),
.Names = c("time",
"group", "completion", "var1", "var2",
"var3"), row.names = c(NA, 20L), class = "data.frame")


The loop I have been trying for just group 3 is:

d=data.frame()
for(i in 4:6){
 a=assign(paste("p-value",i,sep=""),
 survdiff(Surv(time, completion=="2")~dat[i],
 data=dat[group=="3",],
 rho=0))
 b=as.matrix(a$chisq)
 d=rbind(d, b)
write.csv(d, file="C:/.../junk.csv", quote=FALSE)}

Perhaps I am making this more difficult than it needs to be.  Thanks for
any help,

Charles


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


Re: [R] Looping survdiff

2012-10-19 Thread Charles Determan Jr
Thank you for all your responses, I assure you this is not homework.  I am
a graduate student and my classes are complete.  I am trying multiple
different ways to analyze data and my lab requests different types of
scripts to accomplish various tasks.  I am the most computer savy in the
lab so it comes to me.  I am continually trying to learn more about using R
and I truly value all the suggestions.  Again, thank you for your
assistance,

Regards,
Charles

On Fri, Oct 19, 2012 at 8:30 AM, Terry Therneau  wrote:

> The number of recent questions from umn.edu makes me wonder if there's
> homework involved
>
> Simpler for your example is to use get and subset.
> dat <- structure(.as found below
> var.to.test <- names(dat)[4:6]   #variables of interest
> nvar <- length(var.to.test)
> chisq <- double(nvar)
> for (i in 1:nvar) {
> tfit <- survdiff(Surv(time, completion==2) ~ get(var.to.test[i]),
> data=dat, subset=(group==3))
> chisq[i] <- tfit$chisq
> }
> write.csv(data.frame(var.to.**test, chisq))
>
> On 10/19/2012 05:00 AM, r-help-requ...@r-project.org wrote:
>
>> Hello,
>>
>> I am trying to set up a loop that can run the survdiff function with the
>> ultimate goal to generate a csv file with the p-values reported.  However,
>> whenever I try a loop I get an error such as "invalid type (list) for
>> variable 'survival_data_variables[i]".
>>
>> This is a subset of my data:
>>
>> structure(list(time = c(1.516667, 72, 72, 25.78333,
>> 72, 72, 72, 72, 72, 72, 1.18, 0.883,
>> 1.15, 0.867, 72, 1.03, 72, 1.05, 72,
>> 22.76667), group = c(2L, 1L, 3L, 3L, 3L, 4L, 4L,
>> 1L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 4L, 3L, 4L, 3L, 4L), completion =
>> structure(c(2L,
>> 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L,
>> 2L, 1L, 2L), .Label = c("1", "2"), class = "factor"), var1 =
>> structure(c(2L,
>> 2L, 3L, 1L, 1L, 3L, 1L, 1L, 1L, 3L, 2L, 2L, 4L, 3L, 2L, 4L, 2L,
>> 4L, 2L, 4L), .Label = c("1", "2", "3", "4"), class = "factor"),
>>  var2 = structure(c(3L, 3L, 1L, 1L, 2L, 4L, 3L,
>>  3L, 2L, 4L, 2L, 1L, 2L, 1L, 2L, 2L, 4L, 4L, 2L, 3L), .Label = c("1",
>>  "2", "3", "4"), class = "factor"), var3 = structure(c(4L,
>>  2L, 3L, 1L, 3L, 4L, 4L, 2L, 2L, 4L, 2L, 2L, 1L, 2L, 2L, 2L,
>>  1L, 3L, 4L, 1L), .Label = c("1", "2", "3", "4"), class = "factor")),
>> .Names = c("time",
>> "group", "completion", "var1", "var2",
>> "var3"), row.names = c(NA, 20L), class = "data.frame")
>>
>>
>> The loop I have been trying for just group 3 is:
>>
>> d=data.frame()
>> for(i in 4:6){
>>  a=assign(paste("p-value",i,**sep=""),
>>  survdiff(Surv(time, completion=="2")~dat[i],
>>  data=dat[group=="3",],
>>  rho=0))
>>  b=as.matrix(a$chisq)
>>  d=rbind(d, b)
>> write.csv(d, file="C:/.../junk.csv", quote=FALSE)}
>>
>> Perhaps I am making this more difficult than it needs to be.  Thanks for
>> any help,
>>
>> Charles
>>
>

[[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] Matrix to data.frame with factors

2012-10-19 Thread brunosm
Hi all,

I have a matrix with 100 variables: each variable as a value of 0 or 1.

What i want to do is convert this matrix to a data.frame but convert all the
variables to factors (0 and 1) also.

I know i can do this one variable a time but i have 100 variables...

Any easy way of doing this??

Thanks a lot,

Bruno



--
View this message in context: 
http://r.789695.n4.nabble.com/Matrix-to-data-frame-with-factors-tp4646730.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] bigmemory for dataframes?

2012-10-19 Thread Jan
Hi Allie,

When you are working with the ff package, the counterpart of a data.frame is
called an ffdf (ff data frame). It can handle the types you are talking
about - factor, integer but characters will be stored as factors. So this
means that your data types do not have to be of 1 specific type.
Good luck in trying out the package.

Jan



--
View this message in context: 
http://r.789695.n4.nabble.com/bigmemory-for-dataframes-tp4646680p4646749.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Re-projecting geotiff

2012-10-19 Thread Filoche
Thanks for the head-up Don.

Regards,
Phil



--
View this message in context: 
http://r.789695.n4.nabble.com/Re-projecting-geotiff-tp4646616p4646736.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] replacing rows data.frame

2012-10-19 Thread evelyne
I create a data.frame using :
alloc <- data.frame(matrix(nrow=length(unique(mid2agi$gene)), ncol=8))
colnames(alloc) <- c('agi', 'hit_len', 'q_len', 'identity', 'ratio', 'e',
'ok' ,'gene')
alloc$gene <- unique(mid2agi$gene)

this results in: 
> head(alloc)
 agi hit_len q_len identity   ratio  eok   gene
NA NA NA NA NA NA NA BrChr1g1V4
NA NA NA NA NA NA NA BrChr1g2V4

and I already have a dataframe (mid2agi) containing both integers and
factors.
In my empty dataframe I want to replace rows using:

for (i in (1:nrow(alloc)) ) {
find <- alloc[i,]$gene
submid2agi <- subset(mid2agi, gene %in% find)
max <- which.max(submid2agi$identity * submid2agi$ratio)
if (length(max) > 0){
   *alloc[i,] <- submid2agi[max,]*
   }
}

But my problem is that all values are now interpreted as integers, so my
text in my factors are converted to numbers.
Can anyone provide me with tips on how to solve this?

ouoput:
agi hit_len q_len identity   ratio  e ok   gene
*18296* 344   551   86.919 0.62432 2.1142e-89  *2* BrChr1g1V4

SHOULD be:
 agi hit_len q_len identity   ratio  eok   gene
AT4G38360.2 344   551   86.919 0.62432 2.1142e-89  True BrChr1g1V4

Thanks you..
Evelyne


  



--
View this message in context: 
http://r.789695.n4.nabble.com/replacing-rows-data-frame-tp4646731.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] Egarch (1,1) with Student t distribution in R

2012-10-19 Thread Dheeraj Pandey
Hi
I 'm new to R and wants to implement Egarch (1,1) with Student t distribution 
where I need to plot Std. dev series.
Can you please help/provide me with the syntax/commands or any useful content?

Dheeraj


[[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] Matrix to data.frame with factors

2012-10-19 Thread Rui Barradas

Hello,

Try the following.

x <- matrix(sample(0:1, 12, TRUE), ncol = 4)
y <- data.frame(apply(x, 2, factor))
str(y)

Hope this helps,

Rui Barradas
Em 19-10-2012 12:04, brunosm escreveu:

Hi all,

I have a matrix with 100 variables: each variable as a value of 0 or 1.

What i want to do is convert this matrix to a data.frame but convert all the
variables to factors (0 and 1) also.

I know i can do this one variable a time but i have 100 variables...

Any easy way of doing this??

Thanks a lot,

Bruno



--
View this message in context: 
http://r.789695.n4.nabble.com/Matrix-to-data-frame-with-factors-tp4646730.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] Which packages are incompatible with 64-bit R?

2012-10-19 Thread Duncan Murdoch

On 19/10/2012 8:51 AM, Alexander Shenkin wrote:

Thanks Duncan.  Here's what I come up with.  Anything obviously missing?
  I'd think there'd be more incompatibilities than just these few...


If you are on Windows, packages need to pass tests on both 32 and 64 
bits to make it onto CRAN.  So it's not really such a big surprise after 
all...


But I would check those lists against the packages you already have 
installed, in case those are not on CRAN.


Duncan Murdoch


In 32-bit: > pkgs32 = available.packages(type="win.binary")
In 64-bit: > pkgs64 = available.packages(type="win.binary")

> pkgnames32 = pkgs32[,"Package"]
> pkgnames64 = pkgs64[,"Package"]

> as.character(pkgnames32[which(is.na(match(pkgnames32, pkgnames64)))])
[1] "RSVGTipsDevice" "RSvgDevice" "eco""rcqp"
"sparsenet"  "hdf5"


On 10/19/2012 8:22 AM, Duncan Murdoch wrote:
> On 19/10/2012 8:10 AM, Alexander Shenkin wrote:
>> Hi folks,
>>
>> Despite the pain of migrating to 64-bit R (I have to install 64-bit
>> Office also due to RODBC), I'm considering making the leap due to
>> memory issues. Is there any place that lists packages that are 64-bit
>> incompatible? Or, will I just have to march through all my packages
>> and check them one-by-one on CRAN?
>
> An approximation to that is to call
> available.packages(type="win.binary") on both versions, and compare the
> lists.  Packages may fail to appear for reasons other than
> incompatibility, but incompatible packages won't be available in binary
> versions.
>
> Duncan Murdoch


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


Re: [R] Egarch (1,1) with Student t distribution in R

2012-10-19 Thread John Kerpel
Look at the package rugarch - it's the best.

On Fri, Oct 19, 2012 at 7:52 AM, Dheeraj Pandey <
dheeraj.pan...@thesmartcube.com> wrote:

> Hi
> I 'm new to R and wants to implement Egarch (1,1) with Student t
> distribution where I need to plot Std. dev series.
> Can you please help/provide me with the syntax/commands or any useful
> content?
>
> Dheeraj
>
>
> [[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] Matrix to data.frame with factors

2012-10-19 Thread Bert Gunter
Well, strictly speaking, this is still doing it "one variable at a
time." The interpreted loop is hidden, but it's still happening.

A loop free but clumsier approach is:

y <- data.frame(matrix(as.character(x),nrow = nrow(x)))

## Note also that the original column names will be lost and will have
to be added to the data frame.

It would also not surprise me if for such a small matrix that Rui's
version were faster.

-- Bert

On Fri, Oct 19, 2012 at 7:07 AM, Rui Barradas  wrote:
> Hello,
>
> Try the following.
>
> x <- matrix(sample(0:1, 12, TRUE), ncol = 4)
> y <- data.frame(apply(x, 2, factor))
> str(y)
>
> Hope this helps,
>
> Rui Barradas
> Em 19-10-2012 12:04, brunosm escreveu:
>>
>> Hi all,
>>
>> I have a matrix with 100 variables: each variable as a value of 0 or 1.
>>
>> What i want to do is convert this matrix to a data.frame but convert all
>> the
>> variables to factors (0 and 1) also.
>>
>> I know i can do this one variable a time but i have 100 variables...
>>
>> Any easy way of doing this??
>>
>> Thanks a lot,
>>
>> Bruno
>>
>>
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/Matrix-to-data-frame-with-factors-tp4646730.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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

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


Re: [R] Matrix to data.frame with factors

2012-10-19 Thread peter dalgaard

On Oct 19, 2012, at 16:07 , Rui Barradas wrote:

> Hello,
> 
> Try the following.
> 
> x <- matrix(sample(0:1, 12, TRUE), ncol = 4)
> y <- data.frame(apply(x, 2, factor))
> str(y)
> 
> Hope this helps,

Another way, possibly more easily generalized:

x <- matrix(sample(0:1, 12, TRUE), ncol = 4)
y <- as.data.frame(x)
y[] <- lapply(y, factor, levels=0:1)
str(y)

with extensions like

is01 <- function(x) all(na.omit(x) %in% 0:1)
x <- matrix(sample(0:1, 12, TRUE), ncol = 4)
y <- as.data.frame(x)
ix <- sapply(y, is01)
y[ix] <- lapply(y[ix], factor, levels=0:1, labels=c("n","y"))
str(y)

> 
> Rui Barradas
> Em 19-10-2012 12:04, brunosm escreveu:
>> Hi all,
>> 
>> I have a matrix with 100 variables: each variable as a value of 0 or 1.
>> 
>> What i want to do is convert this matrix to a data.frame but convert all the
>> variables to factors (0 and 1) also.
>> 
>> I know i can do this one variable a time but i have 100 variables...
>> 
>> Any easy way of doing this??
>> 
>> Thanks a lot,
>> 
>> Bruno
>> 
>> 
>> 
>> --
>> View this message in context: 
>> http://r.789695.n4.nabble.com/Matrix-to-data-frame-with-factors-tp4646730.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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] Matrix to data.frame with factors

2012-10-19 Thread brunosm
Thanks a lot!



--
View this message in context: 
http://r.789695.n4.nabble.com/Matrix-to-data-frame-with-factors-tp4646730p4646756.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] For loop with i and j and multiple if statements... help!

2012-10-19 Thread ingaschwabe
Again, thank you all for the replies (and for the free R lesson!) 

You helped me a lot and I very appreciate it. 

I will work my self trough the for and apply section of my R manual again.. 

Thanks,

Bye, inga





--
View this message in context: 
http://r.789695.n4.nabble.com/For-loop-with-i-and-j-and-multiple-if-statements-help-tp4646596p4646751.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] Matrix to data.frame with factors

2012-10-19 Thread brunosm
Obrigado Rui, é isso mesmo ;)



--
View this message in context: 
http://r.789695.n4.nabble.com/Matrix-to-data-frame-with-factors-tp4646730p4646757.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] Axis Breaks with ggplot2

2012-10-19 Thread Edward Patzelt
R-help -

I'm trying to create axis breaks similar to this :
http://www.r-bloggers.com/wp-content/uploads/2010/08/bar-chart-natural-axis-split1.png
.

Is there a way to do this in R?  Here's my code thus far:

structure(list(condition = structure(c(2L, 1L, 3L), .Label = c("con",
"exp", "unedit"), class = "factor"), trial.avg = c(4.045833,
4.335417, 4.61875), trial.sd = c(0.928718367573187,
0.851822141963017,
1.03502368980692), s.e. = c(0.0232179591893297, 0.0212955535490754,
0.163651614601074), N = c(40, 40, 40), condition2 = structure(1:3, .Label =
c("Interaction Censured",
"Control Censured", "Uncensured"), class = "factor")), .Names =
c("condition",
"trial.avg", "trial.sd", "s.e.", "N", "condition2"), row.names = c(NA,
-3L), class = "data.frame")

library(ggplot2)
none <- theme_blank()
err1$condition <- as.factor(err1$condition)
censorA <- ggplot() + geom_bar(aes(y = trial.avg, x =
as.factor(condition2), fill = as.factor(condition2), position = "dodge"),
data = err1)

censorB <- censorA + geom_errorbar(aes(x = err1$condition2, ymin =
(err1$trial.avg-(err1$trial.sd/sqrt(40))), ymax = (err1$trial.avg+(err1$
trial.sd/sqrt(40))), data = err1, width = .4))

censorC <- censorB + opts(panel.background = none) + opts(panel.border =
none) + opts(panel.grid.minor = none) + opts(panel.grid.major = none) +
opts(axis.line = theme_segment(colour = "grey35")) + opts(background.fill =
none)


censorC + scale_y_continuous(limits = c(0,7),  expand = c(0,0), 'Rating') +
opts(legend.position = "none")

Best,

-- 
Edward H. Patzelt
Research Assistant – TRiCAM Lab
University of Minnesota – Psychology/Psychiatry
VA Medical Center
S355 Elliot Hall: 612-626-0072
www.psych.umn.edu/research/tricam

[[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] Post Hoc tests for ANOVA

2012-10-19 Thread Richard M. Heiberger
Please look at the ?mmc example for two-way ANOVA in library(HH).

If you don't already have HH you can get it with
install.packages("HH")
library(HH)
?mmc

mmc uses the glht function in the multcomp package for its calculations
and then draws the MMC graph.

Rich

On 10/19/12, Amartya  wrote:
> Hi,
>
> I was trying to figure out how to do  post-hoc tests for Two Way ANOVAs and
> found the following 2 approaches:
>
> a. Do pairwise t-tests (bonferroni corrected) if one finds significance
> with
> the ANOVA.
> Link-
> http://rtutorialseries.blogspot.com/2011/01/r-tutorial-series-two-way-anova-with.html
>
> b. Do TukeyHSD  on an aov model
> Link-
> http://www.r-bloggers.com/post-hoc-pairwise-comparisons-of-two-way-anova/
>
> Running the data set given in the first example in SPSS gives significant
> pairwise difference for Treatment and Age (Treatmen and Age were the
> independent variables) , while using the directions given in the first link
> didn't give me significant pairwise different for Treatment (only gave for
> Age).
>
> I have a few questions:
>
> a. Is the first method completely incorrect as hinted in the second link?
> b. What is the right way to do Bonferroni corrected post hoc tests for Two
> Way ANOVA in R?
> c. Does anyone know how post hoc tests for SPSS work in the case of Two Way
> ANOVAs (Univariate analysis)? Especially for Bonferroni corrected tests.
>
> I am new to R, so please let me know if I made a mistake in framing the
> question; I will try to elucidate as much as I personally can. Thanks for
> your help.
>
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Post-Hoc-tests-for-ANOVA-tp4646710.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] Post Hoc tests for ANOVA

2012-10-19 Thread rent0009
Amartya: This is probably more of a statistics question than an R question. 
I would go with the Tukey HSD, were I you as that is its intention.


Is there anyone in your organization (school, company, etc) that does 
statistical consulting? I have had wonderful experience working with the 
consulting clinic at the U of MN. If nothing else, buying a stats grad 
student some coffee might save you hours of headache in reading and 
searching message boards.


Mike.

On Oct 19 2012, Amartya wrote:


Hi,

I was trying to figure out how to do  post-hoc tests for Two Way ANOVAs and
found the following 2 approaches:

a. Do pairwise t-tests (bonferroni corrected) if one finds significance 
with

the ANOVA.
Link-
 
http://rtutorialseries.blogspot.com/2011/01/r-tutorial-series-two-way-anova-with.html


b. Do TukeyHSD  on an aov model 
Link-

http://www.r-bloggers.com/post-hoc-pairwise-comparisons-of-two-way-anova/

Running the data set given in the first example in SPSS gives significant
pairwise difference for Treatment and Age (Treatmen and Age were the
independent variables) , while using the directions given in the first link
didn't give me significant pairwise different for Treatment (only gave for
Age). 


I have a few questions:

a. Is the first method completely incorrect as hinted in the second link? 
b. What is the right way to do Bonferroni corrected post hoc tests for Two
Way ANOVA in R? 
c. Does anyone know how post hoc tests for SPSS work in the case of Two Way

ANOVAs (Univariate analysis)? Especially for Bonferroni corrected tests.

I am new to R, so please let me know if I made a mistake in framing the
question; I will try to elucidate as much as I personally can. Thanks for
your help.





--
View this message in context: 
http://r.789695.n4.nabble.com/Post-Hoc-tests-for-ANOVA-tp4646710.html

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

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

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



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


[R] factor score from PCA

2012-10-19 Thread ya

 

Hi everyone,

I am trying to get the factor score for each individual case from a principal 
component analysis, as I understand, both princomp() and prcomp() can not 
produce this factor score, the principal() in psych package has this option: 
scores=T, but after running the code, I could not figure out how to show the 
factor score results. Here is my code, could anyone give me some advice please? 
Thank you very much.

> pc <- principal(a,rotate="varimax",scores=TRUE)
> pc
Principal Components Analysis
Call: principal(r = a, rotate = "varimax", scores = TRUE)
Standardized loadings (pattern matrix) based upon correlation matrix
 PC1  h2   u2
V1  0.80 6.4e-01 0.36
V2  0.03 7.9e-04 1.00
V3 -0.92 8.4e-01 0.16
V4  0.00 2.0e-06 1.00
V5  0.54 2.9e-01 0.71

PC1
SS loadings1.77
Proportion Var 0.35

Test of the hypothesis that 1 component is sufficient.

The degrees of freedom for the null model are  10  and the objective function 
was  0.87
The degrees of freedom for the model are 5  and the objective function was  
0.39 
The number of observations was  20  with Chi Square =  6.14  with prob <  0.29 

Fit based upon off diagonal values = 0.61

> summary(pc)

Factor analysis with Call: principal(r = a, rotate = "varimax", scores = TRUE)

Test of the hypothesis that 1 factor is sufficient.
The degrees of freedom for the model is 5  and the objective function was  0.39 
The number of observations was  20  with Chi Square =  6.14  with prob <  0.29 
 






Best regards,
ya
[[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] Matrix to data.frame with factors

2012-10-19 Thread arun
Hi,
No problem.

You can also try this:
set.seed(1)
mat1<-matrix(sample(0:1,50,replace=TRUE),nrow=10,ncol=5)
 dat1<-as.data.frame(mat1)
 dat2<-do.call(data.frame,rapply(dat1,as.factor,classes="integer",how="replace"))
# str(dat2)
#'data.frame':    10 obs. of  5 variables:
# $ X1: Factor w/ 2 levels "0","1": 1 2 1 1 1 1 1 2 2 1
# $ X2: Factor w/ 2 levels "0","1": 2 1 1 1 2 1 1 2 1 2
# $ X3: Factor w/ 2 levels "0","1": 1 2 1 1 1 2 2 1 2 2
# $ X4: Factor w/ 2 levels "0","1": 1 2 1 1 2 1 2 1 1 1
# $ X5: Factor w/ 2 levels "0","1": 1 1 2 2 2 2 1 1 2 2
A.K.






- Original Message -
From: brunosm 
To: r-help@r-project.org
Cc: 
Sent: Friday, October 19, 2012 10:15 AM
Subject: Re: [R] Matrix to data.frame with factors

Thanks a lot!



--
View this message in context: 
http://r.789695.n4.nabble.com/Matrix-to-data-frame-with-factors-tp4646730p4646756.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] likelihood function involving integration, error in nlm

2012-10-19 Thread stats12
Thanks for pointing that out. Made some modifications and it worked.



--
View this message in context: 
http://r.789695.n4.nabble.com/likelihood-function-involving-integration-error-in-nlm-tp4646697p4646764.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] summation coding

2012-10-19 Thread cberry
djbanana  writes:

> Hi,
>
> I think I solved it myself by writing loops.
>
> What I meant is: are there in-built functions in R that calculate the
> following:
>
> a1(b2+...+b190) + a2(b1+b3+...+b190) + ...

Following Rainer's setup:

x <- data.frame( a = sample( 1:10, 4 ), b = sample( 11:20, 4 ) )

isn't 

  prod( colSums(x) ) - x$a %*% x$b

what you are after?

HTH,

Chuck
>  
> I managed to solve it, quite similar to what you just emailed.
>
> Thanks anyway!
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/summation-coding-tp4646678p4646712.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] Centering labels on X-axis

2012-10-19 Thread YAddo
Dear all:
I am trying to center labels on my plot with not much success. I have tried
text(), mtext() but it's not working. I think I am using the wrong function
for  my task.

 Any help will be appreciated.

My working codes.
axis(1,
at=c(1,2,3,4,5),font.lab=2,cex.axis=1.5,cex.lab=3,label=c("W0","CWH2","CWHmc","CH2","CHmc")
,text=c(1.5,2.5,3.5,4.5,5.5))

Many thanks in advance
YA



--
View this message in context: 
http://r.789695.n4.nabble.com/Centering-labels-on-X-axis-tp4646761.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] Kaplan-Meier plotting quirks

2012-10-19 Thread Michael Rentz
Terry: Thank you, that makes quite a bit of sense. In transposing the data 
to intervals (corresponding to trapping runs) it becomes quite clear that 
tag loss is very high up front, and has very good survival after the 
initial period. This is what I needed to know. I think I had a case of too 
many trees to see the forest. I did not set up exactly as you suggest, but 
since I do not expect there to be any interval effect (just number of 
intervals) I think I am OK.


Thank you again, and glad to see another Minnesotan here.

Mike.

On Oct 18 2012, Terry Therneau wrote:

Better would be to use interval censored data. Create your data set so 
that you have
(time1, time2) pairs, each of which describes the interval of time over 
which the tag was
lost. So an animal first captured at time 10 sans tag would be (0,10); 
with tag at 5 and
without at 20 would be (5,20), and last seen with tag at 30 would be (30, 
NA).
Then survit(Surv(time1, time2, type='interval2') ~ 1, data=yourdata) will 
give a curve

that accounts for interval censoring.
   As a prior poster suggested, if the times are very sparse then you may 
be better off
assuming a smooth curve. Use the survreg function with the same equation 
as above; see
help("predict.survreg") for an example of how to draw the resulting 
survival curve.


Terry Therneau

On 10/18/2012 05:00 AM, r-help-requ...@r-project.org wrote:

-Original Message-
From: Michael Rentz [mailto:rent0...@umn.edu]
Sent: Tuesday, October 16, 2012 12:36 PM
To:r-help@r-project.org
Subject: [R] R Kaplan-Meier plotting quirks?

  Hello. I apologize in advance for the VERY lengthy e-mail. I endeavor to 
include enough detail.


  I have a question about survival curves I have been battling off and on 
for a few months. No one local seems to be able to help, so I turn here. 
The issue seems to either be how R calculates Kaplan-Meier Plots, or 
something with the underlying statistic itself that I am misunderstanding. 
Basically, longer survival times are yielding steeper drops in survival 
than a set of shorter survival times but with the same number of loss and 
retention events.


  As a minor part of my research I have been comparing tag survival in 
marked wild rodents. I am comparing a standard ear tag with a relatively 
new technique. The newer tag clearly ?wins? using survival tests, but the 
resultant Kaplan-Meier plot does not seem to make sense. Since I am dealing 
with a wild animal and only trapped a few days out of a month the data is 
fairly messy, with gaps in capture history that require assumptions of tag 
survival. An animal that is tagged and recaptured 2 days later with a tag 
and 30 days later without one could have an assumed tag retention of 2 days 
(minimum confirmed) or 30 days (maximum possible).


  Both are significant with a survtest, but the K-M plots differ. A plot 
of minimum confirmed (overall harsher data, lots of 0 days and 1 or 2 days) 
yields a curve with a steep initial drop in ?survival?, but then a leveling 
off and straight line thereafter at about 80% survival. Plotting the 
maximum possible dates (same number of losses/retention, but retention 
times are longer, the length to the next capture without a tag, typically
  25-30 days or more) does not show as steep of a drop in the first few 
days, but at about the point the minimum estimate levels off this one 
begins dropping steeply. 400 days out the plot with minimum possible 
estimates has tag survival of about 80%, whereas the plot with the same 
loss rate but longer assumed survival times shows only a 20% assumed 
survival at 400 days. Complicating this of course is the fact that the 
great majority of the animals die before the tag is lost, survival of the 
rodents is on the order of months.


  I really am not sure what is going on, unless somehow the high number of 
events in the first few days followed by few events thereafter leads to the 
assumption that after the initial few days survival of the tag is high. The 
plotting of maximum lengths has a more even distribution of events, rather 
than a clumping in the first few days, so I guess the model assumes 
relatively constant hazards? As an aside, a plot of the mean between the 
minimum and maximum almost mirrors the maximum plot. Adding five days to 
the minimum when the minimum plus 5 is less than the maximum returns a plot 
with a steeper initial drop, but then constant thereafter, mimicking the 
minimum plot, but at a lower final survival rate.


  Basically, I am at a loss why surviving longer would*decrease* the 
survival rate???


  My co-author wants to drop the K-M graph given the confusion, but I 
think it would be odd to publish a survival paper without one. I am not 
sure which graph to use? They say very different things, while the actual 
statistics do not differ that greatly.


  I am more than happy to provide the data and code for anyone who would 
like to help if the above is not explanation enough. Thank you in adv

Re: [R] Upper limit in nlsLM not working as expected

2012-10-19 Thread Martin Hehn
Dear John,

this appears to be one of the cases where your algorithm is favourable over the 
nlsLM one. The fitting is now a lot better with  ssquared being lower compared 
to any other fit method I was comparing to. 

As I am relatively new to R, it still puzzles me that there are so many 
packages doing what I want but they seem so hard to track down.

Best regards,
Martin 

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

2012-10-19 Thread Sarah Goslee
>From ?princomp

Arguments:
scores: a logical value indicating whether the score on each
  principal component should be calculated.
Value:
  scores: if ‘scores = TRUE’, the scores of the supplied data on the
  principal components.  These are non-null only if ‘x’ was
  supplied, and if ‘covmat’ was also supplied if it was a
  covariance list.  For the formula method, ‘napredict()’ is
  applied to handle the treatment of values omitted by the
  ‘na.action’.

 ## NA-handling
 USArrests[1, 2] <- NA
 pc.cr <- princomp(~ Murder + Assault + UrbanPop,
   data = USArrests, na.action=na.exclude, cor = TRUE)
 pc.cr$scores[1:5, ]


>From the help for psych:::principal:

Arguments:
  scores: If TRUE, find component scores
Value:
  scores: If scores=TRUE, then estimates of the factor scores are
  reported

So the scores are returned as pc$scores in your example, and princomp
will also calculate them.

Sarah

On Fri, Oct 19, 2012 at 11:30 AM, ya  wrote:
>
>
>
> Hi everyone,
>
> I am trying to get the factor score for each individual case from a principal 
> component analysis, as I understand, both princomp() and prcomp() can not 
> produce this factor score, the principal() in psych package has this option: 
> scores=T, but after running the code, I could not figure out how to show the 
> factor score results. Here is my code, could anyone give me some advice 
> please? Thank you very much.
>
>> pc <- principal(a,rotate="varimax",scores=TRUE)
>> pc
> Principal Components Analysis
> Call: principal(r = a, rotate = "varimax", scores = TRUE)
> Standardized loadings (pattern matrix) based upon correlation matrix
>  PC1  h2   u2
> V1  0.80 6.4e-01 0.36
> V2  0.03 7.9e-04 1.00
> V3 -0.92 8.4e-01 0.16
> V4  0.00 2.0e-06 1.00
> V5  0.54 2.9e-01 0.71
>
> PC1
> SS loadings1.77
> Proportion Var 0.35
>
> Test of the hypothesis that 1 component is sufficient.
>
> The degrees of freedom for the null model are  10  and the objective function 
> was  0.87
> The degrees of freedom for the model are 5  and the objective function was  
> 0.39
> The number of observations was  20  with Chi Square =  6.14  with prob <  0.29
>
> Fit based upon off diagonal values = 0.61
>
>> summary(pc)
>
> Factor analysis with Call: principal(r = a, rotate = "varimax", scores = TRUE)
>
> Test of the hypothesis that 1 factor is sufficient.
> The degrees of freedom for the model is 5  and the objective function was  
> 0.39
> The number of observations was  20  with Chi Square =  6.14  with prob <  0.29
>
>
>

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

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


Re: [R] replacing rows data.frame

2012-10-19 Thread Rui Barradas

Hello,

Your problem comes from the fact that as new values are inserted in 
'alloc' the column alloc$agi keeps changing (obvious!) therefore R can't 
know all the factor levels beforehand. Therefore the values inserted are 
the numeric codes of the original factor. Since your example doesn't 
run, I've made up a dataset. Try to see what happens.



x <- data.frame(A = letters[1:10], B = 1:10)
str(x)

y <- data.frame(matrix(nrow=5, ncol=2))
colnames(y) <- colnames(x)

for(i in 1:10){
if(i %% 2 == 0){  # example condition
y[i/2, 1] <- as.character(x[i, 1])  # the factor column
y[i/2, -1] <- x[i, -1]  # all but 1st column
}
}
y$A <- factor(y$A)  # in the end we know the levels.
str(y)


Likewise, you must first fill in the column with character values then, 
in the end, coerce to factor.


Hope this helps,

Rui Barradas
Em 19-10-2012 12:06, evelyne escreveu:

I create a data.frame using :
alloc <- data.frame(matrix(nrow=length(unique(mid2agi$gene)), ncol=8))
colnames(alloc) <- c('agi', 'hit_len', 'q_len', 'identity', 'ratio', 'e',
'ok' ,'gene')
alloc$gene <- unique(mid2agi$gene)

this results in:

head(alloc)

  agi hit_len q_len identity   ratio  eok   gene
NA NA NA NA NA NA NA BrChr1g1V4
NA NA NA NA NA NA NA BrChr1g2V4

and I already have a dataframe (mid2agi) containing both integers and
factors.
In my empty dataframe I want to replace rows using:

for (i in (1:nrow(alloc)) ) {
 find <- alloc[i,]$gene
 submid2agi <- subset(mid2agi, gene %in% find)
 max <- which.max(submid2agi$identity * submid2agi$ratio)
 if (length(max) > 0){
*alloc[i,] <- submid2agi[max,]*
}
}

But my problem is that all values are now interpreted as integers, so my
text in my factors are converted to numbers.
Can anyone provide me with tips on how to solve this?

ouoput:
agi hit_len q_len identity   ratio  e ok   gene
*18296* 344   551   86.919 0.62432 2.1142e-89  *2* BrChr1g1V4

SHOULD be:
  agi hit_len q_len identity   ratio  eok   gene
AT4G38360.2 344   551   86.919 0.62432 2.1142e-89  True BrChr1g1V4

Thanks you..
Evelyne


   




--
View this message in context: 
http://r.789695.n4.nabble.com/replacing-rows-data-frame-tp4646731.html
Sent from the R help mailing list archive at Nabble.com.

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


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


[R] how can i plot dotted regression line shaped with condition using ggplot

2012-10-19 Thread autumnlin
I am plotting ggplot smooth line. I would like to add dots to the regression
line, the dots are shaped under different condition. 

p <- ggplot(data, aes(x = x, y = y, 
   shape = assign, linetype = factor(sex))) 

p0b <- p+ 
  scale_linetype_manual(breaks=c("0","1"), values=c(1,2)) +
  geom_smooth(aes(shape = assign, linetype = female), method = "lm", se =
FALSE, size = 1.2) 

the dots on the smooth line should be shaped by assign. how can i do it?
maybe i should add something like 
 scale_shape_manual(values=c(17, 0, 19))
and whatelse?
Thanks.



--
View this message in context: 
http://r.789695.n4.nabble.com/how-can-i-plot-dotted-regression-line-shaped-with-condition-using-ggplot-tp4646773.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] Centering labels on X-axis

2012-10-19 Thread Rui Barradas

Hello,

Your working code needs a plot first:

plot(1:5, xaxt = "n")

And there's no 'text' argument to axis(). As for the centering of axis 
labels, they're centered on my graphics device. Exactly what is 
happening to yours?


> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Portuguese_Portugal.1252 LC_CTYPE=Portuguese_Portugal.1252
[3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C
[5] LC_TIME=Portuguese_Portugal.1252

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

other attached packages:
[1] ggplot2_0.9.2 igraph_0.6-2

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   dichromat_1.2-4digest_0.5.2 fortunes_1.5-0
 [5] grid_2.15.1gtable_0.1.1   labeling_0.1 MASS_7.3-21
 [9] memoise_0.1munsell_0.3plyr_1.7.1 proto_0.3-9.2
[13] RColorBrewer_1.0-5 reshape2_1.2.1 scales_0.2.2 stringr_0.6.1
[17] tools_2.15.1

Hope this helps,

Rui Barradas
Em 19-10-2012 15:39, YAddo escreveu:

Dear all:
I am trying to center labels on my plot with not much success. I have tried
text(), mtext() but it's not working. I think I am using the wrong function
for  my task.

  Any help will be appreciated.

My working codes.
axis(1,
at=c(1,2,3,4,5),font.lab=2,cex.axis=1.5,cex.lab=3,label=c("W0","CWH2","CWHmc","CH2","CHmc")
,text=c(1.5,2.5,3.5,4.5,5.5))

Many thanks in advance
YA



--
View this message in context: 
http://r.789695.n4.nabble.com/Centering-labels-on-X-axis-tp4646761.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] how can i plot dotted regression line shaped with condition using ggplot

2012-10-19 Thread Ista Zahn
I may be missing something, but if you want dots you need to ask for
them with geom_point()

Best,
Ista

On Fri, Oct 19, 2012 at 11:46 AM, autumnlin  wrote:
> I am plotting ggplot smooth line. I would like to add dots to the regression
> line, the dots are shaped under different condition.
>
> p <- ggplot(data, aes(x = x, y = y,
>shape = assign, linetype = factor(sex)))
>
> p0b <- p+
>   scale_linetype_manual(breaks=c("0","1"), values=c(1,2)) +
>   geom_smooth(aes(shape = assign, linetype = female), method = "lm", se =
> FALSE, size = 1.2)
>
> the dots on the smooth line should be shaped by assign. how can i do it?
> maybe i should add something like
>  scale_shape_manual(values=c(17, 0, 19))
> and whatelse?
> Thanks.
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/how-can-i-plot-dotted-regression-line-shaped-with-condition-using-ggplot-tp4646773.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Creating a new by variable in a dataframe

2012-10-19 Thread ramoss
Hello,

I have a dataframe w/ 3 variables of interest: transaction,date(tdate) &
time(event_tim).
How could I create a 4th variable (last_trans) that would flag the last
transaction of the day for each day?
In SAS I use:
proc sort data=all6;
by tdate event_tim;
run;
 /*Create last transaction flag per day*/
data all6;
  set all6;
  by tdate event_tim;
  last_trans=last.tdate;

Thanks ahead for any suggestions.



--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-a-new-by-variable-in-a-dataframe-tp4646782.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] Which package/function for solving weighted linear least squares with inequality and equality constraints?

2012-10-19 Thread Berend Hasselman

On 19-10-2012, at 20:00, Thomas Schu wrote:

> Dear All,
> 
> Which package/function could i use to solve following linear least square
> problem?
> A over determined system of linear equations is given. The nnls-function may
> would be a possibility  BUT:
> The solving is constrained with 
> a inequality that all unknowns are >= 0 
> and a equality that the sum of all unknowns is 1
> The influence of the equations according to the solving process is weighted
> too.
> 
> llAx-bll2 * weight
> with xi >=0 and sum(x)=1
> 
> I´m pleased about every suggestion.

Just guessing.

Go to the Optimization task view on the Task Views page on  CRAN: 
http://cran.r-project.org/web/views/

Have a look at package limSolve (Quadratic Programming). From the description I 
gather that it may do what you want.

Berend

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Lattice bwplot: Adding mean with panel.points fails in vertical arrangement

2012-10-19 Thread Henning Wildhagen
Dear collegues,

given a structure of data like this:

## Data ###
set.seed(100)
a <- rnorm(60,10,3)
s <- c(rep("A",20),rep("B",20),rep("C",20))
p <- c(rep("d",6),rep("e",6),rep("f",6),rep("g",6),rep("h",6))
df <- data.frame(a,s,p)

i would like to draw a lattice bwplot in vertical arrangement,
with mean values added.

I tried:

## Plot 1 
library(lattice)
bwplot(a~p|s,data=df,
panel=function(x,y,...) {
        panel.bwplot(x,y, pch="|",...)
        panel.points(mean(x),y, col="red", ...)
})

However, the mean values are not plotted and it produces warnings.

The analogous code for the horizontal arrangement works well:

## Plot 2 #
bwplot(p~a|s,data=df,
panel=function(x,y,...) {
        panel.bwplot(x,y, pch="|",horizontal=TRUE,...)
        panel.points(mean(x),y, col="red", ...)
})

However, i prefer the vertical arrangement. I have no clue about the 
problem with the code for plot 1.
Can someone help me with modifying the code for Plot 1 accordingly?

Thanks, Henning


[[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] Creating a new by variable in a dataframe

2012-10-19 Thread William Dunlap
Suppose your data frame is
d <- data.frame(
 stringsAsFactors = FALSE,
 transaction = c("T01", "T02", "T03", "T04", "T05", "T06", 
"T07", "T08", "T09", "T10"),
 date = c("2012-10-19", "2012-10-19", "2012-10-19", 
"2012-10-19", "2012-10-22", "2012-10-23", 
"2012-10-23", "2012-10-23", "2012-10-23", 
"2012-10-23"),
 time = c("08:00", "09:00", "10:00", "11:00", "12:00", 
"13:00", "14:00", "15:00", "16:00", "17:00"
))
(Convert the date and time to your favorite classes, it doesn't matter here.)

A general way to say if an item is the last of its group is:
  isLastInGroup <- function(...)  ave(logical(length(..1)), ..., 
FUN=function(x)seq_along(x)==length(x))
  is_last_of_dayA <- with(d, isLastInGroup(date))
If you know your data is sorted by date you could save a little time for large
datasets by using
  isLastInRun <- function(x) c(x[-1] != x[-length(x)], TRUE)
  is_last_of_dayB <- isLastInRun(d$date)
The above d is sorted by date so you get the same results for both:
  > cbind(d, is_last_of_dayA, is_last_of_dayB)
 transaction   date  time is_last_of_dayA is_last_of_dayB
  1  T01 2012-10-19 08:00   FALSE   FALSE
  2  T02 2012-10-19 09:00   FALSE   FALSE
  3  T03 2012-10-19 10:00   FALSE   FALSE
  4  T04 2012-10-19 11:00TRUETRUE
  5  T05 2012-10-22 12:00TRUETRUE
  6  T06 2012-10-23 13:00   FALSE   FALSE
  7  T07 2012-10-23 14:00   FALSE   FALSE
  8  T08 2012-10-23 15:00   FALSE   FALSE
  9  T09 2012-10-23 16:00   FALSE   FALSE
  10 T10 2012-10-23 17:00TRUETRUE


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of ramoss
> Sent: Friday, October 19, 2012 10:52 AM
> To: r-help@r-project.org
> Subject: [R] Creating a new by variable in a dataframe
> 
> Hello,
> 
> I have a dataframe w/ 3 variables of interest: transaction,date(tdate) &
> time(event_tim).
> How could I create a 4th variable (last_trans) that would flag the last
> transaction of the day for each day?
> In SAS I use:
> proc sort data=all6;
> by tdate event_tim;
> run;
>  /*Create last transaction flag per day*/
> data all6;
>   set all6;
>   by tdate event_tim;
>   last_trans=last.tdate;
> 
> Thanks ahead for any suggestions.
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Creating-a-new-by-
> variable-in-a-dataframe-tp4646782.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] ggplot specify line type

2012-10-19 Thread autumnlin
 

hi is it possible to draw a graph like the attached one using ggplot?
how should i code it in r?
thanks.



--
View this message in context: 
http://r.789695.n4.nabble.com/ggplot-specify-line-type-tp4646789.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] RColorBrewer

2012-10-19 Thread StatsandtheirPres
Hi there everyone! So I'm a student in college, taking a very basic
Statistics course. We're using R for most of our assignments. I've hit a
pretty big wall here. I'm attempting to create a heat map of the entire
united states which corresponds to a set of percentages I have for each
state. My teacher suggested that I simply create a color palette with
RColorBrewer that is in the exact order of the states by alphabet so that I
can simply plug that pallette into the maps package and have it fill
alphabetically with the gradient I created through my list. My problem is
that I can't seem to create my own color palette using the color codes. How
do i create a color palette using a list of color codes? For example #41BH39
so on and so forth. Is this clear? Please ask me to clarify if it isn't. 

Thanks!





--
View this message in context: 
http://r.789695.n4.nabble.com/RColorBrewer-tp4646790.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] Thanks for the GREAT help :) Re: how can I adjust the ranges of my y-axis in barplot?

2012-10-19 Thread Yakamu Yakamu
Hi Uwe,
thank you very much for this great help,
jsut perfect what I needed to know :)
cheers,
Yakamu

--- On Wed, 10/3/12, Uwe Ligges  wrote:


From: Uwe Ligges 
Subject: Re: [R] how can I adjust the ranges of my y-axis in barplot?
To: "Yakamu Yakamu" 
Cc: "r-help@r-project.org" 
Date: Wednesday, October 3, 2012, 11:02 AM




On 03.10.2012 19:50, Yakamu Yakamu wrote:
> Hi all,
> I am making 2 barplots with 3 different bars inside with command :
>
> bar.wdHo<-barplot(wdHo.mean, names=c(""), cex.lab=1.0, cex.axis=1, 
> cex.names=1, ylim=c(0,15), xlab="", ylab=expression(paste("Thickness 
> (mm"^{2},")")), density=c(0,27,200), col=c("grey90","black","grey"), 
> beside=TRUE, axis.lty=1)
>
> and the other one :
> bar.wdHo<-barplot(wdHo.mean, names=c(""), cex.lab=1.0, cex.axis=1, 
> cex.names=1, ylim=c(0,5), xlab="", ylab=expression(paste("Thickness 
> (mm"^{2},")")), density=c(0,27,200), col=c("grey90","black","grey"), 
> beside=TRUE, axis.lty=1)
>


Not reproducible for us ...

> My question is :
>
> how can i adjust the y range from 0,5,10 and 15? for the first barplot and 
> the second to be 0, 2.5 and 5 ?
> because, even though i put the lim=c(0,15) for the first one, but then it 
> came out as 0,2,4,and so on (with even numbers) and the max is only 14.

You set the range of the whole axis by ylim, if you want to control the 
tick marks, use:

ylim=c(0,15), yaxp=c(0, 15, 3)

and

ylim=c(0,5), yaxp=c(0, 5, 2)

respectively. See ?par for details.


Otherwise, omit the y axis via yaxt="n" and add it separately by a call 
to axis().

Uwe Ligges




>
> because also I would like to show "comparisons" of magnitudes with the other 
> baplots /data that I have, one with max 15 and the other with maximum 5)
>
> Any help/comments/suggestions are highly appreciated,
> THanks in advance,
> cheers,
> Yakamu
>     [[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.


[R] how can I make a legend that applies for all the barplots in one same page?

2012-10-19 Thread Yakamu Yakamu
Dear all,
I would like to make 6 barplots in one page but with a legend that applies to 
all the barplots and would like to put it in the central-bottom of the page.
 
I know only how to make legend for individual barplot, but since all my 
barplots have the same type and would be better if i just use one legend for 
all of them, and i cannot seem to find a way to put the legend in the bottom 
and centered.
Please advice... 
I set the margins (and font type) as follows :
 
par(mfrow=c(3,2),pty="m") # Layout with 3x2 plots
par(oma=c(3,4,3,4)) # Outer margins
par(mar=c(5,5,2,2)) # Inner margins
par(xpd=F)
par(family="serif", font=1) # Times New Roman font 
 
ANy great help is kindly appreciated,
cheers,
Yayu
 
[[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] multiple graphs, lapply and different titles

2012-10-19 Thread Flavio Barros
I have a list of data.frames, and i want to iterate over this list and
generate graphs with the same title of the data.frame.

I did the graphs with:

lapply(anual, function(x) plot(x[,'chuva'], type='l', xlab= 'anos', ylab =
'Precicipatação(mm)', col='red'))

where anual is list of data.frames. I am plotting just the column "chuva"
at each data.frame.

How can i do that?

-- 
Att,

Flávio Barros

[[alternative HTML version deleted]]

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


Re: [R] how can I make a legend that applies for all the barplots in one same page?

2012-10-19 Thread Greg Snow
First of all, in the command par(xpd=F), what is the value of F?  If
it is the default value of FALSE then that says to not plot anything
outside of the plot region, so any attempts to put a legend in the
outer margin will not plot anything.  if F is TRUE (which is a recipe
for disaster) then you can put things into the figure region (inner
margins) but it will still not plot in the outer regions.  Only if F
is NA will it allow plotting in the outer margin.  That is why it is
best practice not to use F and T, but to spell out the logical names.
Best for this case is par(xpd=NA).  Now you can plot in the outer
margins.  Use the grconvertX and grconvertY functions to find the
location to put the legend, then use the legend function to plot it.

On Fri, Oct 19, 2012 at 1:22 PM, Yakamu Yakamu  wrote:
> Dear all,
> I would like to make 6 barplots in one page but with a legend that applies to 
> all the barplots and would like to put it in the central-bottom of the page.
>
> I know only how to make legend for individual barplot, but since all my 
> barplots have the same type and would be better if i just use one legend for 
> all of them, and i cannot seem to find a way to put the legend in the bottom 
> and centered.
> Please advice...
> I set the margins (and font type) as follows :
>
> par(mfrow=c(3,2),pty="m") # Layout with 3x2 plots
> par(oma=c(3,4,3,4)) # Outer margins
> par(mar=c(5,5,2,2)) # Inner margins
> par(xpd=F)
> par(family="serif", font=1) # Times New Roman font
>
> ANy great help is kindly appreciated,
> cheers,
> Yayu
>
> [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

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

2012-10-19 Thread ramoss
Thanks for all the help guys.

This worked for me:

all6 <- arrange(all6, tdate,event_tim)
lt <- ddply(all6,.(tdate),tail,1) 
lt$last_trans <-'Y'
all6 <-merge(all6,lt, by.x=c("tdate","event_tim"),
by.y=c("tdate","event_tim"),all.x=TRUE)




--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-a-new-by-variable-in-a-dataframe-tp4646782p4646799.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 a new by variable in a dataframe

2012-10-19 Thread Flavio Barros
I think i have a better solution

*## Example data.frame*
d <- data.frame(stringsAsFactors = FALSE, transaction = c("T01", "T02",
"T03", "T04", "T05", "T06", "T07", "T08", "T09", "T10"),date =
c("2012-10-19", "2012-10-19", "2012-10-19", "2012-10-19", "2012-10-22",
"2012-10-23", "2012-10-23", "2012-10-23", "2012-10-23", "2012-10-23"),time
= c("08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00",
"16:00", "17:00"))

*## As date tranfomation*
d$date <- as.Date(d$date)
d$time <- strptime(d$time, format='%H')

library(reshape)

*## Create factor to split the data*
fdate <- factor(format(d$date, '%D'))

*## Create a list with logical TRUE when is the last transaction*
ex <- sapply(split(d, fdate), function(x)
ifelse(as.numeric(x[,'time'])==max(as.numeric(x[,'time'])),T,F))

*## Coerce to logical vector*
flag <- unlist(rbind(ex))

*## With reshape we have the transform function e can add the flag column *
d <- transform(d, flag = flag)

On Fri, Oct 19, 2012 at 3:51 PM, William Dunlap  wrote:

> Suppose your data frame is
> d <- data.frame(
>  stringsAsFactors = FALSE,
>  transaction = c("T01", "T02", "T03", "T04", "T05", "T06",
> "T07", "T08", "T09", "T10"),
>  date = c("2012-10-19", "2012-10-19", "2012-10-19",
> "2012-10-19", "2012-10-22", "2012-10-23",
> "2012-10-23", "2012-10-23", "2012-10-23",
> "2012-10-23"),
>  time = c("08:00", "09:00", "10:00", "11:00", "12:00",
> "13:00", "14:00", "15:00", "16:00", "17:00"
> ))
> (Convert the date and time to your favorite classes, it doesn't matter
> here.)
>
> A general way to say if an item is the last of its group is:
>   isLastInGroup <- function(...)  ave(logical(length(..1)), ...,
> FUN=function(x)seq_along(x)==length(x))
>   is_last_of_dayA <- with(d, isLastInGroup(date))
> If you know your data is sorted by date you could save a little time for
> large
> datasets by using
>   isLastInRun <- function(x) c(x[-1] != x[-length(x)], TRUE)
>   is_last_of_dayB <- isLastInRun(d$date)
> The above d is sorted by date so you get the same results for both:
>   > cbind(d, is_last_of_dayA, is_last_of_dayB)
>  transaction   date  time is_last_of_dayA is_last_of_dayB
>   1  T01 2012-10-19 08:00   FALSE   FALSE
>   2  T02 2012-10-19 09:00   FALSE   FALSE
>   3  T03 2012-10-19 10:00   FALSE   FALSE
>   4  T04 2012-10-19 11:00TRUETRUE
>   5  T05 2012-10-22 12:00TRUETRUE
>   6  T06 2012-10-23 13:00   FALSE   FALSE
>   7  T07 2012-10-23 14:00   FALSE   FALSE
>   8  T08 2012-10-23 15:00   FALSE   FALSE
>   9  T09 2012-10-23 16:00   FALSE   FALSE
>   10 T10 2012-10-23 17:00TRUETRUE
>
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf
> > Of ramoss
> > Sent: Friday, October 19, 2012 10:52 AM
> > To: r-help@r-project.org
> > Subject: [R] Creating a new by variable in a dataframe
> >
> > Hello,
> >
> > I have a dataframe w/ 3 variables of interest: transaction,date(tdate) &
> > time(event_tim).
> > How could I create a 4th variable (last_trans) that would flag the last
> > transaction of the day for each day?
> > In SAS I use:
> > proc sort data=all6;
> > by tdate event_tim;
> > run;
> >  /*Create last transaction flag per day*/
> > data all6;
> >   set all6;
> >   by tdate event_tim;
> >   last_trans=last.tdate;
> >
> > Thanks ahead for any suggestions.
> >
> >
> >
> > --
> > View this message in context:
> http://r.789695.n4.nabble.com/Creating-a-new-by-
> > variable-in-a-dataframe-tp4646782.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.
>



-- 
Att,

Flávio Barros

[[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] Creating a new by variable in a dataframe

2012-10-19 Thread arun
Hi,

May be this helps you: 

dat1<-read.table(text="
tdate  event_tim  transaction
1/10/2012   2   14
1/10/2012   4   28
1/10/2012   6   42
1/10/2012   8   14
2/10/2012   6   46
2/10/2012   9   64
2/10/2012   8   71
3/10/2012  3   85
3/10/2012   1   14
3/10/2012   4   28
9/10/2012   5   51
9/10/2012   9   66
9/20/2012  12   84
",sep="",header=TRUE,stringsAsFactors=FALSE)
dat2<-dat1[with(dat1,order(tdate,event_tim)),]
dat2$tdate<-as.Date(dat2$tdate,format="%m/%d/%Y")
dat3<-dat2
 dat3$last_trans<-NA
library(plyr)
dat4<-merge(dat3,ddply(dat2,.(tdate),tail,1))
dat4$last_trans<-dat4$transaction
 res<-merge(dat4,dat2,all=TRUE)
 res
#    tdate event_tim transaction last_trans
#1  2012-01-10 2  14 NA
#2  2012-01-10 4  28 NA
#3  2012-01-10 6  42 NA
#4  2012-01-10 8  14 14
#5  2012-02-10 6  46 NA
#6  2012-02-10 8  71 NA
#7  2012-02-10 9  64 64
#8  2012-03-10 1  14 NA
#9  2012-03-10 3  85 NA
#10 2012-03-10 4  28 28
#11 2012-09-10 5  51 NA
#12 2012-09-10 9  66 66
#13 2012-09-20    12  84 84





- Original Message -
From: ramoss 
To: r-help@r-project.org
Cc: 
Sent: Friday, October 19, 2012 1:51 PM
Subject: [R] Creating a new by variable in a dataframe

Hello,

I have a dataframe w/ 3 variables of interest: transaction,date(tdate) &
time(event_tim).
How could I create a 4th variable (last_trans) that would flag the last
transaction of the day for each day?
In SAS I use:
proc sort data=all6;
by tdate event_tim;
run;
         /*Create last transaction flag per day*/
data all6;
  set all6;
  by tdate event_tim;
  last_trans=last.tdate;

Thanks ahead for any suggestions.



--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-a-new-by-variable-in-a-dataframe-tp4646782.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] Creating a new by variable in a dataframe

2012-10-19 Thread arun
Hi,

In addition to merge(), you can also use join()
dat1<-read.table(text="
tdate  event_tim  transaction
1/10/2012   2   14
1/10/2012   4   28
1/10/2012   6   42
1/10/2012   8   14
2/10/2012   6   46
2/10/2012   9   64
2/10/2012   8   71
3/10/2012  3   85
3/10/2012   1   14
3/10/2012   4   28
9/10/2012   5   51
9/10/2012   9   66
9/20/2012  12   84
",sep="",header=TRUE,stringsAsFactors=FALSE)
dat2<-dat1[with(dat1,order(tdate,event_tim)),]
aggres<-aggregate(dat2[,-1],by=list(tdate=dat2$tdate),tail,1)
aggres$last_trans<-"Y"
library(plyr)

join(dat2,aggres,by=intersect(names(dat2),names(aggres)),type="full")
#   tdate event_tim transaction last_trans
#1  1/10/2012 2  14   
#2  1/10/2012 4  28   
#3  1/10/2012 6  42   
#4  1/10/2012 8  14  Y
#5  2/10/2012 6  46   
#6  2/10/2012 8  71   
#7  2/10/2012 9  64  Y
#8  3/10/2012 1  14   
#9  3/10/2012 3  85   
#10 3/10/2012 4  28  Y
#11 9/10/2012 5  51   
#12 9/10/2012 9  66  Y
#13 9/20/2012    12  84  Y


A.K.

- Original Message -
From: ramoss 
To: r-help@r-project.org
Cc: 
Sent: Friday, October 19, 2012 1:51 PM
Subject: [R] Creating a new by variable in a dataframe

Hello,

I have a dataframe w/ 3 variables of interest: transaction,date(tdate) &
time(event_tim).
How could I create a 4th variable (last_trans) that would flag the last
transaction of the day for each day?
In SAS I use:
proc sort data=all6;
by tdate event_tim;
run;
         /*Create last transaction flag per day*/
data all6;
  set all6;
  by tdate event_tim;
  last_trans=last.tdate;

Thanks ahead for any suggestions.



--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-a-new-by-variable-in-a-dataframe-tp4646782.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] how can i plot dotted regression line shaped with condition using ggplot

2012-10-19 Thread autumnlin
I would like to add specific point on to the regression line, like
(x=1),shape=value(1)
is it possible?



--
View this message in context: 
http://r.789695.n4.nabble.com/how-can-i-plot-dotted-regression-line-shaped-with-condition-using-ggplot-tp4646773p4646797.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] saving to docx

2012-10-19 Thread javad bayat
hi all,
how can i saving R output to docx or Jpeg format?

[[alternative HTML version deleted]]

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


Re: [R] how can i plot dotted regression line shaped with condition using ggplot

2012-10-19 Thread Ista Zahn
See

?annotate

for help on adding individual points/labels/etc to a plot.

Best,
Ista

On Fri, Oct 19, 2012 at 3:48 PM, autumnlin  wrote:
> I would like to add specific point on to the regression line, like
> (x=1),shape=value(1)
> is it possible?
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/how-can-i-plot-dotted-regression-line-shaped-with-condition-using-ggplot-tp4646773p4646797.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] multiple graphs, lapply and different titles

2012-10-19 Thread David Winsemius

On Oct 19, 2012, at 12:30 PM, Flavio Barros wrote:

> I have a list of data.frames, and i want to iterate over this list and
> generate graphs with the same title of the data.frame.
> 
> I did the graphs with:
> 
> lapply(anual, function(x) plot(x[,'chuva'], type='l', xlab= 'anos', ylab =
> 'Precicipatação(mm)', col='red'))
> 
> where anual is list of data.frames. I am plotting just the column "chuva"
> at each data.frame.
> 
> How can i do that?

Easiest way would be to iterate over the names of the list 'anual' and then use 
nam as your formal argument,  pull each data.frame in from 'anual' with 
anual[nam] and use main=nam in the plot command.

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

Had you provided a self-contained example I would have offered tested code in 
return.

-- 

David Winsemius, MD
Alameda, CA, USA

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


Re: [R] ggplot specify line type

2012-10-19 Thread Brian Diggs

On 10/19/2012 11:42 AM, autumnlin wrote:



hi is it possible to draw a graph like the attached one using ggplot?


Yes


how should i code it in r?


Use a geom_point() where the shape aesthetic is mapped to the grouping 
variable and also add a geom_line(). If your horizontal axis is 
discrete, then you will need to set the grouping in the geom_line() 
correctly.


This answer is vague because the question was. Reproducible data and 
examples are appreciated/expected.  Here is code for a similar sort of 
graph.


ggplot(mtcars, aes(x=mpg, y=wt, shape=factor(carb))) +
geom_point() +
geom_line()


thanks.



--
View this message in context: 
http://r.789695.n4.nabble.com/ggplot-specify-line-type-tp4646789.html
Sent from the R help mailing list archive at Nabble.com.




--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

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


Re: [R] saving to docx

2012-10-19 Thread David Winsemius

On Oct 19, 2012, at 12:54 PM, javad bayat wrote:

> hi all,
> how can i saving R output to docx or Jpeg format?

There are some packages with functions to write to Word formats, but the one I 
know of only runs on Windows, so I have not bothered remembering its name. The 
sos package offers nice search facilities.

For saving to jpeg format:

?Devices

-- 

David Winsemius, MD
Alameda, CA, USA

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


Re: [R] saving to docx

2012-10-19 Thread Daróczi Gergely
Hi Javad,

saving R output to jpeg depends on what you want to save. For example
saving an `lm` object to an image would be fun :)
But you could export that quite easily to e.g. docx after installing
Pandoc[1] and pander[2] package. You can find some examples in the
README[3].

Best,
Gergely

[1] http://johnmacfarlane.net/pandoc/installing.html
[2] http://cran.r-project.org/web/packages/pander/index.html
[3a] brew syntax: http://rapporter.github.com/pander/#brew-to-pandoc
[3b] in a live R session:
http://rapporter.github.com/pander/#live-report-generation

On Fri, Oct 19, 2012 at 9:54 PM, javad bayat  wrote:

> hi all,
> how can i saving R output to docx or Jpeg format?
>
> [[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] how R implement qnorm()

2012-10-19 Thread Sheng Liu
Thanks, again! Sorry for my misleading expression, I only knew the value is
inquired from a polynomial approximation, but I have no idea how it is done
in such a great detail.  It's a great lesson for people like me who want a
deep understanding of the basics.

Sheng

On Thu, Oct 18, 2012 at 11:46 PM, peter dalgaard  wrote:

>
> On Oct 19, 2012, at 06:05 , Thomas Lumley wrote:
>
> > On Fri, Oct 19, 2012 at 12:21 PM, Sheng Liu  wrote:
> >> Thanks a lot. It's very helpful.
> >> I've read through the c code. Just FYI and for my completion of the
> >> question, I post some of my thought on it:
> >> To me it looks like the algorithm is actually inquiring through an
> >> approximation table (the approximations, at least for pnom, is "derived
> >> from those in "Rational Chebyshev approximations for the error
> function" by
> >> W. J. Cody, Math. Comp., 1969, 631-637."), it is not using any function
> >> such as intergration or inverse erf to compute the value based on an
> >> equation as I thought, though lack a bit subtlety but the up side is the
> >> speed.
> >
> > It's not an approximation table, it's a rational Chebyshev
> > approximation, a ratio of polynomials.  qnorm also uses a rational
> > polynomial approximation.
>
> I inferred that Sheng probably knew that and meant that there's a table of
> coefficients of a rational polynomial approximation.
>
> > At some level this *has to be* what is going on: computers don't
> > implement pnorm/qnorm or erfc in hardware, and there is no closed-form
> > expression for them in terms of quantities that are implemented in
> > hardware, so the functions must be some sort of approximate expression
> > using arithmetic and other hardware computations.
>
> Up to a few years ago, or maybe a decade, that was also the way special
> functions and even square roots and division were implemented in hardware
> using lookup tables and add/multiply circuits. All hell broke loose when
> one of the coefficients got entered incorrectly -- some may remember the
> FDIV Pentium bug of 1994. I used to have a really nice paper from Byte
> magazine c. 1990 which detailed the process, but I think it got lost in
> space. (L. Brett Glass: "Math Coprocessors" could be the one.
> http://dl.acm.org/citation.cfm?id=86680).
>
> Nowadays, we have single CPU cycle transcendentals, so I suppose that has
> all been reduced to hard-core optimized electronic circuitry. Fringe-market
> customers like statisticians still need to implement their functions in
> software, of course.
>
> >> From the point of view of R, the only relevant issues are precision,
> > speed, and portability, and these approximations are portable,
> > accurate, and fast.
> >
> >-thomas
> >
> >> Hope this can help others who had similar questions as well.
> >>
> >> Sheng
> >>
> >>
> >> On Thu, Oct 18, 2012 at 2:32 AM, peter dalgaard 
> wrote:
> >>
> >>>
> >>> On Oct 18, 2012, at 09:55 , Prof Brian Ripley wrote:
> >>>
> > R is a bit confusing as it requires inverse error function (X =
> > - sqrt(2)* erf-1 (2*P)), while R doesn't have a build in one. The
> InvErf
> > function most people use is through qnorm( InvErf=function(x)
> 
>  I think you are wrong about 'most people': this is the notation used
> by
> >>> a small group of non-statisticians (mainly physicists, I think).
> >>>
> >>> Well, he's right in the sense that it is erf/erfc that are commonly
> >>> documented in collections of special functions (like Abramowitz &
> Stegun),
> >>> and also those that appear in common C math libraries. In both cases of
> >>> course because physicists have dominated in their development.
> >>>
> >>> Of course "most people" use Excel these days (which has the inverse
> normal
> >>> distribution but AFAICS not the inverse error function).
> >>>
> >>> --
> >>> Peter Dalgaard, Professor,
> >>> Center for Statistics, Copenhagen Business School
> >>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> >>> Phone: (+45)38153501
> >>> Email: pd@cbs.dk  Priv: pda...@gmail.com
> >>>
> >>> __
> >>> R-help@r-project.org mailing list
> >>> https://stat.ethz.ch/mailman/listinfo/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.
> >
> >
> >
> > --
> > Thomas Lumley
> > Professor of Biostatistics
> > University of Auckland
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project

Re: [R] Question about survdiff in for-loop.

2012-10-19 Thread Thomas Lumley
On Fri, Oct 19, 2012 at 8:02 PM, Sando  wrote:
>
> Hi everyone!!
>
> I have dataset composed of a numbers of survival analyses.
> ( for batch survival analyses by using for-loop) .
> Here are code !!
>
> ###
> dim(svsv)
> Num_t<-dim(svsv)
> Num<-Num_t[2]   # These are predictors !!
>
> names=colnames(svsv)
>
> for (i in 1:Num  )
> {
> name_tt=names[i]
> survdiff(Surv(survival.m, survival) ~ names[i], data=svsv)
> fit.Group<-survfit(Surv(survival.m, survival) ~ names[i] , data=svsv)
> plot(fit.Group, col=2:1, xlab="Survival", ylab="Prob")
> }
>
> #
>
> names[i] is not working in the survdiff.

That's a problem with how formulas are parsed: you are effectively
telling survdiff() that you want names[i] as your predictor variable,
when actually you want it as the name of your predictor variable.

Using svsv[i] rather than names[i] should work.  Or you can insert the
value of names[i] into the formula with

 survdiff(eval(bquote(Surv(survival.m, survival) ~ .(names[i]))), data=svsv)

Even after you fix that, there's another problem, which is that your
code doesn't actually use the result from survdiff() in any way.

  -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

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


Re: [R] saving to docx

2012-10-19 Thread David Winsemius

On Oct 19, 2012, at 2:48 PM, Daróczi Gergely wrote:

> Hi Javad,
> 
> saving R output to jpeg depends on what you want to save. For example
> saving an `lm` object to an image would be fun :)
> But you could export that quite easily to e.g. docx after installing
> Pandoc[1] and pander[2] package. You can find some examples in the
> README[3].
> 
> Best,
> Gergely
> 
> [1] http://johnmacfarlane.net/pandoc/installing.html
> [2] http://cran.r-project.org/web/packages/pander/index.html
> [3a] brew syntax: http://rapporter.github.com/pander/#brew-to-pandoc
> [3b] in a live R session:
> http://rapporter.github.com/pander/#live-report-generation

I guess I need to retract my comment that such packages only existed on 
Windows. Despite 'pander' not passing its CRAN package check for Mac, it does 
build from source and the Pandoc installer does succeed inSnow Leapard and R 
2.15.1. Thank you for writing the pander package, Daróczi.


> 
> On Fri, Oct 19, 2012 at 9:54 PM, javad bayat  wrote:
> 
>> hi all,
>> how can i saving R output to docx or Jpeg format?
> 

-- 

David Winsemius, MD
Alameda, CA, USA

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


[R] Newly installed version; can't run lm function

2012-10-19 Thread Michael Grant
New installation seems to have behavior I cannot figure out.  Here is 
illustrative sequence where I load a small data set (test) from Crawley's files 
and try to run a simple linear model and get an error message.  Oddly, R 
reports that the variable 'test$ozone' is numeric while, after attaching test, 
the variable ozone is not numeric.  Can someone please help?  This behavior is 
occurring with multiple data sets loaded from outside R.  Thank you in advance.
Michael Grant


Example:
> test
   ozone garden
1  3  A
2  5  B
3  4  A
4  5  B
5  4  A
6  6  B
7  3  A
8  7  B
9  2  A
10 4  B
11 3  A
12 4  B
13 1  A
14 3  B
15 3  A
16 5  B
17 5  A
18 6  B
19 2  A
20 5  B
> is.data.frame(test)
[1] TRUE
> is.numeric(test$ozone)
[1] TRUE
> is.factor(test$garden)
[1] TRUE
> lm(ozone~garden)
Error in model.frame.default(formula = ozone ~ garden, drop.unused.levels = 
TRUE) :
  invalid type (list) for variable 'ozone'

> attach(test)
> is.numeric(ozone)
[1] FALSE
> is.numeric(test$ozone)
[1] TRUE

[[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] Newly installed version; can't run lm function

2012-10-19 Thread Jorge I Velez
Hi Michael,

Try

fit <- lm(ozone~garden, data = test)
summary(fit)

See ?lm for more details.

HTH,
Jorge.-


On Sat, Oct 20, 2012 at 8:26 AM, Michael Grant <> wrote:

> New installation seems to have behavior I cannot figure out.  Here is
> illustrative sequence where I load a small data set (test) from Crawley's
> files and try to run a simple linear model and get an error message.
>  Oddly, R reports that the variable 'test$ozone' is numeric while, after
> attaching test, the variable ozone is not numeric.  Can someone please
> help?  This behavior is occurring with multiple data sets loaded from
> outside R.  Thank you in advance.
> Michael Grant
>
>
> Example:
> > test
>ozone garden
> 1  3  A
> 2  5  B
> 3  4  A
> 4  5  B
> 5  4  A
> 6  6  B
> 7  3  A
> 8  7  B
> 9  2  A
> 10 4  B
> 11 3  A
> 12 4  B
> 13 1  A
> 14 3  B
> 15 3  A
> 16 5  B
> 17 5  A
> 18 6  B
> 19 2  A
> 20 5  B
> > is.data.frame(test)
> [1] TRUE
> > is.numeric(test$ozone)
> [1] TRUE
> > is.factor(test$garden)
> [1] TRUE
> > lm(ozone~garden)
> Error in model.frame.default(formula = ozone ~ garden, drop.unused.levels
> = TRUE) :
>   invalid type (list) for variable 'ozone'
>
> > attach(test)
> > is.numeric(ozone)
> [1] FALSE
> > is.numeric(test$ozone)
> [1] TRUE
>
> [[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] Newly installed version; can't run lm function

2012-10-19 Thread David Winsemius

On Oct 19, 2012, at 2:26 PM, Michael Grant wrote:

> New installation seems to have behavior I cannot figure out.  Here is 
> illustrative sequence where I load a small data set (test) from Crawley's 
> files and try to run a simple linear model and get an error message.  Oddly, 
> R reports that the variable 'test$ozone' is numeric while, after attaching 
> test, the variable ozone is not numeric.  Can someone please help?  This 
> behavior is occurring with multiple data sets loaded from outside R.  Thank 
> you in advance.
> Michael Grant
> 
> 
> Example:
>> test
>   ozone garden
> 1  3  A
> 2  5  B
> 3  4  A
> 4  5  B
> 5  4  A
> 6  6  B
> 7  3  A
> 8  7  B
> 9  2  A
> 10 4  B
> 11 3  A
> 12 4  B
> 13 1  A
> 14 3  B
> 15 3  A
> 16 5  B
> 17 5  A
> 18 6  B
> 19 2  A
> 20 5  B
>> is.data.frame(test)
> [1] TRUE
>> is.numeric(test$ozone)
> [1] TRUE
>> is.factor(test$garden)
> [1] TRUE
>> lm(ozone~garden)
> Error in model.frame.default(formula = ozone ~ garden, drop.unused.levels = 
> TRUE) :
>  invalid type (list) for variable 'ozone'

This is not surprising for two reasons. Crawley's presumptuously named text 
"The R Book" teaches students to use `attach`, leaving them unprepared to deal 
with the rather predictable confusion that unfortunate practice leads to. (The 
second reason is that you have not yet used `attach`.)

> 
>> attach(test)
>> is.numeric(ozone)

And when I do that, I do not get the same result:

test <- read.table(text="  ozone garden
1  3  A
2  5  B
3  4  A
4  5  B
5  4  A
6  6  B
7  3  A
8  7  B
9  2  A
10 4  B
11 3  A
12 4  B
13 1  A
14 3  B
15 3  A
16 5  B
17 5  A
18 6  B
19 2  A
20 5  B", header=TRUE)
is.data.frame(test)
#[1] TRUE
is.numeric(test$ozone)
#[1] TRUE
is.factor(test$garden)
#[1] TRUE
lm(ozone~garden)

# Error which seems perfectly expected without a 'data' argument.
attach(test)
is.numeric(ozone)
---

# I get 

> is.numeric(ozone)
[1] TRUE

So you have done something else. What it is we cannot tell. Why not send a 
letter to Crawley? He's the one you paid money for that fat book, and whose 
dataset you are importing in some unspecified manner. Or perhaps use:

str(test)



> [1] FALSE
>> is.numeric(test$ozone)
> [1] TRUE
> 
>   [[alternative HTML version deleted]]
> 

-- 

David Winsemius, MD
Alameda, CA, USA

> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

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


Re: [R] Newly installed version; can't run lm function

2012-10-19 Thread Rolf Turner


You have an object named "ozone" kicking around in your workspace/global
environment.  This is apparently not of mode "numeric" and it is masking
the "ozone" object (column) from the attached data frame "test".

Simply doing ls() would have told you this.

Presumably you also got a warning about this when you attached test.
Heed the warning!

As others have advised you ***don't use attach()***!!!

Instead, use "data= ..." in your call to lm().

cheers,

Rolf Turner

On 20/10/12 10:26, Michael Grant wrote:

New installation seems to have behavior I cannot figure out.  Here is 
illustrative sequence where I load a small data set (test) from Crawley's files 
and try to run a simple linear model and get an error message.  Oddly, R 
reports that the variable 'test$ozone' is numeric while, after attaching test, 
the variable ozone is not numeric.  Can someone please help?  This behavior is 
occurring with multiple data sets loaded from outside R.  Thank you in advance.
Michael Grant


Example:

test

ozone garden
1  3  A
2  5  B
3  4  A
4  5  B
5  4  A
6  6  B
7  3  A
8  7  B
9  2  A
10 4  B
11 3  A
12 4  B
13 1  A
14 3  B
15 3  A
16 5  B
17 5  A
18 6  B
19 2  A
20 5  B

is.data.frame(test)

[1] TRUE

is.numeric(test$ozone)

[1] TRUE

is.factor(test$garden)

[1] TRUE

lm(ozone~garden)

Error in model.frame.default(formula = ozone ~ garden, drop.unused.levels = 
TRUE) :
   invalid type (list) for variable 'ozone'


attach(test)
is.numeric(ozone)

[1] FALSE

is.numeric(test$ozone)

[1] TRUE

[[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] help finding edge connecting two nodes

2012-10-19 Thread Gábor Csárdi
On Fri, Oct 19, 2012 at 2:50 PM, Dhaval Adjodah  wrote:
[...]
> Your way works best! Another way I found from stackoverflow (see the post
> at
> http://stackoverflow.com/questions/12964332/igraph-edge-between-two-vertices/12980550#12980550)
> was
> to convert the graph into an adjacency matrix and then use simple matrix
> indices .

Just make this clear. The example (repeated below) on the
stackoverflow page does _not_ convert the graph into an adjacency
matrix. The indexing only makes the graph look as if it was an
adjacency matrix. But there is no conversion at all.

Gabor

ps. I would appreciate if you didn't cross-post your questions
everywhere (R-help, igraph-help and stackoverflow, maybe other places
as well). Please only post it on the platform you prefer first and
then, if you don't get a good answer, try elsewhere. Thanks!

library(igraph)
g <- graph.ring(10)
g[1,2]
# [1] 1
E(g)$weight <- runif(ecount(g))
g[1,2]
# [1] 0.8115639

[...]

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


Re: [R] plot.new() and grid functions in multipage pdfs

2012-10-19 Thread Ali Tofigh
On Wed, Oct 17, 2012 at 4:08 PM, ilai  wrote:
> On Wed, Oct 17, 2012 at 11:10 AM, Ali Tofigh  wrote:
>>
>> my problem is that I usually have no choice but to mix grid and base
>> graphics.
>
> What does that have to do with the answer you got ? did you even try it ?
> here it is (again) but this time mixing base+grid:

The answer I got was that "base and grid graphics don't usually play
well together". I replied that I don't have a choice. So my reply has
everything to do with the answer I got. And yes, of course I tried. I
tried not using plot.new() and using grid.newpage() instead. Contrary
to what you think, that does not always work. Below is a minimal example that
you requested.

It seems that I have to use a mix of plot.new() and grid.newpage().
But if base graphics and grid don't play well together, is there
another option?

library(grid)
library(gridBase)

# plot a rectangle on the right side and a simple plot on the left.
my.plot <- function() {
pushViewport(viewport(layout = grid.layout(nrow=1, ncol=2)))
pushViewport(viewport(layout.pos.row = 1, layout.pos.col = 2))
grid.rect(c(0.25, 0.75), width=c(0.5, 0.5), gp=gpar(fill=c("blue", "red")))
popViewport()

pushViewport(viewport(layout.pos.row = 1, layout.pos.col = 1))
par(new=TRUE, fig=gridFIG())
plot(1:10)
popViewport()
popViewport()
}

## incorrect first plot
pdf("test1.pdf")
my.plot(); grid.newpage(); my.plot()
dev.off()

## incorrect second plot
pdf("test2.pdf")
plot.new(); my.plot(); plot.new(); my.plot()
dev.off()

## this works as intended with a mix of plot.new() and grid.newpage
pdf("test3.pdf")
plot.new(); my.plot(); grid.newpage(); my.plot()
dev.off()

/ali

>
> require(gridBase)
> pdf("test.pdf")
>
> grid.rect(gp = gpar(fill="blue"))
> grid.newpage()
> grid.rect(gp=gpar(fill='blue'))
> # mix in base+grid. adapted from ?gridPAR in gridBase
> par(fig=gridFIG(), new=TRUE)
>  plot(1:10)
> # plot.new()  # uncomment to see it's unnecessary
> plot(1:10)
>  pushViewport(viewport(width=0.5, height=0.5)) ;
> grid.rect(gp=gpar(col="grey", lwd=2))
> plot(rnorm(10))
> grid.newpage()
> grid.rect(gp=gpar(fill='blue'))
> dev.off()
>
>>
>> I use grid as much as possible, but for example for plotting
>> dendrograms, I don't know how to plot them other than using base
>> graphics. So I use the functions in gridBase to produce those plots.
>
>
> Then you may have noticed the dendrogram examples in the gridBase docs don't
> use plot.new() either but use lattice for the layout.
>
>
>> In order to do that I have to call plot.new() at some point in my code
>> to initialize the base graphics, and that can mess things up.
>
>
>>
>> No. See example above or provide a minimal reproducible example that does
>> require it.
>
>
>
>>
>> /ali
>>
>>
>> On Tue, Oct 9, 2012 at 4:00 PM, Greg Snow <538...@gmail.com> wrote:
>> > The plot.new function is for base graphics and base and grid graphics
>> > don't usually play well together.  You probably want to use
>> > grid.newpage function instead.
>> >
>> > On Tue, Oct 9, 2012 at 1:26 PM, Ali Tofigh 
>> > wrote:
>> >> Hi,
>> >>
>> >> when using the grid package, I've come across this weird behaviour
>> >> where a call to plot.new() will start a new page for a multi-page pdf,
>> >> but then the margins will somehow behave strangely for all but the
>> >> first page: here is some code:
>> >>
>> >> pdf("test.pdf"); plot.new(); grid.rect(gp = gpar(fill="blue"));
>> >> plot.new();  grid.rect(gp = gpar(fill="blue")); dev.off()
>> >>
>> >> The first page is filled completely with a blue rectangle, but in the
>> >> second page, the margins clip the rectangle. This is causing me
>> >> considerable headache, as I rely on many grid functions for plotting.
>> >> This seems like a bug to me, or is there something about the behaviour
>> >> of plot.new() and/or grid functions that I don't understand?
>> >>
>> >> /Ali
>> >>
>> >> __
>> >> R-help@r-project.org mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/r-help
>> >> PLEASE do read the posting guide
>> >> http://www.R-project.org/posting-guide.html
>> >> and provide commented, minimal, self-contained, reproducible code.
>> >
>> >
>> >
>> > --
>> > Gregory (Greg) L. Snow Ph.D.
>> > 538...@gmail.com
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] grid(Base): How to avoid "Figure region too small and/or viewport too large" by specifying 'relative' units?

2012-10-19 Thread Marius Hofert
In the meanwhile, I found a more minimal example which shows the problem (just
change 'inch' to TRUE to see the difference):


require(grid)

inch <- FALSE # TRUE

d <- if(inch) 5 else 1
pspc <- d*c(0.3, 0.3) # width, height of panels
spc <- d*c(0.05, 0.05) # width, height of space
axlabspc <- d*c(0.1, 0.1) # width y label, height x label
labspc <- d*c(0.05, 0.05) # width label boxes, height label boxes

par. <- par(no.readonly=TRUE)
gl <- grid.layout(5, 5, default.units=if(inch) "inches" else "npc",
  widths=c(axlabspc[1], pspc[1], spc[1], pspc[1], labspc[1]),
  heights=c(labspc[2], pspc[2], spc[2], pspc[2], axlabspc[2]))
grid.show.layout(gl)
pushViewport(viewport(layout=gl))
for(i in 1:2) {
for(j in 1:2) {
pushViewport(viewport(layout.pos.row=2*i, layout.pos.col=2*j, 
name="foo"))
grid.rect()
upViewport()
}
}
par(par.)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] mark sections on a time chart

2012-10-19 Thread Christof Kluß
Hi

is there a comfortable way to mark periods on time chart (axis.Date)?

To do it with arrows(...), seems to be irritating.

I want to have something like

<---winter--><--spring--><--summer-->

thx
Christof

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

2012-10-19 Thread arun


HI,
Without using "ifelse()" on the same example dataset.
d <- data.frame(stringsAsFactors = FALSE, transaction = c("T01", "T02",
"T03", "T04", "T05", "T06", "T07", "T08", "T09", "T10"),date =
c("2012-10-19", "2012-10-19", "2012-10-19", "2012-10-19", "2012-10-22",
"2012-10-23", "2012-10-23", "2012-10-23", "2012-10-23", "2012-10-23"),time
= c("08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00",
"16:00", "17:00"))

d$date <- as.Date(d$date,format="%Y-%m-%d")
d$time<-strptime(d$time,format="%H:%M")$hour
d$flag<-unlist(rbind(lapply(split(d,d$date),function(x) x[3]==max(x[3]
d$datetime<-as.POSIXct(paste(d$date,d$time," "),format="%Y-%m-%d %H")
d1<-d[,c(1,5,4)]
 d1
#   transaction    datetime  flag
#1  T01 2012-10-19 08:00:00 FALSE
#2  T02 2012-10-19 09:00:00 FALSE
#3  T03 2012-10-19 10:00:00 FALSE
#4  T04 2012-10-19 11:00:00  TRUE
#5  T05 2012-10-22 12:00:00  TRUE
#6  T06 2012-10-23 13:00:00 FALSE
#7  T07 2012-10-23 14:00:00 FALSE
#8  T08 2012-10-23 15:00:00 FALSE
#9  T09 2012-10-23 16:00:00 FALSE
#10 T10 2012-10-23 17:00:00  TRUE

str(d1)
#'data.frame':    10 obs. of  3 variables:
# $ transaction: chr  "T01" "T02" "T03" "T04" ...
# $ datetime   : POSIXct, format: "2012-10-19 08:00:00" "2012-10-19 09:00:00" 
...
# $ flag   : logi  FALSE FALSE FALSE TRUE TRUE FALSE ...

A.K.


- Original Message -
From: Flavio Barros 
To: William Dunlap 
Cc: "r-help@r-project.org" ; ramoss 

Sent: Friday, October 19, 2012 4:24 PM
Subject: Re: [R] Creating a new by variable in a dataframe

I think i have a better solution

*## Example data.frame*
d <- data.frame(stringsAsFactors = FALSE, transaction = c("T01", "T02",
"T03", "T04", "T05", "T06", "T07", "T08", "T09", "T10"),date =
c("2012-10-19", "2012-10-19", "2012-10-19", "2012-10-19", "2012-10-22",
"2012-10-23", "2012-10-23", "2012-10-23", "2012-10-23", "2012-10-23"),time
= c("08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00",
"16:00", "17:00"))

*## As date tranfomation*
d$date <- as.Date(d$date)
d$time <- strptime(d$time, format='%H')

library(reshape)

*## Create factor to split the data*
fdate <- factor(format(d$date, '%D'))

*## Create a list with logical TRUE when is the last transaction*
ex <- sapply(split(d, fdate), function(x)
ifelse(as.numeric(x[,'time'])==max(as.numeric(x[,'time'])),T,F))

*## Coerce to logical vector*
flag <- unlist(rbind(ex))

*## With reshape we have the transform function e can add the flag column *
d <- transform(d, flag = flag)

On Fri, Oct 19, 2012 at 3:51 PM, William Dunlap  wrote:

> Suppose your data frame is
> d <- data.frame(
>      stringsAsFactors = FALSE,
>      transaction = c("T01", "T02", "T03", "T04", "T05", "T06",
>         "T07", "T08", "T09", "T10"),
>      date = c("2012-10-19", "2012-10-19", "2012-10-19",
>         "2012-10-19", "2012-10-22", "2012-10-23",
>         "2012-10-23", "2012-10-23", "2012-10-23",
>         "2012-10-23"),
>      time = c("08:00", "09:00", "10:00", "11:00", "12:00",
>         "13:00", "14:00", "15:00", "16:00", "17:00"
>         ))
> (Convert the date and time to your favorite classes, it doesn't matter
> here.)
>
> A general way to say if an item is the last of its group is:
>   isLastInGroup <- function(...)  ave(logical(length(..1)), ...,
> FUN=function(x)seq_along(x)==length(x))
>   is_last_of_dayA <- with(d, isLastInGroup(date))
> If you know your data is sorted by date you could save a little time for
> large
> datasets by using
>   isLastInRun <- function(x) c(x[-1] != x[-length(x)], TRUE)
>   is_last_of_dayB <- isLastInRun(d$date)
> The above d is sorted by date so you get the same results for both:
>   > cbind(d, is_last_of_dayA, is_last_of_dayB)
>      transaction       date  time is_last_of_dayA is_last_of_dayB
>   1          T01 2012-10-19 08:00           FALSE           FALSE
>   2          T02 2012-10-19 09:00           FALSE           FALSE
>   3          T03 2012-10-19 10:00           FALSE           FALSE
>   4          T04 2012-10-19 11:00            TRUE            TRUE
>   5          T05 2012-10-22 12:00            TRUE            TRUE
>   6          T06 2012-10-23 13:00           FALSE           FALSE
>   7          T07 2012-10-23 14:00           FALSE           FALSE
>   8          T08 2012-10-23 15:00           FALSE           FALSE
>   9          T09 2012-10-23 16:00           FALSE           FALSE
>   10         T10 2012-10-23 17:00            TRUE            TRUE
>
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf
> > Of ramoss
> > Sent: Friday, October 19, 2012 10:52 AM
> > To: r-help@r-project.org
> > Subject: [R] Creating a new by variable in a dataframe
> >
> > Hello,
> >
> > I have a dataframe w/ 3 variables of interest: transaction,date(tdate) &
> > time(event_tim).
> > How could I create a 4th

Re: [R] Question about survdiff in for-loop.

2012-10-19 Thread Sando


Thank you for your replay and help !!

Best Regards, Young. 



--
View this message in context: 
http://r.789695.n4.nabble.com/Question-about-survdiff-in-for-loop-tp4646707p4646827.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] xyplot type 'a' with mean symbols

2012-10-19 Thread Jasmine
Hi there

I almost have the graph I want (except for moving the legend into the
graph).

Can someone please tell me how to put symbols at the means for this graph?

xyplot (anxiety ~ treatment, groups=therapist, data=study2, ylim=c(0,50),
auto.key=T, type='a')

Thank you so much :)



--
View this message in context: 
http://r.789695.n4.nabble.com/xyplot-type-a-with-mean-symbols-tp4646829.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.