Re: [R] integrate function

2009-12-05 Thread Berend Hasselman



li li-13 wrote:
> 
> Yes, f2 is the function I wanted to write. I tried to do use "Vectorize"
> function to f1, it did not work.
>> f2 <- function(x)
> +  {
> +  integrate(Vectorize(f1,vectorize.args =p), lower=0,upper=1, x)
> +   }
>> f2(c(2,3))
> Error in Vectorize(f1, vectorize.args = p) :
>   must specify formal argument names to vectorize
> 

Use  integrate(Vectorize(f1,vectorize.args =c("p")), lower=0,upper=1, x) 

vectorize.args is a character vector of arguments according to the
documentation.

Then f2(1:3) will give:  19 with absolute error < 2.1e-13

Berend
-- 
View this message in context: 
http://n4.nabble.com/integrate-function-tp949420p949533.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Error in eval(expr, envir, enclos) : object 'N' not found

2009-12-05 Thread hansoffate

I'm running an LSODA to generate some graphs, but I need to stop at a certain
point and use those values to generate another LSODA output.  This is
working fine, but when I try to run the second LSODA, I get the "Error in
eval(expr, envir, enclos) : object 'N' not found".  Any ideas what can be
causing this? I have no object 'N' anywhere in the script.  I made an
identical version of models states, parameters, and everything just by
adding 2 after each one, and I'm still getting this error.  

Thanks,
-Hans

::CODE::
require(odesolve);
###Params for running script ##
iniT=1E3; iniN=10; iniM=0; iniC=1E3;
num_days = 30; interval_size = .1; OF_prcnt = .10;

model <- function(t, state, pars)
{
  with (as.list(c(state, pars)), {
dT=(a*T-a*T*b*T) - (c1*N*T) - (Kt*M*T)
dN=a1 - (f*N) + g * (T/(h+T)) * N - (p * N * T) - (Kn * M * N)
dC=a2 - (beta * C) - (Kc * M  * C)
dM= -(gamma) * M + Vm 

return(list(c(dT,dN,dC,dM)))
  })
}

model2 <- function(t, state2, pars2)
{
  with (as.list(c(state2, pars2)), {
dT=(a*T-a*T*b*T) - (c1*N*T) - (Kt*M*T)
dN=a1 - (f*N) + g * (T/(h+T)) * N - (p * N * T) - (Kn * M * N)
dC=a2 - (beta * C) - (Kc * M  * C)
dM= -(gamma) * M + Vm 

return(list(c(dT,dN,dC,dM)))
  })
}

### First Half - Tumor growth to 10%
pars <- list( Tini=iniT, Nini=iniN, Mini=iniM, Cini=iniC,
  a=4.31E-3, b=1.02E-14, c1=3.41E-10, Kt=8E-1,
  f=4.12E-2, g=1.5E-2, h=2.02E1, beta=1.20E-2, gamma=9E-1,
  Kc=6E-1, Kn=6E-1, p=2E-11, a1=1.2E4, a2=7.5E8, Vm=0 )

tout<- seq(0, num_days, by=interval_size)
state   <- c(T = pars$Tini, N = pars$Nini, C = pars$Cini, M = pars$Mini)
out <- lsoda(state, tout, model, pars)

## Finding position at which OF function is reached
final_matrix = out;
loopsize = (num_days / interval_size) + 1
OF_tumor_size = iniT + (OF_prcnt * iniT)

## Sentinel Value to find at which row in the matrix reaches OF_tumor_size
OF_row=-1;  
for(i in 1:loopsize) {
  if( out[i,2] >= OF_tumor_size) {
OF_row=i;
break;
  }
}

if(OF_row != -1) {
  ##Params setup
  OF_iniT=out[OF_row,2]; OF_iniN=out[OF_row,3]; OF_iniC=out[OF_row,4];
OF_iniM=out[OF_row,5];
  pars2 <- list( Tini=OF_iniT, Nini=OF_iniN, Mini=OF_iniM, Cini=OF_iniC,
  a=4.31E-3, b=1.02E-14, c1=3.41E-10, Kt=8E-1,
f=4.12E-2, g=1.5E-2, h=2.02E1, beta=1.20E-2, gamma=9E-1,
Kc=6E-1, Kn=6E-1, p=2E-11, a1=1.2E4, a2=7.5E8, Vm=0 )
  state2   <- c(T = pars2$Tini, N = pars2$Nini, C = pars2$Cini, M =
pars2$Mini)
  out2 <- lsoda(state2, tout, model2, pars2)
}

-- 
View this message in context: 
http://n4.nabble.com/Error-in-eval-expr-envir-enclos-object-N-not-found-tp949499p949499.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Error in eval(expr, envir, enclos) : object 'N' not found

2009-12-05 Thread hansoffate

I'm running an LSODA to generate some graphs, but I need to stop at a certain
point and use those values to generate another LSODA output.  This is
working fine, but when I try to run the second LSODA, I get the "Error in
eval(expr, envir, enclos) : object 'N' not found".  Any ideas what can be
causing this? I have no object 'N' anywhere in the script.  I made an
identical version of models states, parameters, and everything just by
adding 2 after each one, and I'm still getting this error.  

Thanks,
-Hans

::CODE::
require(odesolve);
###Params for running script ##
iniT=1E3; iniN=10; iniM=0; iniC=1E3;
num_days = 30; interval_size = .1; OF_prcnt = .10;

model <- function(t, state, pars)
{
  with (as.list(c(state, pars)), {
dT=(a*T-a*T*b*T) - (c1*N*T) - (Kt*M*T)
dN=a1 - (f*N) + g * (T/(h+T)) * N - (p * N * T) - (Kn * M * N)
dC=a2 - (beta * C) - (Kc * M  * C)
dM= -(gamma) * M + Vm
   
return(list(c(dT,dN,dC,dM)))
  })
}

model2 <- function(t, state2, pars2)
{
  with (as.list(c(state2, pars2)), {
dT=(a*T-a*T*b*T) - (c1*N*T) - (Kt*M*T)
dN=a1 - (f*N) + g * (T/(h+T)) * N - (p * N * T) - (Kn * M * N)
dC=a2 - (beta * C) - (Kc * M  * C)
dM= -(gamma) * M + Vm
   
return(list(c(dT,dN,dC,dM)))
  })
}

### First Half - Tumor growth to 10%
pars <- list( Tini=iniT, Nini=iniN, Mini=iniM, Cini=iniC,
  a=4.31E-3, b=1.02E-14, c1=3.41E-10, Kt=8E-1,
  f=4.12E-2, g=1.5E-2, h=2.02E1, beta=1.20E-2, gamma=9E-1,
  Kc=6E-1, Kn=6E-1, p=2E-11, a1=1.2E4, a2=7.5E8, Vm=0 )

tout<- seq(0, num_days, by=interval_size)
state   <- c(T = pars$Tini, N = pars$Nini, C = pars$Cini, M = pars$Mini)
out <- lsoda(state, tout, model, pars)

## Finding position at which OF function is reached
final_matrix = out;
loopsize = (num_days / interval_size) + 1
OF_tumor_size = iniT + (OF_prcnt * iniT)

## Sentinel Value to find at which row in the matrix reaches OF_tumor_size
OF_row=-1;  
for(i in 1:loopsize) {
  if( out[i,2] >= OF_tumor_size) {
OF_row=i;
break;
  }
}

if(OF_row != -1) {
  ##Params setup
  OF_iniT=out[OF_row,2]; OF_iniN=out[OF_row,3]; OF_iniC=out[OF_row,4];
OF_iniM=out[OF_row,5];
  pars2 <- list( Tini=OF_iniT, Nini=OF_iniN, Mini=OF_iniM, Cini=OF_iniC,
  a=4.31E-3, b=1.02E-14, c1=3.41E-10, Kt=8E-1,
f=4.12E-2, g=1.5E-2, h=2.02E1, beta=1.20E-2, gamma=9E-1,
Kc=6E-1, Kn=6E-1, p=2E-11, a1=1.2E4, a2=7.5E8, Vm=0 )
  state2   <- c(T = pars2$Tini, N = pars2$Nini, C = pars2$Cini, M =
pars2$Mini)
  out2 <- lsoda(state2, tout, model2, pars2)
} 
-- 
View this message in context: 
http://n4.nabble.com/Error-in-eval-expr-envir-enclos-object-N-not-found-tp949512p949512.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] integrate function

2009-12-05 Thread David Winsemius
I did get it to "work" with  Vectorize. My problem was that I don't  
know if the answer made sense because I could not tell what  
mathematical underpinnings were being studied.


--
David.


On Dec 5, 2009, at 10:05 PM, li li wrote:


Thank you all very much!
Yes, f2 is the function I wanted to write. I tried to do use  
"Vectorize" function to f1, it did not work.

> f2 <- function(x)
+  {
+  integrate(Vectorize(f1,vectorize.args =p), lower=0,upper=1, x)
+   }
> f2(c(2,3))
Error in Vectorize(f1, vectorize.args = p) :
  must specify formal argument names to vectorize

I do not quite understand the logic why we need to vectorize here.
2009/12/5 Ravi Varadhan 
Here is how you can do it:


f1 <- function (p,x) {
sapply(p, function(p) prod( p*x+(1-p)*x^2) )  # the function should  
be vectorized for `integrate'

}

 f2 <- function(x) {
integrate(f1, 0, 1, x)$val  # you need to only return the `value' of  
integration

}

f2(x=1:3)

Hope this helps,
Ravi.



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

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


- Original Message -
From: li li 
Date: Saturday, December 5, 2009 7:13 pm
Subject: Re: [R] integrate function
To: David Winsemius 
Cc: r-help@r-project.org


> Thank you very much for your reply!
>  It is not an assignment.
>  What I want to do is what we often do.  If we have a bivariate
> function of x
>  and p,
>  I first fix x and integrate out p. Then the resultant function is
> only in
>  terms of x.
>
>
>  Here f1 is a  bivariate function of x and p.
>  > f1 <- function (p,x)
>  +   {
>  +prod(p*x+(1-p)*x^{2})
>}
>
>  f2 is a function of x only after integrating out p from f1. Here f1
> is the
>  integrand, x is the additional argument to be
>  passed to f1. The integration is in terms of p.
>
>  > f2 <- function(x)
>  + {
>  + integrate(f1, lower=0,upper=1, x)
>  +  }
>  There is error output when I evaluate f2 at specific x values.  
See below:

>
>  > f2(c(2,3))
>  Error in integrate(f1, lower = 0, upper = 1, x) :
>evaluation of function gave a result of wrong length
>  In addition: Warning messages:
>  1: In p * x :
>longer object length is not a multiple of shorter object length
>  2: In (1 - p) * x^{ :
>longer object length is not a multiple of shorter object length
>
>
>  Can any one give me some suggestions! Thank you!
>  2009/12/5 David Winsemius 
>
>  >
>  > On Dec 5, 2009, at 4:59 PM, li li wrote:
>  >
>  > Hello,
>  >>  I have some trouble in terms of using integrate function in R.
>  >>
>  >> f1 is a function of p and x where x is supposed to be a vector.
> (See the
>  >> code).
>  >> Then I want to write function f2 which is a function of the  
vector

>  >> x after I integrate out p.
>  >>  Can some one give me some help? Many thanks!
>  >>Hannah
>  >>
>  >> f1 <- function (p,x)
>  >>>
>  >> +   {
>  >> +y <- p*x+(1-p)*x^{2}
>  >> +   prod(y)
>  >> +   }
>  >>
>  >>>
>  >>> f2 <- function(x)
>  >>>
>  >> + {
>  >> + integrate(f1, 0,1, x)
>  >>
>  >
>  > Just looking at the help page for integrate makes me wonder what
> you are
>  > doing. There are 3 named arguments before the dots, so 0 and 1  
will

> become
>  > "lower" and "upper", while x is not among the named arguemnts,  
so I

> suppose
>  > x will go to f1 as "p". But f1 takes two arguments, so where will
> it get the
>  > second argument? Maybe if you would tell us a bit more about why
> you made
>  > those functions the way you did, it would help. I am guessing  
it's

> classwork
>  > but perhaps not.
>  >
>  >
>  > +  }
>  >>
>  >> f2(x=c(1,2))
>  >>>
>  >> Error in integrate(f1, 0, 1, x) :
>  >>  evaluation of function gave a result of wrong length
>  >> In addition: Warning messages:
>  >> 1: In p * x :
>  >>  longer object length is not a multiple of shorter object length
>  >> 2: In (1 - p) * x^{ :
>  >>  longer object length is not a multiple of shorter object length
>  >>
>  >>[[alternative HTML version deleted]]
>  >>
>  >
>  > --
>  >
>  > David Winsemius, MD
>  > Heritage Laboratories
>  > West Hartford, CT
>  >
>  >
>
>   [[alternative HTML version deleted]]
>
>  __
>  R-help@r-project.org mailing list
>
>  PLEASE do read the posting guide
>  and provide commented, minimal, self-contained, reproducible code.



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] integrate function

2009-12-05 Thread li li
Thank you all very much!
Yes, f2 is the function I wanted to write. I tried to do use "Vectorize"
function to f1, it did not work.
> f2 <- function(x)
+  {
+  integrate(Vectorize(f1,vectorize.args =p), lower=0,upper=1, x)
+   }
> f2(c(2,3))
Error in Vectorize(f1, vectorize.args = p) :
  must specify formal argument names to vectorize

I do not quite understand the logic why we need to vectorize here.
2009/12/5 Ravi Varadhan 

> Here is how you can do it:
>
>
> f1 <- function (p,x) {
> sapply(p, function(p) prod( p*x+(1-p)*x^2) )  # the function should be
> vectorized for `integrate'
> }
>
>  f2 <- function(x) {
> integrate(f1, 0, 1, x)$val  # you need to only return the `value' of
> integration
> }
>
> f2(x=1:3)
>
> Hope this helps,
> Ravi.
>
> 
>
> Ravi Varadhan, Ph.D.
> Assistant Professor,
> Division of Geriatric Medicine and Gerontology
> School of Medicine
> Johns Hopkins University
>
> Ph. (410) 502-2619
> email: rvarad...@jhmi.edu
>
>
> - Original Message -
> From: li li 
> Date: Saturday, December 5, 2009 7:13 pm
> Subject: Re: [R] integrate function
> To: David Winsemius 
> Cc: r-help@r-project.org
>
>
> > Thank you very much for your reply!
> >  It is not an assignment.
> >  What I want to do is what we often do.  If we have a bivariate
> > function of x
> >  and p,
> >  I first fix x and integrate out p. Then the resultant function is
> > only in
> >  terms of x.
> >
> >
> >  Here f1 is a  bivariate function of x and p.
> >  > f1 <- function (p,x)
> >  +   {
> >  +prod(p*x+(1-p)*x^{2})
> >}
> >
> >  f2 is a function of x only after integrating out p from f1. Here f1
> > is the
> >  integrand, x is the additional argument to be
> >  passed to f1. The integration is in terms of p.
> >
> >  > f2 <- function(x)
> >  + {
> >  + integrate(f1, lower=0,upper=1, x)
> >  +  }
> >  There is error output when I evaluate f2 at specific x values. See
> below:
> >
> >  > f2(c(2,3))
> >  Error in integrate(f1, lower = 0, upper = 1, x) :
> >evaluation of function gave a result of wrong length
> >  In addition: Warning messages:
> >  1: In p * x :
> >longer object length is not a multiple of shorter object length
> >  2: In (1 - p) * x^{ :
> >longer object length is not a multiple of shorter object length
> >
> >
> >  Can any one give me some suggestions! Thank you!
> >  2009/12/5 David Winsemius 
> >
> >  >
> >  > On Dec 5, 2009, at 4:59 PM, li li wrote:
> >  >
> >  > Hello,
> >  >>  I have some trouble in terms of using integrate function in R.
> >  >>
> >  >> f1 is a function of p and x where x is supposed to be a vector.
> > (See the
> >  >> code).
> >  >> Then I want to write function f2 which is a function of the vector
> >  >> x after I integrate out p.
> >  >>  Can some one give me some help? Many thanks!
> >  >>Hannah
> >  >>
> >  >> f1 <- function (p,x)
> >  >>>
> >  >> +   {
> >  >> +y <- p*x+(1-p)*x^{2}
> >  >> +   prod(y)
> >  >> +   }
> >  >>
> >  >>>
> >  >>> f2 <- function(x)
> >  >>>
> >  >> + {
> >  >> + integrate(f1, 0,1, x)
> >  >>
> >  >
> >  > Just looking at the help page for integrate makes me wonder what
> > you are
> >  > doing. There are 3 named arguments before the dots, so 0 and 1 will
> > become
> >  > "lower" and "upper", while x is not among the named arguemnts, so I
> > suppose
> >  > x will go to f1 as "p". But f1 takes two arguments, so where will
> > it get the
> >  > second argument? Maybe if you would tell us a bit more about why
> > you made
> >  > those functions the way you did, it would help. I am guessing it's
> > classwork
> >  > but perhaps not.
> >  >
> >  >
> >  > +  }
> >  >>
> >  >> f2(x=c(1,2))
> >  >>>
> >  >> Error in integrate(f1, 0, 1, x) :
> >  >>  evaluation of function gave a result of wrong length
> >  >> In addition: Warning messages:
> >  >> 1: In p * x :
> >  >>  longer object length is not a multiple of shorter object length
> >  >> 2: In (1 - p) * x^{ :
> >  >>  longer object length is not a multiple of shorter object length
> >  >>
> >  >>[[alternative HTML version deleted]]
> >  >>
> >  >
> >  > --
> >  >
> >  > David Winsemius, MD
> >  > Heritage Laboratories
> >  > West Hartford, CT
> >  >
> >  >
> >
> >   [[alternative HTML version deleted]]
> >
> >  __
> >  R-help@r-project.org mailing list
> >
> >  PLEASE do read the posting guide
>  >  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] integrate function

2009-12-05 Thread Ravi Varadhan
Here is how you can do it:


f1 <- function (p,x) {
sapply(p, function(p) prod( p*x+(1-p)*x^2) )  # the function should be 
vectorized for `integrate'
}

 f2 <- function(x) {
integrate(f1, 0, 1, x)$val  # you need to only return the `value' of integration
}

f2(x=1:3)

Hope this helps,
Ravi.



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

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


- Original Message -
From: li li 
Date: Saturday, December 5, 2009 7:13 pm
Subject: Re: [R] integrate function
To: David Winsemius 
Cc: r-help@r-project.org


> Thank you very much for your reply!
>  It is not an assignment.
>  What I want to do is what we often do.  If we have a bivariate 
> function of x
>  and p,
>  I first fix x and integrate out p. Then the resultant function is 
> only in
>  terms of x.
>  
>  
>  Here f1 is a  bivariate function of x and p.
>  > f1 <- function (p,x)
>  +   {
>  +prod(p*x+(1-p)*x^{2})
>}
>  
>  f2 is a function of x only after integrating out p from f1. Here f1 
> is the
>  integrand, x is the additional argument to be
>  passed to f1. The integration is in terms of p.
>  
>  > f2 <- function(x)
>  + {
>  + integrate(f1, lower=0,upper=1, x)
>  +  }
>  There is error output when I evaluate f2 at specific x values. See below:
>  
>  > f2(c(2,3))
>  Error in integrate(f1, lower = 0, upper = 1, x) :
>evaluation of function gave a result of wrong length
>  In addition: Warning messages:
>  1: In p * x :
>longer object length is not a multiple of shorter object length
>  2: In (1 - p) * x^{ :
>longer object length is not a multiple of shorter object length
>  
>  
>  Can any one give me some suggestions! Thank you!
>  2009/12/5 David Winsemius 
>  
>  >
>  > On Dec 5, 2009, at 4:59 PM, li li wrote:
>  >
>  > Hello,
>  >>  I have some trouble in terms of using integrate function in R.
>  >>
>  >> f1 is a function of p and x where x is supposed to be a vector. 
> (See the
>  >> code).
>  >> Then I want to write function f2 which is a function of the vector
>  >> x after I integrate out p.
>  >>  Can some one give me some help? Many thanks!
>  >>Hannah
>  >>
>  >> f1 <- function (p,x)
>  >>>
>  >> +   {
>  >> +y <- p*x+(1-p)*x^{2}
>  >> +   prod(y)
>  >> +   }
>  >>
>  >>>
>  >>> f2 <- function(x)
>  >>>
>  >> + {
>  >> + integrate(f1, 0,1, x)
>  >>
>  >
>  > Just looking at the help page for integrate makes me wonder what 
> you are
>  > doing. There are 3 named arguments before the dots, so 0 and 1 will 
> become
>  > "lower" and "upper", while x is not among the named arguemnts, so I 
> suppose
>  > x will go to f1 as "p". But f1 takes two arguments, so where will 
> it get the
>  > second argument? Maybe if you would tell us a bit more about why 
> you made
>  > those functions the way you did, it would help. I am guessing it's 
> classwork
>  > but perhaps not.
>  >
>  >
>  > +  }
>  >>
>  >> f2(x=c(1,2))
>  >>>
>  >> Error in integrate(f1, 0, 1, x) :
>  >>  evaluation of function gave a result of wrong length
>  >> In addition: Warning messages:
>  >> 1: In p * x :
>  >>  longer object length is not a multiple of shorter object length
>  >> 2: In (1 - p) * x^{ :
>  >>  longer object length is not a multiple of shorter object length
>  >>
>  >>[[alternative HTML version deleted]]
>  >>
>  >
>  > --
>  >
>  > David Winsemius, MD
>  > Heritage Laboratories
>  > West Hartford, CT
>  >
>  >
>  
>   [[alternative HTML version deleted]]
>  
>  __
>  R-help@r-project.org mailing list
>  
>  PLEASE do read the posting guide 
>  and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] SAS "datalines" or "cards" statement equivalent in R?

2009-12-05 Thread Jorge Ivan Velez
Dear Gary,

Here is a suggestion using read.table() and textConnection():

toread <- "id sex age inc r1 r2 r3
1  F  35 17  7 2 2
17  M  50 14  5 5 3
33  F  45  6  7 2 7
49  M  24 14  7 5 7
65  F  52  9  4 7 7
81  M  44 11  7 7 7
2   F  34 17  6 5 3
18  M  40 14  7 5 2
34  F  47  6  6 5 6
50  M  35 17  5 7 5"

survey <- read.table(textConnection(toread), header = TRUE)
closeAllConnections()
survey

See ?read.table and ?textConnection for more information.

HTH,
Jorge


On Sat, Dec 5, 2009 at 8:11 PM, Gary Miller <> wrote:

> Hi R Users,
>
> Is there a equivalent command in R where I can read in raw data? For
> example
> I'm looking for equivalent R code for following SAS code:
>
> DATA survey;
>   INPUT id sex $ age inc r1 r2 r3 ;
>   DATALINES;
>  1  F  35 17  7 2 2
> 17  M  50 14  5 5 3
> 33  F  45  6  7 2 7
> 49  M  24 14  7 5 7
> 65  F  52  9  4 7 7
> 81  M  44 11  7 7 7
> 2   F  34 17  6 5 3
> 18  M  40 14  7 5 2
> 34  F  47  6  6 5 6
> 50  M  35 17  5 7 5
> ;
>
> Any help would be highly appreciated,
> Gary
>
>[[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] SAS "datalines" or "cards" statement equivalent in R?

2009-12-05 Thread Gary Miller
Hi R Users,

Is there a equivalent command in R where I can read in raw data? For example
I'm looking for equivalent R code for following SAS code:

DATA survey;
   INPUT id sex $ age inc r1 r2 r3 ;
   DATALINES;
 1  F  35 17  7 2 2
17  M  50 14  5 5 3
33  F  45  6  7 2 7
49  M  24 14  7 5 7
65  F  52  9  4 7 7
81  M  44 11  7 7 7
2   F  34 17  6 5 3
18  M  40 14  7 5 2
34  F  47  6  6 5 6
50  M  35 17  5 7 5
;

Any help would be highly appreciated,
Gary

[[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] barchart() {lattice} help.

2009-12-05 Thread Peng Cai
Hi,

I'm plotting grouped barplot using following code and data. I need help with
re-ordering the labels.

1. On x-axis the factor "AGE" is grouped in order "0--4", "15--18", "5--14";
whereas I would like to have it in "0--4", "5--14", "15--18".

2. If I need to re-order "RACE" variable. How can I do it assuming I need to
change it on both the x-axis and legend. Currenlty the order is
"Black","Other","White"; whereas I would like "White", "Black", "Other".

Can anyone help please. I'm using following code, which is working fine
except above issues.

Code:

library(lattice)

### assuming data is read in object name "dta".
attach(dta)
barchart(sum ~ age | gender, data = dta,
groups = race,
  stack = FALSE,
  ylab="Sum of admissions over 10 years (1996-2005)",
  xlab="Age",
  par.settings=simpleTheme(col = c("green1", "yellow1", "orange")),
  key=list(space="right", cex=1,
  text=list(c("Black","Other","White")),
  rectangles=list(size=1.7, border="white", col = c("green1", "yellow1",
"orange"))),
  strip = strip.custom(bg="greenyellow")
)
detach(dta)

Data:
age gender  race sum
0--4 Female Black 145
0--4 Female Other  53
0--4 Female White  47
0--4   Male Black 286
0--4   Male Other 130
0--4   Male White  94
15--18 Female Black  30
15--18 Female Other   3
15--18 Female White   9
15--18   Male Black  21
15--18   Male Other   2
15--18   Male White   3
5--14 Female Black 138
5--14 Female Other  31
5--14 Female White  23
5--14   Male Black 199
5--14   Male Other  65
5--14   Male White  29

Thanks,
Peng

[[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] STATISTICAL ANALYSIS OF TEXT EMAILS Re: Refreshments after SOMS Seminar Friday 3:30-4:30 in HBB 334

2009-12-05 Thread ajay ohri
Dear Professor Frank Guess,

Why did you call me a Curious George?

What is a curious george as in American context?

Why did you address this email only to Laura and me.

Why did you not answer my early query on what is a curious George?

Why do you also send me emails saying I and Gandhi are full of compassion?



How come University of Tennessee is funded by Federal Bailout Funds AND has
a row of churches just behind the HODGES library and so accessible to
CHRISTIAN students

BUT NO temples or mosques near to Library.

We are children of a lesser God

But we are also children.

Thanks and Have a Happy Holidays and Merry Christmas.
*
WHY DO YOU SAY you may have one of those emails> and better not to use?*

AJAY

Graduate Student
University of Tennessee, Knoxville.


Go Vols!

Websites-
http://decisionstats.com
http://dudeofdata.com
http://prayers2go.com

Linkedin- www.linkedin.com/in/ajayohri
Facebook-www.facebook.com/ajayohri
Twitter-www.twitter.com/dudeofdata

Quote for the Day-
Mike Ditka  - "If God had wanted man to play soccer, he wouldn't have given
us arms." - http://www.brainyquote.com/quotes/authors/m/mike_ditka.html


On Thu, Sep 24, 2009 at 3:46 PM, Guess, Frank M  wrote:
> Thanks Laura, great email. Ajay is just a curious George on understanding
> better.
>
> Thanks Ajay, also.
>
> We are blessed to have both of you here at UT!!
>
> Best to all,
> Dr. Guess
>
>
> (Ajay, I may have one of these email, best not to use, which is it?)
> 
> From: Brewster, Laura
> Sent: Thu 9/24/2009 3:09 PM
> To: Beal, Dennis Jack; Carty, Dillon M; Cinder, Matthew Robert; Duraisamy,
> Praveen Raja; Erar, Bahar; Ezell, Ashley Renee; Fajolu, Olufemi Nelson;
> fjiang6; Harper, Matt (Matt); Huang, Xia; Jarajapu, Neeharika; Jeong,
> Jaehwan; Kim, Je Guk; Kitchens, Karin Elizabeth; Kodra, Evan Anton; Kuang,
> Xun; lge; Liu, Nancy; Loghavi, Mina; Lu, Xin (Lucy); Mathias, Blake
Dustin;
> Mcclary, Erica Whitney; Muindi, Pius Matheka; Ohri, Ajay; Pan, Chun;
Pannell
> Jr, T Allen (Allen); Robson, Paul Andrew; Romanova, Anna V; Roth, Wendy;
> Shah, Reshma; Shipman, Michael Livingston; Turan, Esra; Vepkhvadze, Nana;
> Wang, Wenfang; Wang, Yingjin; Weese, Maria L; White, Philip Robert;
> Williams, Maria Annette; Wu, Wei; Xu, Liang; Xu, Qin; Zeng, Yan; Zhang,
> Shuping; Zhao, Yijia; Moser, Jane; Walker, Rebecca M (Becky); Bichescu,
> Bogdan Cristian; Edirisinghe, Nalin C P; Bowers, Melissa R; Noon, Charles
E;
> Srinivasan, Mandyam M; js...@arcautomotive.com; Kirby, Kenneth E;
Bozdogan,
> Hamparsum; Cwiek, Charles Mitchell; Gilbert, Kenneth C; Guess, Frank M;
> Leitnaker, Mary G; Leon, Ramon V; Mee, Robert W; Petrie, Adam George;
> Zaretzki, Russell Lee; Schmidhammer, James L; Seaver, William L; Younger,
> Mary Sue
> Subject: Refreshments after SOMS Seminar Friday 3:30-4:30 in HBB 334
>
> Everyone,
>
>
>
> Directly after Maria Weese’s seminar tomorrow, we will meet in HBB 334 for
> light refreshments and stimulating conversation.  I hope you’ll join us!
> Remember, the actual seminar is in HBB 403 from 2:30-3:30.
>
>
>
> Laura Brewster
>
> Administrative Assistant
>
> Department of Statistics, Operations
>
> and Management Science
>
> 344A Stokely Management Center
>
> Knoxville, TN 37996-0532
>
> (865) 974-5544
>
> (865) 974-2490 (fax)
>
>

[[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] integrate function

2009-12-05 Thread li li
Thank you very much for your reply!
It is not an assignment.
What I want to do is what we often do.  If we have a bivariate function of x
and p,
I first fix x and integrate out p. Then the resultant function is only in
terms of x.


Here f1 is a  bivariate function of x and p.
> f1 <- function (p,x)
+   {
+prod(p*x+(1-p)*x^{2})
  }

f2 is a function of x only after integrating out p from f1. Here f1 is the
integrand, x is the additional argument to be
passed to f1. The integration is in terms of p.

> f2 <- function(x)
+ {
+ integrate(f1, lower=0,upper=1, x)
+  }
There is error output when I evaluate f2 at specific x values. See below:

> f2(c(2,3))
Error in integrate(f1, lower = 0, upper = 1, x) :
  evaluation of function gave a result of wrong length
In addition: Warning messages:
1: In p * x :
  longer object length is not a multiple of shorter object length
2: In (1 - p) * x^{ :
  longer object length is not a multiple of shorter object length


Can any one give me some suggestions! Thank you!
2009/12/5 David Winsemius 

>
> On Dec 5, 2009, at 4:59 PM, li li wrote:
>
> Hello,
>>  I have some trouble in terms of using integrate function in R.
>>
>> f1 is a function of p and x where x is supposed to be a vector. (See the
>> code).
>> Then I want to write function f2 which is a function of the vector
>> x after I integrate out p.
>>  Can some one give me some help? Many thanks!
>>Hannah
>>
>> f1 <- function (p,x)
>>>
>> +   {
>> +y <- p*x+(1-p)*x^{2}
>> +   prod(y)
>> +   }
>>
>>>
>>> f2 <- function(x)
>>>
>> + {
>> + integrate(f1, 0,1, x)
>>
>
> Just looking at the help page for integrate makes me wonder what you are
> doing. There are 3 named arguments before the dots, so 0 and 1 will become
> "lower" and "upper", while x is not among the named arguemnts, so I suppose
> x will go to f1 as "p". But f1 takes two arguments, so where will it get the
> second argument? Maybe if you would tell us a bit more about why you made
> those functions the way you did, it would help. I am guessing it's classwork
> but perhaps not.
>
>
> +  }
>>
>> f2(x=c(1,2))
>>>
>> Error in integrate(f1, 0, 1, x) :
>>  evaluation of function gave a result of wrong length
>> In addition: Warning messages:
>> 1: In p * x :
>>  longer object length is not a multiple of shorter object length
>> 2: In (1 - p) * x^{ :
>>  longer object length is not a multiple of shorter object length
>>
>>[[alternative HTML version deleted]]
>>
>
> --
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>

[[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] Forest Plot

2009-12-05 Thread Xin Ge
Thanks for your reply. Which function I should explore in "metafor" package
for this kind of plot.

Also I have to do a forest plot for "regressions estimates" (betas) and
corresponding "sqrt(var)". I hope in this case there is no difference
between std. error and std. deviation? So, a 95% confidence interval would
be [estimate +/- 1.96*sqrt(variance of estimate)]. Am I correct in saying
this?

Thanks again,
Xin

On Sat, Dec 5, 2009 at 6:21 PM, Viechtbauer Wolfgang (STAT) <
wolfgang.viechtba...@stat.unimaas.nl> wrote:

> The figure that you linked to was produced with the "metafor" package. It
> can also be used to produce a forest plot if you have means and
> corresponding standard errors of the means. The standard error of a mean is
> equal to SD / sqrt(n), so as long as you also know the sample sizes (n), you
> can convert those standard deviations to the standard errors.
>
> Best,
>
> --
> Wolfgang Viechtbauerhttp://www.wvbauer.com/
> Department of Methodology and StatisticsTel: +31 (0)43 388-2277
> School for Public Health and Primary Care   Office Location:
> Maastricht University, P.O. Box 616 Room B2.01 (second floor)
> 6200 MD Maastricht, The Netherlands Debyeplein 1 (Randwyck)
> 
> From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On
> Behalf Of Xin Ge [xingemaill...@gmail.com]
> Sent: Sunday, December 06, 2009 12:11 AM
> To: r-help@r-project.org
> Subject: [R] Forest Plot
>
> Hi All,
>
> I want to produce a similar "Forest Plot" as it is on the following link,
> but my data would be having only two columns (one for "Estimate" and other
> for "Std. Dev"). Can anyone suggest some function() {Package} which can
> take
> such file as an input and give following forest plot:
>
>
> http://bm2.genes.nig.ac.jp/RGM2/R_current/library/metafor/man/images/big_plot.rma.uni_001.png
>
> Thanks,
> Xin
>
>[[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.
>

[[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] Forest Plot

2009-12-05 Thread Viechtbauer Wolfgang (STAT)
The figure that you linked to was produced with the "metafor" package. It can 
also be used to produce a forest plot if you have means and corresponding 
standard errors of the means. The standard error of a mean is equal to SD / 
sqrt(n), so as long as you also know the sample sizes (n), you can convert 
those standard deviations to the standard errors.

Best,

--
Wolfgang Viechtbauerhttp://www.wvbauer.com/
Department of Methodology and StatisticsTel: +31 (0)43 388-2277
School for Public Health and Primary Care   Office Location:
Maastricht University, P.O. Box 616 Room B2.01 (second floor)
6200 MD Maastricht, The Netherlands Debyeplein 1 (Randwyck)

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
Xin Ge [xingemaill...@gmail.com]
Sent: Sunday, December 06, 2009 12:11 AM
To: r-help@r-project.org
Subject: [R] Forest Plot

Hi All,

I want to produce a similar "Forest Plot" as it is on the following link,
but my data would be having only two columns (one for "Estimate" and other
for "Std. Dev"). Can anyone suggest some function() {Package} which can take
such file as an input and give following forest plot:

http://bm2.genes.nig.ac.jp/RGM2/R_current/library/metafor/man/images/big_plot.rma.uni_001.png

Thanks,
Xin

[[alternative HTML version deleted]]

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


[R] Forest Plot

2009-12-05 Thread Xin Ge
Hi All,

I want to produce a similar "Forest Plot" as it is on the following link,
but my data would be having only two columns (one for "Estimate" and other
for "Std. Dev"). Can anyone suggest some function() {Package} which can take
such file as an input and give following forest plot:

http://bm2.genes.nig.ac.jp/RGM2/R_current/library/metafor/man/images/big_plot.rma.uni_001.png

Thanks,
Xin

[[alternative HTML version deleted]]

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


Re: [R] R packages and assess to data in packages

2009-12-05 Thread Sharpie


Tariq Perwez wrote:
> 
> Hi Everyone,
> 
> I have two very basic questions and would appreciate your help.
> 1. I would like to see/access the data that comes with a given R package
> by
> using a function like read.table(). For example, I just installed car
> package from CRAN. I know that somewhere within the package, there is
> Duncan.txt file. 
> 

This is not necessarily true.  Most packages distribute data sets in the
.rda format.  Text files are usually only distributed if the package
implements some method of parsing them, such as the example .xml files in
the XML package.



Tariq Perwez wrote:
> 
> I would not only like to look at it from file browser (or
> using ls command in shell)  but also to access it as:
> 
>> Duncan <- read.table("path/to/data/Duncan.txt", header = T)
> 
> I can certainly use:
> 
>> data(Duncan)
> 
> and
> 
>> attach(Duncan)
> 
> after loading the package car. However, I would like to see all the data
> that come with a package as separate files. Where are these files located?
> I
> installed the car package under Mac OSX  under the user level (if this
> detail is important). However, I do use R under Ubuntu linux also and
> general solution to this problem will be great. 
> 

The system.file() command provides a platform-independent method for
recovering the path to files distributed in packages.  For example, to list
all files in the "data" folder of the car package:

  system.file( 'data', package = 'car' )

To get the path to the .rda file containing all the datasets:

  system.file( 'data', 'Rdata.rda', package = 'car' )


Tariq Perwez wrote:
> 
> I even downloaded the car binaries and unpacked the zipped file on desktop
> but I just see .rda files
> within the data folder; there are no .txt files anywhere.  I do see
> Duncan.rda file (I believe this contains the Duncan.txt data). How can I
> access the data files from such package, say using a text editor??
> 

Package datasets are usually only distributed as binary .Rda files.  If you
want to view them using a text editor you will have to translate them to a
plain text format-- something like load() followed by write.csv().



Tariq Perwez wrote:
> 
> 2. What is the safest/preferred place to install an R package that I want
> to
> delete/remove once I do not need it. Sometimes, I just need to install a
> package from a book's website so that I can work on the exercises etc but
> do
> not need the package permanently hanging around. Removing such a package
> and
> all the associated files etc would be nice.
> 
> I would appreciate any help and comments on my questions. Regards,
> 
> Tariq
> 

Just install it normally.  You can remove it by running:

  R CMD REMOVE packageName

>From the command line.

Hope this helps!

-Charlie

-- 
View this message in context: 
http://n4.nabble.com/R-packages-and-assess-to-data-in-packages-tp949415p949439.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] plot data from tapply

2009-12-05 Thread dwwc

i have three data, x coordinate, y coordinate and  signal strength

i use tapply() function to get the average ss in the give x,y location
 x=c(1,2,3,1)
 y=c(1,2,3,1)
 ss=c(55,NA,55,88)
  ss_byxy_test=tapply(  ss, list( x, y), mean)
and I get this table
 1  2  3
1 71.5 NA NA
2   NA NA NA
3   NA NA 55
but i don't know how to plot different the ss with the xy location,
can anyone help me
-- 
View this message in context: 
http://n4.nabble.com/plot-data-from-tapply-tp949436p949436.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] Announcing a new R news site: R-bloggers.com

2009-12-05 Thread Tal Galili
Hi Romain,
First - I'd like to say that you where one of the bloggers I wanted to
e-mail and didn't get to it. I still remember our short session in useR 2009
where you showed me your plans for an R editor - I am still waiting to see
it once it comes out.

Regarding the rest of what you wrote, I'll reply to you in each section:


On Sun, Dec 6, 2009 at 3:22 AM, Romain Francois 
wrote:

On 12/05/2009 09:32 PM, Tal Galili wrote:



1) Planet R is limited (for years) to 26 feeds only, and I don't remember
seeing it evolve to include (or allow inclusion) of new R blogs that came
around.

R: that's not quite true. If you send an email to the maintainer of planet
R, he will add your feed (both my blog and r graph gallery was added this
year for example).

T:Thanks for the correction. Yet let's put this in context - I can't see on
the planetR website (http://planetr.stderr.org/) any e-mail or link to
contact. So for me, for example, I don't know how to add my own blog (What
IS the e-mail of the maintainer ?)


2) The feeds are of blogs and non blogs (such as wiki or cran updates). That
makes finding "reading material" inside it very difficult, since the site is
cluttered with a lot of "updates" from cranbarries and the wiki.
R: I see this as a good thing. In the program i use to read planet R
(thunderbird) you can filter out things you are not interested about.

T: But Romain, both planetR and R-bloggers are not meant for you, except as
a source for feeds. What you are saying is that you don't use the interface
either website offers, which is exactly my point.

R: I have requested to be added to yours anyway, might be good for my
pagerank.
T: Cool, I just added you.

[[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] Announcing a new R news site: R-bloggers.com

2009-12-05 Thread Daniel Nordlund
I don’t have comments as yet, because I didn’t stay around the site too 
long.  I will go back and look at it using a spare Ubuntu box and let you know 
what I think.

 

Dan

 

Daniel Nordlund

Bothell, WA USA

 

 

  _  

From: Tal Galili [mailto:tal.gal...@gmail.com] 
Sent: Saturday, December 05, 2009 1:24 PM
To: Daniel Nordlund
Cc: r-help@r-project.org
Subject: Re: [R] Announcing a new R news site: R-bloggers.com

 

Hi Daniel.

 

In short: no.

 

In more words:

1) I have zone alarm also on my computer and it gives me no warnings.

2) The only two external scripts the site has are of "woopra" and "google 
analytics", both are known external statistics services.

3) It could be (although not likely) that the site is hacked and was injected 
with something, but services like this one:

http://www.unmaskparasites.com/security-report/

claims that my site is clean.

 

If you have anymore suggestions - I would love to know them.

 

Thanks for reporting, what do you think of the site itself BTW?

 

Best,

Tal

 

 

 




Contact 
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | 
www.r-statistics.com/ (English)
--





On Sat, Dec 5, 2009 at 11:04 PM, Daniel Nordlund  wrote:



> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Tal Galili
> Sent: Saturday, December 05, 2009 11:38 AM
> To: r-help@r-project.org
> Subject: [R] Announcing a new R news site: R-bloggers.com
>
> Hello everyone.
> After some good time of work, I am proud to present: www.r-bloggers.com
>
> What is R-Bloggers.com?
>
> R-Bloggers.com hopes to serve the R community by presenting (in one place)
> all the new articles (posts) written (in English) about R in the "R
> blogosphere".
> How does R-Bloggers operate?
>
> This site aggregates feeds (only with permission!) from participating R
> blogs. The beginnings of each participating blog s posts will
> automatically
> be displayed on the main page with links to the original posts; inside
> every
> post there is a link to the original blog and links to other related
> articles.  All participating blogs will have links in the  Contributors
> section of our sidebar
> What does R-Bloggers offer the community?
>
>- Discover: If every blogger will add itself, we will all be able to
> find
>new R blogs (which is hard to find on the web, if you ever tried). The
>site also allows to search in the content of the bloggers (although for
>searches of older content - you better go to the blogs themselves or
> wait
>for the customized google search box I will add in the future)
>- Follow: Enter your e-mail and subscribe to receive a daily digest
> with
>teasers of new posts from participating blogs.  You will more easily
> get a
>sense of hot topics in the R blogosphere.
>- Connect: Click on  Fan this site  to become a "fan" of R Bloggers.
> You
>can  friend  other people and share thoughts on our wall. Or just by
> leaving
>comments on the blog.
>- Participate: Add your R blog to get increased visibility (for readers
>and search engines) with permanent links on our Contributors sidebar.
> Your
>blog will also gain visibility via our e-mail digest and through your
>presence on the main page with posts.
>
> How do I become a participating blog in R Bloggers?
>
> To add your blog, simply click on Add your

> blog! and

> enter the required information.  I will review your link and approve it in
> a
> timely fashion.
> How can I help?
>
> We share readers to gain readers!  If you are interested and haven t

> already, please submit your blog  blog/>.
>  Also please consider putting *a link from your blog* to R-Bloggers from
> your sidebar (we do the same for you); you can even put up a post about us
> -
> if each blogger will do so - all of us will gain from it.
>  Who started R-Bloggers (and way)?
>

> R Bloggers was started by Tal Galili . After

> searching for numerous R blogs, Tal (well, me) decided that there must be
> more R blogs our there then he knows about, and maybe the best way for
> finding them is to make them find him. You can reach Tal via the

> Contact page

> (or just e-mail him: tal.gal...@gmail.com).
> Extra thanks and a deceleration of "good intentions"
> I would like to thank John, Yihui, Jaanus and Taiyun for being the first
> bloggers to allow me to enlist their blogs to the project.
> There are more R bloggers out there that I know of, and didn't get to ask
> for permission. I apologies to you for not contacting you personally,
> still
> If you are one such b

Re: [R] integrate function

2009-12-05 Thread David Winsemius


On Dec 5, 2009, at 4:59 PM, li li wrote:


Hello,
  I have some trouble in terms of using integrate function in R.

f1 is a function of p and x where x is supposed to be a vector. (See  
the

code).
Then I want to write function f2 which is a function of the vector
x after I integrate out p.
 Can some one give me some help? Many thanks!
Hannah


f1 <- function (p,x)

+   {
+y <- p*x+(1-p)*x^{2}
+   prod(y)
+   }


f2 <- function(x)

+ {
+ integrate(f1, 0,1, x)


Just looking at the help page for integrate makes me wonder what you  
are doing. There are 3 named arguments before the dots, so 0 and 1  
will become "lower" and "upper", while x is not among the named  
arguemnts, so I suppose x will go to f1 as "p". But f1 takes two  
arguments, so where will it get the second argument? Maybe if you  
would tell us a bit more about why you made those functions the way  
you did, it would help. I am guessing it's classwork but perhaps not.




+  }

f2(x=c(1,2))

Error in integrate(f1, 0, 1, x) :
 evaluation of function gave a result of wrong length
In addition: Warning messages:
1: In p * x :
 longer object length is not a multiple of shorter object length
2: In (1 - p) * x^{ :
 longer object length is not a multiple of shorter object length

[[alternative HTML version deleted]]


--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


[R] integrate function

2009-12-05 Thread li li
Hello,
   I have some trouble in terms of using integrate function in R.

f1 is a function of p and x where x is supposed to be a vector. (See the
code).
Then I want to write function f2 which is a function of the vector
 x after I integrate out p.
  Can some one give me some help? Many thanks!
 Hannah

> f1 <- function (p,x)
+   {
+y <- p*x+(1-p)*x^{2}
+   prod(y)
+   }
>
> f2 <- function(x)
+ {
+ integrate(f1, 0,1, x)
+  }
> f2(x=c(1,2))
Error in integrate(f1, 0, 1, x) :
  evaluation of function gave a result of wrong length
In addition: Warning messages:
1: In p * x :
  longer object length is not a multiple of shorter object length
2: In (1 - p) * x^{ :
  longer object length is not a multiple of shorter object length

[[alternative HTML version deleted]]

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


[R] R example for ancova

2009-12-05 Thread syrvn

Hi list,

does anybody know a easy to understand example in R which shows how to
perfom an ANCOVA?
I already tried to understand the example which you get when you type ?aov,
but I did not really
understand the output.


Best,
syrvn

-- 
View this message in context: 
http://n4.nabble.com/R-example-for-ancova-tp949324p949324.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] Incorrect number of dimensions

2009-12-05 Thread Sarah

I am trying to fit a linear model with seasonal effects but keep getting
'Incorrect number of dimensions'.  I have no idea what this means or how to
fix it.  I am following instructions received from an instructor and it
worked for him, so I assume it has something to do with my data.  Here is my
code:

sed<-ts(data2[,-c(1,2)],start=c(1967,10),end=c(2007,9),freq=12)
ym<-time(sed)
month<-as.factor(sed[,"Period"])
  Error in `[.default`(sed, , "Period") : incorrect number of dimensions

So I am getting the error when I try to designate month as a factor.

Help!
-- 
View this message in context: 
http://n4.nabble.com/Incorrect-number-of-dimensions-tp949301p949301.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] Announcing a new R news site: R-bloggers.com

2009-12-05 Thread Romain Francois

On 12/05/2009 09:32 PM, Tal Galili wrote:


Hi Dirk,

I wish to emphasis that I came across PlanetR over a year ago,
but completely forgot it existed when working on R-bloggers. Also, when I
contacted the bloggers about this idea, non of them actually wrote to me
about it (which makes me feel better about not remembering it). I apologies
if setting up R-bloggers seems like trying to "compete" with PlanetR, this
at all wasn't my intention.
Yet, now that my website is up, I hope it will be of use and here
are several ways in which (at hindsight) I can say it has something to
offer:

1) Planet R is limited (for years) to 26 feeds only, and I don't remember
seeing it evolve to include (or allow inclusion) of new R blogs that came
around.


That's not quite true. If you send an email to the maintainer of planet 
R, he will add your feed (both my blog and r graph gallery was added 
this year for example).



2) The feeds are of blogs and non blogs (such as wiki or cran updates). That
makes finding "reading material" inside it very difficult, since the site is
cluttered with a lot of "updates" from cranbarries and the wiki.


I see this as a good thing. In the program i use to read planet R 
(thunderbird) you can filter out things you are not interested about.


I have requested to be added to yours anyway, might be good for my pagerank.


3) In PlanetR, one can only view (about) 5 days back and no more (R-bloggers
allows viewing of much more then 5 days back).
4) R-bloggers allows searching inside the content, PlanetR doesn't.
5) R-bloggers allow one to get e-mail updates, PlanetR doesn't.
6) R-bloggers offers "related articles", PlanetR doesn't.

I see R-bloggers  as a "news site" based on the
R bloggers, and I can't say the same about PlanetR for the reasons I gave
above.


With much respect to you Dirk,
Tal






Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com/ (English)
--




On Sat, Dec 5, 2009 at 9:59 PM, Dirk Eddelbuettel  wrote:



On 5 December 2009 at 21:38, Tal Galili wrote:
| R-Bloggers.com hopes to serve the R community by presenting (in one
place)
| all the new articles (posts) written (in English) about R in the "R
| blogosphere".

But how is that different from

  http://PlanetR.stderr.org

which has been doing the same quite admirably for years?

Dirk

--
Three out of two people have difficulties with fractions.



--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/Gq7i : ohloh
|- http://tr.im/FtUu : new package : highlight
`- http://tr.im/EAD5 : LondonR slides

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


[R] R packages and assess to data in packages

2009-12-05 Thread Tariq Perwez
Hi Everyone,

I have two very basic questions and would appreciate your help.
1. I would like to see/access the data that comes with a given R package by
using a function like read.table(). For example, I just installed car
package from CRAN. I know that somewhere within the package, there is
Duncan.txt file. I would not only like to look at it from file browser (or
using ls command in shell)  but also to access it as:

> Duncan <- read.table("path/to/data/Duncan.txt", header = T)

I can certainly use:

> data(Duncan)

and

> attach(Duncan)

after loading the package car. However, I would like to see all the data
that come with a package as separate files. Where are these files located? I
installed the car package under Mac OSX  under the user level (if this
detail is important). However, I do use R under Ubuntu linux also and
general solution to this problem will be great. I even downloaded the car
binaries and unpacked the zipped file on desktop but I just see .rda files
within the data folder; there are no .txt files anywhere.  I do see
Duncan.rda file (I believe this contains the Duncan.txt data). How can I
access the data files from such package, say using a text editor??

2. What is the safest/preferred place to install an R package that I want to
delete/remove once I do not need it. Sometimes, I just need to install a
package from a book's website so that I can work on the exercises etc but do
not need the package permanently hanging around. Removing such a package and
all the associated files etc would be nice.

I would appreciate any help and comments on my questions. Regards,

Tariq

[[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] Rounding a Measurement to be Consistent with its Uncertainty

2009-12-05 Thread Tom La Bone


Uwe Ligges-3 wrote:
> 
> 
> 
> Tom La Bone wrote:
>> I have a measurement of 8165.666 and an uncertainty of 338.9741 (the
>> units of
>> both are unimportant). I can easily round the uncertainty to two
>> significant
>> digits with signif(338.9741,2), which gives 340. Is there a function in R
>> that will take 8165.666 and round it to be consistent with its
>> uncertainty,
>> i.e., 8170?
> 
> That's not consistent, you have 3 significant digits here, but 2 for the 
> "uncertainty" (whatever that is) ...
> 
> Uwe Ligges
> 
> 
>> 
>> Tom
> 
> In metrology, what I did is indeed consistent (provided that I have
> correctly interpreted the guidance given in the "ISO Guide to the
> Expression of Uncertainty in Measurement"). The uncertainty is basically a
> way of specifying in which digits I begin to doubt my result. So, I while
> I will usually have two digits in my uncertainty, I can have 10
> significant digits in my result. Some folks have given me some ideas
> off-line on how to write a function that will round a number in this
> fashion, but I always prefer to use an existing R function if it already
> exists rather than write my own. And, with the tens of thousands of R
> functions in existence, it is always a good idea to ask the forum if they
> know of one.
> 
> Tom
> 
> 
> 
> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://n4.nabble.com/Rounding-a-Measurement-to-be-Consistent-with-its-Uncertainty-tp948151p949395.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] Announcing a new R news site: R-bloggers.com

2009-12-05 Thread Tal Galili
Hi Daniel.

In short: no.

In more words:
1) I have zone alarm also on my computer and it gives me no warnings.
2) The only two external scripts the site has are of "woopra" and "google
analytics", both are known external statistics services.
3) It could be (although not likely) that the site is hacked and was
injected with something, but services like this one:
http://www.unmaskparasites.com/security-report/
claims that my site is clean.

If you have anymore suggestions - I would love to know them.

Thanks for reporting, what do you think of the site itself BTW?

Best,
Tal






Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com/ (English)
--




On Sat, Dec 5, 2009 at 11:04 PM, Daniel Nordlund wrote:

>
>
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> > On Behalf Of Tal Galili
> > Sent: Saturday, December 05, 2009 11:38 AM
> > To: r-help@r-project.org
> > Subject: [R] Announcing a new R news site: R-bloggers.com
> >
> > Hello everyone.
> > After some good time of work, I am proud to present: www.r-bloggers.com
> >
> > What is R-Bloggers.com?
> >
> > R-Bloggers.com hopes to serve the R community by presenting (in one
> place)
> > all the new articles (posts) written (in English) about R in the "R
> > blogosphere".
> > How does R-Bloggers operate?
> >
> > This site aggregates feeds (only with permission!) from participating R
> > blogs. The beginnings of each participating blog s posts will
> > automatically
> > be displayed on the main page with links to the original posts; inside
> > every
> > post there is a link to the original blog and links to other related
> > articles.  All participating blogs will have links in the  Contributors
> > section of our sidebar
> > What does R-Bloggers offer the community?
> >
> >- Discover: If every blogger will add itself, we will all be able to
> > find
> >new R blogs (which is hard to find on the web, if you ever tried). The
> >site also allows to search in the content of the bloggers (although
> for
> >searches of older content - you better go to the blogs themselves or
> > wait
> >for the customized google search box I will add in the future)
> >- Follow: Enter your e-mail and subscribe to receive a daily digest
> > with
> >teasers of new posts from participating blogs.  You will more easily
> > get a
> >sense of hot topics in the R blogosphere.
> >- Connect: Click on  Fan this site  to become a "fan" of R Bloggers.
> > You
> >can  friend  other people and share thoughts on our wall. Or just by
> > leaving
> >comments on the blog.
> >- Participate: Add your R blog to get increased visibility (for
> readers
> >and search engines) with permanent links on our Contributors sidebar.
> > Your
> >blog will also gain visibility via our e-mail digest and through your
> >presence on the main page with posts.
> >
> > How do I become a participating blog in R Bloggers?
> >
> > To add your blog, simply click on Add your
> > blog! and
> > enter the required information.  I will review your link and approve it
> in
> > a
> > timely fashion.
> > How can I help?
> >
> > We share readers to gain readers!  If you are interested and haven t
> > already, please submit your blog  > blog/>.
> >  Also please consider putting *a link from your blog* to R-Bloggers from
> > your sidebar (we do the same for you); you can even put up a post about
> us
> > -
> > if each blogger will do so - all of us will gain from it.
> >  Who started R-Bloggers (and way)?
> >
> > R Bloggers was started by Tal Galili . After
> > searching for numerous R blogs, Tal (well, me) decided that there must be
> > more R blogs our there then he knows about, and maybe the best way for
> > finding them is to make them find him. You can reach Tal via the
> > Contact page
> > (or just e-mail him: tal.gal...@gmail.com).
> > Extra thanks and a deceleration of "good intentions"
> > I would like to thank John, Yihui, Jaanus and Taiyun for being the first
> > bloggers to allow me to enlist their blogs to the project.
> > There are more R bloggers out there that I know of, and didn't get to ask
> > for permission. I apologies to you for not contacting you personally,
> > still
> > If you are one such blogger, and you want to join the site, please feel
> > welcome to submit your blog .
> >
> > I hope this e-mail was not an abuse of the R mailing list. Since I
> > intended
> > this project for the good of the R community I allowed myself to publish
> > the
> >

Re: [R] Announcing a new R news site: R-bloggers.com

2009-12-05 Thread Daniel Nordlund


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Tal Galili
> Sent: Saturday, December 05, 2009 11:38 AM
> To: r-help@r-project.org
> Subject: [R] Announcing a new R news site: R-bloggers.com
> 
> Hello everyone.
> After some good time of work, I am proud to present: www.r-bloggers.com
> 
> What is R-Bloggers.com?
> 
> R-Bloggers.com hopes to serve the R community by presenting (in one place)
> all the new articles (posts) written (in English) about R in the "R
> blogosphere".
> How does R-Bloggers operate?
> 
> This site aggregates feeds (only with permission!) from participating R
> blogs. The beginnings of each participating blogs posts will
> automatically
> be displayed on the main page with links to the original posts; inside
> every
> post there is a link to the original blog and links to other related
> articles.  All participating blogs will have links in the Contributors
> section of our sidebar
> What does R-Bloggers offer the community?
> 
>- Discover: If every blogger will add itself, we will all be able to
> find
>new R blogs (which is hard to find on the web, if you ever tried). The
>site also allows to search in the content of the bloggers (although for
>searches of older content - you better go to the blogs themselves or
> wait
>for the customized google search box I will add in the future)
>- Follow: Enter your e-mail and subscribe to receive a daily digest
> with
>teasers of new posts from participating blogs.  You will more easily
> get a
>sense of hot topics in the R blogosphere.
>- Connect: Click on Fan this site to become a "fan" of R Bloggers.
> You
>can friend other people and share thoughts on our wall. Or just by
> leaving
>comments on the blog.
>- Participate: Add your R blog to get increased visibility (for readers
>and search engines) with permanent links on our Contributors sidebar.
> Your
>blog will also gain visibility via our e-mail digest and through your
>presence on the main page with posts.
> 
> How do I become a participating blog in R Bloggers?
> 
> To add your blog, simply click on Add your
> blog! and
> enter the required information.  I will review your link and approve it in
> a
> timely fashion.
> How can I help?
> 
> We share readers to gain readers!  If you are interested and havent
> already, please submit your blog  blog/>.
>  Also please consider putting *a link from your blog* to R-Bloggers from
> your sidebar (we do the same for you); you can even put up a post about us
> -
> if each blogger will do so - all of us will gain from it.
>  Who started R-Bloggers (and way)?
> 
> R Bloggers was started by Tal Galili . After
> searching for numerous R blogs, Tal (well, me) decided that there must be
> more R blogs our there then he knows about, and maybe the best way for
> finding them is to make them find him. You can reach Tal via the
> Contact page
> (or just e-mail him: tal.gal...@gmail.com).
> Extra thanks and a deceleration of "good intentions"
> I would like to thank John, Yihui, Jaanus and Taiyun for being the first
> bloggers to allow me to enlist their blogs to the project.
> There are more R bloggers out there that I know of, and didn't get to ask
> for permission. I apologies to you for not contacting you personally,
> still
> If you are one such blogger, and you want to join the site, please feel
> welcome to submit your blog .
> 
> I hope this e-mail was not an abuse of the R mailing list. Since I
> intended
> this project for the good of the R community I allowed myself to publish
> the
> site here, so I hope it wouldn't upset anyone.
> 
> Best wishes to all,
> Tal
> 
> 

I went to the site listed above and ZoneAlarm on my computer reported the site 
as suspicious (I can count on one hand the number of times I have received that 
warning).  My question: do you know what your site is doing that might be 
considered suspicious?

Dan

Daniel Nordlund
Bothell, WA 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] Announcing a new R news site: R-bloggers.com

2009-12-05 Thread Tal Galili
Hi Dirk,

I wish to emphasis that I came across PlanetR over a year ago,
but completely forgot it existed when working on R-bloggers. Also, when I
contacted the bloggers about this idea, non of them actually wrote to me
about it (which makes me feel better about not remembering it). I apologies
if setting up R-bloggers seems like trying to "compete" with PlanetR, this
at all wasn't my intention.
Yet, now that my website is up, I hope it will be of use and here
are several ways in which (at hindsight) I can say it has something to
offer:

1) Planet R is limited (for years) to 26 feeds only, and I don't remember
seeing it evolve to include (or allow inclusion) of new R blogs that came
around.
2) The feeds are of blogs and non blogs (such as wiki or cran updates). That
makes finding "reading material" inside it very difficult, since the site is
cluttered with a lot of "updates" from cranbarries and the wiki.
3) In PlanetR, one can only view (about) 5 days back and no more (R-bloggers
allows viewing of much more then 5 days back).
4) R-bloggers allows searching inside the content, PlanetR doesn't.
5) R-bloggers allow one to get e-mail updates, PlanetR doesn't.
6) R-bloggers offers "related articles", PlanetR doesn't.

I see R-bloggers  as a "news site" based on the
R bloggers, and I can't say the same about PlanetR for the reasons I gave
above.


With much respect to you Dirk,
Tal






Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com/ (English)
--




On Sat, Dec 5, 2009 at 9:59 PM, Dirk Eddelbuettel  wrote:

>
> On 5 December 2009 at 21:38, Tal Galili wrote:
> | R-Bloggers.com hopes to serve the R community by presenting (in one
> place)
> | all the new articles (posts) written (in English) about R in the "R
> | blogosphere".
>
> But how is that different from
>
>  http://PlanetR.stderr.org
>
> which has been doing the same quite admirably for years?
>
> Dirk
>
> --
> Three out of two people have difficulties with fractions.
>

[[alternative HTML version deleted]]

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


Re: [R] HELP boxplot for time class

2009-12-05 Thread Gabor Grothendieck
Use the title function:

title("My main", xlab = "My X", ylab = "My Y")


On Sat, Dec 5, 2009 at 12:38 PM, uvilla  wrote:

>
> Thanks a lot Gabor, now I could finally plot the as time data. I just have
> one more question, and I hope it is the last.
>
> In the script of the boxplot,
>
> bp <- boxplot(as.numeric(skiers$start), yaxt = "n")
> axis(2, bp$stats, times(bp$stats), las = 2, cex.axis = 0.5)
>
> I have been trying to add a main tittle and xlab, ylab with no succes.
> Where
> I am supposed to type: main="skiing starting tour" and so on
>
>
> Thanks a lot!!
>
> Maria
>
>
>
>
> Gabor Grothendieck wrote:
> >
> > Try this:
> >
> > Lines <- " protokollid datestart  end
> > 4 2/23/2009  8:50:10 15:17:30
> > 4 2/24/2009  9:47:00 13:52:25
> > 5 3/22/2009  8:51:25 12:00:05"
> >
> > library(chron)
> > skiers <- read.table(textConnection(Lines), header = TRUE, as.is = TRUE)
> > skiers <- transform(skiers, date = dates(date),
> > start = times(start), end = times(end))
> >
> > bp <- boxplot(as.numeric(skiers$start), yaxt = "n")
> > axis(2, bp$stats, times(bp$stats), las = 2, cex.axis = 0.5)
> >
> >
> > On Sat, Dec 5, 2009 at 6:52 AM, uvilla  wrote:
> >
> >>
> >> hi again
> >>
> >> I will try this time to explain my problem clearly
> >> I have the following data from the file skiing.csv (3 first rows)
> >>
> >>  protokollid datestart  end
> >> 14 2/23/2009  8:50:10 15:17:30
> >> 24 2/24/2009  9:47:00 13:52:25
> >> 35 3/22/2009  8:51:25 12:00:05
> >>
> >>
> >> I have the following script
> >>
> >> library(chron)
> >>
> >> skiers=read.csv("skiing.csv")
> >> strptime("08:50:10","%H:%M:%S")
> >>
> >> start=times(skiers[,3])
> >> strptime(start,"%H:%M:%S")
> >> end=times(skiers[,4])
> >> strptime(end,"%H:%M:%S")
> >>
> >> #calc lenght of the route
> >> length.route=end-start
> >>
> >> #calc medians
> >> median(start)
> >> median(length.route)
> >>
> >> Then I want to do a box plot of the staring time
> >> when I use:
> >>
> >> boxplot(start)
> >>
> >> this error appears: Warning message:
> >> In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
> >>
> >> when I try to convert start as POSIXct
> >>
> >> > start=as.POSIXct(start)
> >> Error in as.POSIXct.default(start) :
> >>  do not know how to convert 'start' to class "POSIXlt"
> >>
> >> and when I try to convert skiers[,3] as POSIXct
> >>
> >> > skiers[,3]=as.POSIXct(skiers[,3])
> >> Error in as.POSIXlt.character(as.character(x)) :
> >>  character string is not in a standard unambiguous format
> >>
> >> start is of "times" class and skiers[,3] of "factor" class
> >>
> >> I want to do a boxplot of the starting time of my data, which reflect
> the
> >> median " 08:36:45", and all O get in the y axis are decimal numbers :(
> >> Help please
> >>
> >> Best regards
> >>
> >> Maria Stauss
> >>
> >>
> >> --
> >> View this message in context:
> >> http://n4.nabble.com/HELP-boxplot-for-time-class-tp949154p949154.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.
> >
> >
>
> --
> View this message in context:
> http://n4.nabble.com/HELP-boxplot-for-time-class-tp949154p949270.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] Announcing a new R news site: R-bloggers.com

2009-12-05 Thread Dirk Eddelbuettel

On 5 December 2009 at 21:38, Tal Galili wrote:
| R-Bloggers.com hopes to serve the R community by presenting (in one place)
| all the new articles (posts) written (in English) about R in the "R
| blogosphere".

But how is that different from   
  
  http://PlanetR.stderr.org   

which has been doing the same quite admirably for years?

Dirk

-- 
Three out of two people have difficulties with fractions.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Announcing a new R news site: R-bloggers.com

2009-12-05 Thread Tal Galili
Hello everyone.
After some good time of work, I am proud to present: www.r-bloggers.com

What is R-Bloggers.com?

R-Bloggers.com hopes to serve the R community by presenting (in one place)
all the new articles (posts) written (in English) about R in the "R
blogosphere".
How does R-Bloggers operate?

This site aggregates feeds (only with permission!) from participating R
blogs. The beginnings of each participating blog’s posts will automatically
be displayed on the main page with links to the original posts; inside every
post there is a link to the original blog and links to other related
articles.  All participating blogs will have links in the “Contributors”
section of our sidebar
What does R-Bloggers offer the community?

   - Discover: If every blogger will add itself, we will all be able to find
   new R blogs (which is hard to find on the web, if you ever tried). The
   site also allows to search in the content of the bloggers (although for
   searches of older content - you better go to the blogs themselves or wait
   for the customized google search box I will add in the future)
   - Follow: Enter your e-mail and subscribe to receive a daily digest with
   teasers of new posts from participating blogs.  You will more easily get a
   sense of hot topics in the R blogosphere.
   - Connect: Click on “Fan this site” to become a "fan" of R Bloggers.  You
   can “friend” other people and share thoughts on our wall. Or just by leaving
   comments on the blog.
   - Participate: Add your R blog to get increased visibility (for readers
   and search engines) with permanent links on our Contributors sidebar.  Your
   blog will also gain visibility via our e-mail digest and through your
   presence on the main page with posts.

How do I become a participating blog in R Bloggers?

To add your blog, simply click on Add your
blog! and
enter the required information.  I will review your link and approve it in a
timely fashion.
How can I help?

We share readers to gain readers!  If you are interested and haven’t
already, please submit your blog .
 Also please consider putting *a link from your blog* to R-Bloggers from
your sidebar (we do the same for you); you can even put up a post about us -
if each blogger will do so - all of us will gain from it.
 Who started R-Bloggers (and way)?

R Bloggers was started by Tal Galili . After
searching for numerous R blogs, Tal (well, me) decided that there must be
more R blogs our there then he knows about, and maybe the best way for
finding them is to make them find him. You can reach Tal via the
Contact page
(or just e-mail him: tal.gal...@gmail.com).
Extra thanks and a deceleration of "good intentions"
I would like to thank John, Yihui, Jaanus and Taiyun for being the first
bloggers to allow me to enlist their blogs to the project.
There are more R bloggers out there that I know of, and didn't get to ask
for permission. I apologies to you for not contacting you personally, still
If you are one such blogger, and you want to join the site, please feel
welcome to submit your blog .

I hope this e-mail was not an abuse of the R mailing list. Since I intended
this project for the good of the R community I allowed myself to publish the
site here, so I hope it wouldn't upset anyone.

Best wishes to all,
Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com/ (English)
--

[[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] Problem with date x-axis

2009-12-05 Thread Uwe Ligges



PtitBleu wrote:

Hello,

I have a "friday" problem.
I'm trying to plot the number of measures by day with this command between
the 2008-07-31 and the 2009-11-13 (it works) :
plot(unique(as.Date(strptime(data$date, format="%Y-%m-%d %H:%M:%S))),
measuresbyday)
then I would like to plot vertical lines for each month. 
But it doesn't work because

par()$usr gives
14071.16  14579.84  -7.16  213.16
and
as.numeric(as.POSIXct(unique(as.Date(strptime(data$date, format="%Y-%m-%d
%H:%M:%S)))[1])) corresponding to "2008-08-01" gives
1217376000

I think the last value is ok but I don't understand why the par()$usr values
are so low.

Any idea ?




Seems to be unanswered so far - not a big surprise given we do not see a 
small reproducible example (we do neither have measuresbyday nor data) 
that would be easy and quick to adapt to your needs.


Best wishes,
Uwe Ligges



Thanks in advance and have a nice week-end,
Ptit Bleu.







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


Re: [R] How to draw a big heatmap?

2009-12-05 Thread Uwe Ligges



Ning Ma wrote:

Hi everyone. How can I draw a big heatmaps?

png("foo.png",1,1)
heatmap(x)
dev.off()

where x is a big matrix, say 200*200.

The code above generates a small heatmap in the middle of the png file
and leaves big margins. I expect it to take up more space so that the
labels are not overlapping.




Without having looked in detail -  I cannot even allocate enough space 
for a 1x1 and you certainly do not want to produce some 300Mb 
file, do you?

Anway, to proceed, decrease the size of the margins, see ?par.

Uwe Ligges



Thanks in advance.

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


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


Re: [R] Rounding a Measurement to be Consistent with its Uncertainty

2009-12-05 Thread Uwe Ligges



Tom La Bone wrote:

I have a measurement of 8165.666 and an uncertainty of 338.9741 (the units of
both are unimportant). I can easily round the uncertainty to two significant
digits with signif(338.9741,2), which gives 340. Is there a function in R
that will take 8165.666 and round it to be consistent with its uncertainty,
i.e., 8170?


That's not consistent, you have 3 significant digits here, but 2 for the 
"uncertainty" (whatever that is) ...


Uwe Ligges




Tom


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


Re: [R] Installing RandomForest on SuSe Linux - warnings

2009-12-05 Thread Uwe Ligges
If the package passes the checks (R CMD check) on your macine, it should 
be fine. Some compiler warnings are expected.


Best wishes,
Uwe Ligges



NCS wrote:


I installed RF on Linux OpenSuSe 11.1 and while it did install and did run a model I had 
created on Windows correctly, it gave me a lot of "uninitialized" warnings.  I 
don't know if these are significant and so am a little concerned even though my model 
ran.  Any thoughts?

Thanks

R version 2.10.0 (2009-10-26)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.


install.packages("randomForest")

--- Please select a CRAN mirror for use in this session ---
CRAN mirror

 1: Argentina (Buenos Aires)   2: Australia
 3: Austria4: Belarus
 5: Belgium6: Brazil (PR)
 7: Brazil (RJ)8: Brazil (SP 1)
 9: Brazil (SP 2) 10: Canada (BC)
11: Canada (ON)   12: Canada (QC)
13: Chile 14: China (Beijing 1)
15: China (Beijing 2) 16: China (Hong Kong)
17: Colombia  18: Denmark
19: France (Toulouse) 20: France (Lyon)
21: France (Paris)22: Germany (Berlin)
23: Germany (Goettingen)  24: Germany (Hannover)
25: Germany (Muenchen)26: Germany (Wiesbaden)
27: Iran  28: Ireland
29: Italy (Milano)30: Italy (Padua)
31: Italy (Palermo)   32: Japan (Aizu)
33: Japan (Hyogo) 34: Japan (Tokyo)
35: Japan (Tsukuba)   36: Korea
37: Netherlands   38: New Zealand
39: Norway40: Poland (Oswiecim)
41: Poland (Wroclaw)  42: Portugal
43: Russia44: Singapore 1
45: Singapore 2   46: Slovakia
47: South Africa  48: Spain (Madrid)
49: Sweden50: Switzerland
51: Taiwan (Taichung) 52: Taiwan (Taipeh)
53: Thailand  54: UK (Bristol)
55: UK (London)   56: USA (AZ)
57: USA (CA 1)58: USA (CA 2)
59: USA (IA)  60: USA (MA)
61: USA (MD)  62: USA (MI)
63: USA (MO)  64: USA (NC)
65: USA (OH)  66: USA (PA 1)
67: USA (PA 2)68: USA (TN)
69: USA (TX 1)70: USA (TX 3)
71: USA (WA)

Selection: 57
trying URL 'http://cran.cnr.Berkeley.edu/src/contrib/randomForest_4.5-33.tar.gz'
Content type 'application/x-gzip' length 71745 bytes (70 Kb)
opened URL
==
downloaded 70 Kb

* installing *source* package ârandomForestâ ...
** libs
gcc -std=gnu99 -I/usr/lib64/R/include  -I/usr/local/include-fpic  
-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector 
-funwind-tables -fasynchronous-unwind-tables -c classTree.c -o classTree.o
classTree.c: In function âpredictClassTreeâ:
classTree.c:414: warning: âcbestsplitâ may be used uninitialized in this 
function
gcc -std=gnu99 -I/usr/lib64/R/include  -I/usr/local/include-fpic  
-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector 
-funwind-tables -fasynchronous-unwind-tables -c regTree.c -o regTree.o
regTree.c: In function âpredictRegTreeâ:
regTree.c:294: warning: âcbestsplitâ may be used uninitialized in this function
gcc -std=gnu99 -I/usr/lib64/R/include  -I/usr/local/include-fpic  
-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector 
-funwind-tables -fasynchronous-unwind-tables -c regrf.c -o regrf.o
regrf.c: In function âregRFâ:
regrf.c:61: warning: ânodextsâ may be used uninitialized in this function
regrf.c:55: warning: âytreeâ may be used uninitialized in this function
gcc -std=gnu99 -I/usr/lib64/R/include  -I/usr/local/include-fpic  
-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector 
-funwind-tables -fasynchronous-unwind-tables -c rf.c -o rf.o
rf.c: In function âclassRFâ:
rf.c:97: warning: âoobpairâ may be used uninitialized in this function
rf.c:98: warning: âstrata_sizeâ may be used uninitialized in this function
rf.c:98: warning: âstrata_idxâ may be used uninitialized in this function
rf.c:97: warning: ânindâ may be used uninitialized in this function
rf.c:89: warning: ânstrataâ may be used uninitialized in this function
rf.c:92: warning: âncltsâ may be used uninitialized in this function
gfortran   -fpic  -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 
-fstack-protector -funwind-tables -fasynchronous-unwind-tables -c rfsub.f -o 
rfsub.o

Re: [R] regression tests still fail for R version 2.10.0

2009-12-05 Thread David Winsemius
The question lacks so many specifics that would be needed to address  
problem that I suspect persons with sufficient knowledge to address it  
(and I am probably not among that group) simply passed it over and  
waited for you to get sufficiently motivated to actually  read the  
Posting Guide. Among the missing items are OS specifics, why you need  
to install from sources, which version of the source bundle, (perhaps)  
which mirror, etc, etc.


(I surely would not report a bug with so much missing information.)

--
David.
On Dec 5, 2009, at 1:25 PM, Oliver Kullmann wrote:


Hello,

on Mon Nov 9 17:57:04 CET 2009 I've sent
an e-mail to the R mailing list (see below),
about a failing regression test. Yet nobody
replied, while (obviously) the situation didn't
change (installation still fails, and might
continue to do so in the future).

I wonder whether somebody has to say something here?
Shall a bug report be submitted?
Or will R 2.10.1 have fixed the bug?

Oliver

--

Hello,

I have installed R version 2.9.2, and everything
works fine, but when attempting to install version 2.10.0
I get:

running code in 'datasets.R' ... OK
comparing 'datasets.Rout' to './datasets.Rout.save' ... OK
make[4]: Leaving directory `/home/csoliver/SAT-Algorithmen/ 
OKplatform/ExternalSources/builds/R/R-2.10.0/tests'
make[3]: Leaving directory `/home/csoliver/SAT-Algorithmen/ 
OKplatform/ExternalSources/builds/R/R-2.10.0/tests'
make[3]: Entering directory `/home/csoliver/SAT-Algorithmen/ 
OKplatform/ExternalSources/builds/R/R-2.10.0/tests'

running regression tests ...
make[4]: Entering directory `/home/csoliver/SAT-Algorithmen/ 
OKplatform/ExternalSources/builds/R/R-2.10.0/tests'
running code in 'reg-tests-1.R' ...make[4]: *** [reg-tests-1.Rout]  
Error 1
make[4]: Leaving directory `/home/csoliver/SAT-Algorithmen/ 
OKplatform/ExternalSources/builds/R/R-2.10.0/tests'

make[3]: *** [test-Reg] Error 2
make[3]: Leaving directory `/home/csoliver/SAT-Algorithmen/ 
OKplatform/ExternalSources/builds/R/R-2.10.0/tests'

make[2]: *** [test-all-basics] Error 1
make[2]: Leaving directory `/home/csoliver/SAT-Algorithmen/ 
OKplatform/ExternalSources/builds/R/R-2.10.0/tests'

make[1]: *** [check] Error 2
make[1]: Leaving directory `/home/csoliver/SAT-Algorithmen/ 
OKplatform/ExternalSources/builds/R/R-2.10.0'

make: *** [R_base] Error 1

Before that the build seems alright.

Oliver

--
Dr. Oliver Kullmann
Computer Science Department
Swansea University
Faraday Building, Singleton Park
Swansea SA2 8PP, UK
http://cs.swan.ac.uk/~csoliver/

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


[R] regression tests still fail for R version 2.10.0

2009-12-05 Thread Oliver Kullmann
Hello,

on Mon Nov 9 17:57:04 CET 2009 I've sent
an e-mail to the R mailing list (see below),
about a failing regression test. Yet nobody
replied, while (obviously) the situation didn't
change (installation still fails, and might
continue to do so in the future).

I wonder whether somebody has to say something here?
Shall a bug report be submitted?
Or will R 2.10.1 have fixed the bug?

Oliver

--

Hello,

I have installed R version 2.9.2, and everything
works fine, but when attempting to install version 2.10.0
I get:

running code in 'datasets.R' ... OK
comparing 'datasets.Rout' to './datasets.Rout.save' ... OK
make[4]: Leaving directory 
`/home/csoliver/SAT-Algorithmen/OKplatform/ExternalSources/builds/R/R-2.10.0/tests'
make[3]: Leaving directory 
`/home/csoliver/SAT-Algorithmen/OKplatform/ExternalSources/builds/R/R-2.10.0/tests'
make[3]: Entering directory 
`/home/csoliver/SAT-Algorithmen/OKplatform/ExternalSources/builds/R/R-2.10.0/tests'
running regression tests ...
make[4]: Entering directory 
`/home/csoliver/SAT-Algorithmen/OKplatform/ExternalSources/builds/R/R-2.10.0/tests'
running code in 'reg-tests-1.R' ...make[4]: *** [reg-tests-1.Rout] Error 1
make[4]: Leaving directory 
`/home/csoliver/SAT-Algorithmen/OKplatform/ExternalSources/builds/R/R-2.10.0/tests'
make[3]: *** [test-Reg] Error 2
make[3]: Leaving directory 
`/home/csoliver/SAT-Algorithmen/OKplatform/ExternalSources/builds/R/R-2.10.0/tests'
make[2]: *** [test-all-basics] Error 1
make[2]: Leaving directory 
`/home/csoliver/SAT-Algorithmen/OKplatform/ExternalSources/builds/R/R-2.10.0/tests'
make[1]: *** [check] Error 2
make[1]: Leaving directory 
`/home/csoliver/SAT-Algorithmen/OKplatform/ExternalSources/builds/R/R-2.10.0'
make: *** [R_base] Error 1

Before that the build seems alright.

Oliver

-- 
Dr. Oliver Kullmann
Computer Science Department
Swansea University
Faraday Building, Singleton Park
Swansea SA2 8PP, UK
http://cs.swan.ac.uk/~csoliver/

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


Re: [R] Partial correlations and p-values

2009-12-05 Thread David Freedman

you might look at partial.r in the psych package


dadrivr wrote:
> 
> I'm trying to write code to calculate partial correlations (along with
> p-values).  I'm new to R, and I don't know how to do this.  I have
> searched and come across different functions, but I haven't been able to
> get any of them to work (for example, pcor and pcor.test from the ggm
> package).
> 
> In the following example, I am trying to compute the correlation between x
> and y, while controlling for z (partial correlation):
> 
> x <- c(1,20,14,7,9)
> y <- c(5,6,7,9,10)
> z <- c(13,27,16,5,4)
> 
> What function can I append to this to find this partial correlation?  Many
> thanks!
> 
> 
> 

-- 
View this message in context: 
http://n4.nabble.com/Partial-correlations-and-p-values-tp908641p949283.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] Partial correlations and p-values

2009-12-05 Thread Charles C. Berry

On Sat, 5 Dec 2009, Juliet Hannah wrote:


Your R code looks correct.


There are a couple of hiccups.

First the degrees of freedom for the partial correlation would be wrong 
even if there was no missing data.




Because this is a straightforward calculation, I would be surprised if there
were any differences with SPSS.


There are differences. SPSS seems to use the correlation matrix computed 
with a pairwise present method and compute partial correlations from that.


Following

http://wiki.r-project.org/rwiki/doku.php?id=tips:data-matrices:part_corr


R.pp <- cor(cbind(x,y,z1,z2),use='pair')
R.comp <- cor(cbind(x,y,z1,z2),use='complete')
Rinv <- solve(R.pp)
D <- diag(1 / sqrt(diag(Rinv)))
P <- -D %*% Rinv %*% D
P[1,2]

[1] 0.4596122

Rinv <- solve(R.comp)
D <- diag(1 / sqrt(diag(Rinv)))
P <- -D %*% Rinv %*% D
P[1,2]

[1] 0.657214

The pairwise present value seems to be what SPSS is reporting.

The complete cases values is nearly (but not the same as) what you got.

A real issue here is how to usefully compute and test partial 
correlations in the presence of missing data. If you want to persue that, 
I would suggest opening a new thread with a subject line like 'partial 
correlations with missing observations'


HTH,

Chuck


It may be worthwhile to check

if SPSS  gives partial correlations or semipartial correlations. For example,
if you take the correlation between

py <- resid(lm(y ~ z1 + z2,data=mydat2))

and

x

where mydat2 has missing values removed, you get 0.47.

On Tue, Dec 1, 2009 at 8:24 PM, dadrivr  wrote:


I am trying to calculate a partial correlation and p-values.  Unfortunately,
the results in R are different than what SPSS gives.

Here is an example in R (calculating the partial correlation of x and y,
controlling for z1 and z2):

x <- c(1,20,14,30,9,4,8)
y <- c(5,6,7,9,NA,10,6)
z1 <- c(13,8,16,14,26,13,20)
z2 <- c(12,NA,2,5,8,16,13)
fmx <- lm(x ~ z1 + z2, na.action = na.exclude)
fmy <- lm(y ~ z1 + z2, na.action = na.exclude)
yres <- resid(fmy)
xres <- resid(fmx)
cor(xres, yres, use = "p")
ct <- cor.test(xres, yres)
ct$estimate
ct$p.value

R give me:
r = .65, p = .23

However, SPSS calculates:
r = .46, p = .70

I think something may be different with R's handling of missing data, as
when I replace the NA's with values, R and SPSS give the same r-values,
albeit different p-values still.  I am doing pairwise case exclusion in both
R and SPSS.  Any ideas why I'm getting different values?  Is something wrong
with my formula in R?  Any help would be greatly appreciated.  Thanks!



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



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

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


Re: [R] HELP boxplot for time class

2009-12-05 Thread uvilla

Thanks a lot Gabor, now I could finally plot the as time data. I just have
one more question, and I hope it is the last. 

In the script of the boxplot, 

bp <- boxplot(as.numeric(skiers$start), yaxt = "n")
axis(2, bp$stats, times(bp$stats), las = 2, cex.axis = 0.5)

I have been trying to add a main tittle and xlab, ylab with no succes. Where
I am supposed to type: main="skiing starting tour" and so on


Thanks a lot!!

Maria




Gabor Grothendieck wrote:
> 
> Try this:
> 
> Lines <- " protokollid datestart  end
> 4 2/23/2009  8:50:10 15:17:30
> 4 2/24/2009  9:47:00 13:52:25
> 5 3/22/2009  8:51:25 12:00:05"
> 
> library(chron)
> skiers <- read.table(textConnection(Lines), header = TRUE, as.is = TRUE)
> skiers <- transform(skiers, date = dates(date),
> start = times(start), end = times(end))
> 
> bp <- boxplot(as.numeric(skiers$start), yaxt = "n")
> axis(2, bp$stats, times(bp$stats), las = 2, cex.axis = 0.5)
> 
> 
> On Sat, Dec 5, 2009 at 6:52 AM, uvilla  wrote:
> 
>>
>> hi again
>>
>> I will try this time to explain my problem clearly
>> I have the following data from the file skiing.csv (3 first rows)
>>
>>  protokollid datestart  end
>> 14 2/23/2009  8:50:10 15:17:30
>> 24 2/24/2009  9:47:00 13:52:25
>> 35 3/22/2009  8:51:25 12:00:05
>>
>>
>> I have the following script
>>
>> library(chron)
>>
>> skiers=read.csv("skiing.csv")
>> strptime("08:50:10","%H:%M:%S")
>>
>> start=times(skiers[,3])
>> strptime(start,"%H:%M:%S")
>> end=times(skiers[,4])
>> strptime(end,"%H:%M:%S")
>>
>> #calc lenght of the route
>> length.route=end-start
>>
>> #calc medians
>> median(start)
>> median(length.route)
>>
>> Then I want to do a box plot of the staring time
>> when I use:
>>
>> boxplot(start)
>>
>> this error appears: Warning message:
>> In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
>>
>> when I try to convert start as POSIXct
>>
>> > start=as.POSIXct(start)
>> Error in as.POSIXct.default(start) :
>>  do not know how to convert 'start' to class "POSIXlt"
>>
>> and when I try to convert skiers[,3] as POSIXct
>>
>> > skiers[,3]=as.POSIXct(skiers[,3])
>> Error in as.POSIXlt.character(as.character(x)) :
>>  character string is not in a standard unambiguous format
>>
>> start is of "times" class and skiers[,3] of "factor" class
>>
>> I want to do a boxplot of the starting time of my data, which reflect the
>> median " 08:36:45", and all O get in the y axis are decimal numbers :(
>> Help please
>>
>> Best regards
>>
>> Maria Stauss
>>
>>
>> --
>> View this message in context:
>> http://n4.nabble.com/HELP-boxplot-for-time-class-tp949154p949154.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.
> 
> 

-- 
View this message in context: 
http://n4.nabble.com/HELP-boxplot-for-time-class-tp949154p949270.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] three plots as one JEPG?

2009-12-05 Thread Marc Schwartz

On Dec 5, 2009, at 11:34 AM, Marc Schwartz wrote:


On Dec 5, 2009, at 11:21 AM, Walther, Alexander wrote:


Dear List,


i have a question concerning these device-related function (i.e.
pdf(),jpeg(), etc.). Currently, I plot three graphs, one below the  
other
into a /single/ window by using par(). I would like to save this  
figure

now as JPEG or PNG. By now, code looks as follows:


jepg(...)

par(...)
plot(...)

par(...)
plot(...)

par(...)
plot(...)

dev.off()


Unfortunaltely, I just get the last plot saved, the rest is  
dismissed.

Does anyone have a solution for this problem?

Cheers

Alex



In the sequence you have above, each time you call plot(), you are  
erasing the prior plot.


What you want is:

jpeg(...)

par(mfrow = (3, 1))


Sorry, typo on that line. It should be:

  par(mfrow = c(3, 1))

Marc

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


Re: [R] three plots as one JEPG?

2009-12-05 Thread Duncan Murdoch

On 05/12/2009 12:21 PM, Walther, Alexander wrote:

Dear List,


i have a question concerning these device-related function (i.e.
pdf(),jpeg(), etc.). Currently, I plot three graphs, one below the other
into a /single/ window by using par(). I would like to save this figure
now as JPEG or PNG. By now, code looks as follows:


jepg(...)

par(...)
plot(...)

par(...)
plot(...)

par(...)
plot(...)

dev.off()


Unfortunaltely, I just get the last plot saved, the rest is dismissed.
Does anyone have a solution for this problem?


Sure, just do it like this:

jpeg(...)
par(mfrow=c(3,1))
plot(...)
plot(...)
plot(...)
dev.off()

There's also the layout() function, and more elaborate layout 
possibilities in the grid package.  But the basic idea is that you want 
the code to generate just one image on screen if you use a screen device 
rather than jpeg(), then jpeg() will generate something very similar.


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] three plots as one JEPG?

2009-12-05 Thread Marc Schwartz

On Dec 5, 2009, at 11:21 AM, Walther, Alexander wrote:


Dear List,


i have a question concerning these device-related function (i.e.
pdf(),jpeg(), etc.). Currently, I plot three graphs, one below the  
other
into a /single/ window by using par(). I would like to save this  
figure

now as JPEG or PNG. By now, code looks as follows:


jepg(...)

par(...)
plot(...)

par(...)
plot(...)

par(...)
plot(...)

dev.off()


Unfortunaltely, I just get the last plot saved, the rest is dismissed.
Does anyone have a solution for this problem?

Cheers

Alex



In the sequence you have above, each time you call plot(), you are  
erasing the prior plot.


What you want is:

jpeg(...)

par(mfrow = (3, 1))

plot(...)
plot(...)
plot(...)

dev.off()


That will create a plot matrix of 3 rows and 1 column, which will be  
saved to the jpeg file. Each new plot will be below the prior one.


A good way of going about this is to start by just plotting to the  
normal display device and then output to an external file. For the  
most part, the output should be similar, as long as you don't re-size  
the display device (eg. dragging a corner, etc.). With the code you  
have above, you would see right away that each new plot was clearing  
the prior one, thus knowing that this behavior was not unique to jpeg().


You can then tweak the plot as may be needed for the jpeg device.

You can also use ?layout to play around with creating differing  
arrangements of plots within a single device instance.


HTH,

Marc Schwartz

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


Re: [R] categorical vs numerical

2009-12-05 Thread DispersionMap

im using w7 ultimate


Peter Ehlers wrote:
> 
> pkg:lattice is installed as part of the base R distribution.
> You don't need to install it.
> 
> DispersionMap wrote:
>> Thanks, ill give them whirl...when i was installing the lattice package i
>> got
>> the error in bold below...why does it say permission denied and what
>> effect
>> does this have?
> I guess that you're on Vista and don't have write permission
> for that directory.
> 
>   -Peter Ehlers
>> 
>>> utils:::menuInstallLocal()
>> package 'lattice' successfully unpacked and MD5 sums checked
>> updating HTML package descriptions
>> Warning message:
>> In file.create(f.tg) :
>>   cannot create file 'C:\PROGRA~1\R\R-29~1.2/doc/html/packages.html',
>> reason
>> 'Permission denied'
>> 
>>> local({pkg <- select.list(sort(.packages(all.available = TRUE)))
>> + if(nchar(pkg)) library(pkg, character.only=TRUE)})
>> Warning message:
>> package 'lattice' was built under R version 2.10.0 
>> 
>> I have it loaded 
>> 
>> 
>> 
>> Peter Ehlers wrote:
>>> Whoops, that should be
>>>
>>>   densityplot(~y|g, data=dat, plot.points=FALSE, layout=c(1,4))
>>>
>>>   -Peter Ehlers
>>>
>>> Peter Ehlers wrote:
 You could try density plots:
 If dat is your dataframe, y is your numerical vector and
 g is your factor,

 library(lattice)
 trellis.device(height=9, width=7)
 densityplot(~g|y, data=dat, plot.points=FALSE, layout=c(1,4))

 See ?densityplot, ?panel.densityplot

  -Peter Ehlers

 DispersionMap wrote:
> Thanks, however the group sizes are really big (each a,b,c.. category
> has
> 60,000 observations). Its hard to see whats going on withe the
> jittered
> stripchart, i just get big black blobs.
>
> Any other suggestions?
>
>
>
>
> Peter Ehlers wrote:
>> If your group sizes are not too large, I would use jittered
>> stripcharts.
>> They're more informative than boxplots and much less subject to
>> misinterpretation. One warning, I'm not fond of the default pch=0.
>>
>>  -Peter Ehlers
>>
>> DispersionMap wrote:
>>> What ways are there to plot categorical vs numerical data in R.
>>>
>>>
>>> I have two columns: one with categorical data in 5 categories 
>>> a,b,c,d,e,
>>> and
>>> a numerical column with integers between 1 and 100.
>>>
>>> I have used a boxplot with a,b,c,d,e on the x-axis and an increasing
>>> numerical scale on the y-axis. This look fine but im looking for
>>> other
>>> ways
>>> to present the data.
>>>
>>>
>>> What other ways can i do this???
>>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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 Ehlers
>>> University of Calgary
>>> 403.202.3936
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/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 Ehlers
> University of Calgary
> 403.202.3936
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://n4.nabble.com/categorical-vs-numerical-tp948817p949267.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] Refresh with default x11() cairo

2009-12-05 Thread Marc Chiarini (Tufts)

Greetings R community:

Since R 2.9.0+ I have noticed that when I use the default cairo x11() 
device, if I obscure a device window (or switch virtual desktops), the 
window does not refresh.  I need to move it or resize it to make it 
redraw.  This behavior did not happen before 2.9.0.  It also does not 
occur currently when using the Xlib type in x11.


Now, I should make clear that I am not running on a machine under my 
administrative control, so it is entirely possible that something 
changed in the default X Window System configuration that prevents Cairo 
from refreshing.  I would like to ask if anyone has seen this behavior 
before and if so, have you found the cause and/or solution?  Thank you.


Possibly useful info:

Linux sunfire47 2.6.18-164.6.1.el5 #1 SMP Tue Oct 27 11:28:30 EDT 2009 
x86_64 x86_64 x86_64 GNU/Linux


R version 2.10.0 (2009-10-26)

Name: cairoRelocations: (not relocatable)
Version : 1.2.4 Vendor: Red Hat, Inc.
Release : 5.el5 Build Date: Fri 18 Jan 2008 
04:55:11 PM EST



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


[R] three plots as one JEPG?

2009-12-05 Thread Walther, Alexander
Dear List,


i have a question concerning these device-related function (i.e.
pdf(),jpeg(), etc.). Currently, I plot three graphs, one below the other
into a /single/ window by using par(). I would like to save this figure
now as JPEG or PNG. By now, code looks as follows:


jepg(...)

par(...)
plot(...)

par(...)
plot(...)

par(...)
plot(...)

dev.off()


Unfortunaltely, I just get the last plot saved, the rest is dismissed.
Does anyone have a solution for this problem?

Cheers

Alex

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


Re: [R] Referencing variable names rather than column numbers

2009-12-05 Thread John-Paul Ferguson
Holy Cats, those were four quick responses! And the question,
basically, is answered:

1. When in doubt, try quoting column names where you would try using
unquoted column indexes.
2. Subset() seems, overall, the most flexible analog to Stata's
variable-referencing syntax.

I appreciate the help. I'm encouraging several of my PhD students to
pick up R, given the research that they are doing, but it seems wrong
to make them do that without learning it myself. Humbling to be back
at this level of basic interface interaction, but very good to know
that a resource like this list exists.

Best,
John-Paul

2009/12/5 Marc Schwartz :
> Alternatively, you can use subset(), which supports the ":" operator
> for the 'select' argument:
>
>  > cor(subset(iris, select = Sepal.Length:Petal.Length))
>              Sepal.Length Sepal.Width Petal.Length
> Sepal.Length    1.000  -0.1175698    0.8717538
> Sepal.Width    -0.1175698   1.000   -0.4284401
> Petal.Length    0.8717538  -0.4284401    1.000
>
>
> which is equivalent to:
>
>  > cor(iris[, 1:3])
>              Sepal.Length Sepal.Width Petal.Length
> Sepal.Length    1.000  -0.1175698    0.8717538
> Sepal.Width    -0.1175698   1.000   -0.4284401
> Petal.Length    0.8717538  -0.4284401    1.000
>
>
> So for the pollute data:
>
>   cor(subset(pollute, select = Pollution:Industry))
>
> should work.
>
> Note also that the 'select' argument to subset can take non-contiguous
> column names:
>
> # Skip 'Sepal.Width'
>  > cor(subset(iris, select = c(Sepal.Length, Petal.Length:Petal.Width)))
>              Sepal.Length Petal.Length Petal.Width
> Sepal.Length    1.000    0.8717538   0.8179411
> Petal.Length    0.8717538    1.000   0.9628654
> Petal.Width     0.8179411    0.9628654   1.000
>
> So you have the option of specifying, by name, multiple series of
> contiguous and non-contiguous column names.
>
> See ?subset
>
> HTH,
>
> Marc Schwartz
>
>
> On Dec 5, 2009, at 10:43 AM, Ista Zahn wrote:
>
>> As baptiste noted, you can do
>>
>> cor(pollute[ ,c("Pollution","Temp","Industry")]).
>>
>> But
>>
>> cor(pollute[,"Pollution":"Industry"])
>>
>> will not work. For that you can do
>>
>> cor
>> (pollute
>> [ ,which
>> (names(pollute)=="Pollution"):which(names(pollute)=="Industry")])
>>
>> -Ista
>>
>> On Sat, Dec 5, 2009 at 11:22 AM, John-Paul Ferguson
>>  wrote:
>>> I apologize for how basic a question this is. I am a Stata user who
>>> has begun using R, and the syntax differences still trip me up. The
>>> most basic questions, involving as they do general terms, can be the
>>> hardest to find solutions for through search.
>>>
>>> Assume for the moment that I have a dataset that contains seven
>>> variables: Pollution, Temp, Industry, Population, Wind, Rain and
>>> Wet.days. (This actual dataset is taken from Michael Crawley's
>>> "Statistics: An Introduction Using R" and is available as
>>> "pollute.txt" in
>>> http://www.bio.ic.ac.uk/research/crawley/statistics/data/zipped.zip.)
>>> Assume I have attached pollute. Then
>>>
>>> cor(pollute)
>>>
>>> will give me the correlation table for these seven variables. If I
>>> would prefer only to see the correlations between, say, Pollution,
>>> Temp and Industry, I can get that with
>>>
>>> cor(pollute[,1:3])
>>>
>>> or with
>>>
>>> cor(pollute[1:3])
>>>
>>> Similarly, I can see the correlations between Temp, Population and
>>> Rain with
>>>
>>> cor(pollute[,c(2,4,6)])
>>>
>>> or with
>>>
>>> cor(pollute[c(2,4,6)])
>>>
>>> This is fine for a seven-variable dataset. When I have 250 variables,
>>> though, I start to pale at looking up column indexes over and over. I
>>> know from reading the list archives that I can extract the column
>>> index of Industry, for example, by typing
>>>
>>> which("Industry"==names(pollute))
>>>
>>> but doing that before each command seems dire. Trained to using Stata
>>> as I am, I am inclined to check the correlation of the first three or
>>> the second, fourth and sixth columns by substituting the column names
>>> for the column indexes--something like the following:
>>>
>>> cor(pollute[Pollution:Industry])
>>> cor(pollute[c(Temp,Population,Rain)])
>>>
>>> These however throw errors.
>>>
>>> I know that many commands in R are perfectly happy to take variable
>>> names--the regression models, for example--but that some do not. And
>>> so I ask you two general questions:
>>>
>>> 1. Is there a syntax for referring to variable names rather than
>>> column indexes in situations like these?
>>> 2. Is there something that I should look for in a command's help file
>>> that often indicates whether it can take column names rather than
>>> indexes?
>>>
>>> Again, apologies for asking something that has likely been asked
>>> before. I would appreciate any suggestions that you have.
>>>
>>> Best,
>>> John-Paul Ferguson
>>> Assistant Professor of Organizational Behavior
>>> Stanford University Graduate School of Business
>>> 518 Memorial Way, K313
>>> Stanford, CA 94305
>>>
>>> 

Re: [R] Referencing variable names rather than column numbers

2009-12-05 Thread David Winsemius


On Dec 5, 2009, at 11:30 AM, baptiste auguie wrote:


Hi,

Try this,

cor(pollute[ ,c("Pollution","Temp","Industry")])

and ?"[" in particular,
"Character vectors will be matched to the names of the object "


John-Paul;

In the time it took me to compose this, I see that others have already  
pointed out all of what I had written so it only remains to offer yet- 
another-R-method for ranges of column names.


You could have defined a "targets" vector of names if you know the  
starting and ending position:


?Extract   # or equivalently ?"["
targets <- names(pollute)[1:3]# colnames is an equivalent function  
for dataframe objects

targets
pollute[ , targets]

--

Best;
David.




HTH,

baptiste

2009/12/5 John-Paul Ferguson :

I apologize for how basic a question this is. I am a Stata user who
has begun using R, and the syntax differences still trip me up. The
most basic questions, involving as they do general terms, can be the
hardest to find solutions for through search.

Assume for the moment that I have a dataset that contains seven
variables: Pollution, Temp, Industry, Population, Wind, Rain and
Wet.days. (This actual dataset is taken from Michael Crawley's
"Statistics: An Introduction Using R" and is available as
"pollute.txt" in
http://www.bio.ic.ac.uk/research/crawley/statistics/data/zipped.zip.)
Assume I have attached pollute. Then

cor(pollute)

will give me the correlation table for these seven variables. If I
would prefer only to see the correlations between, say, Pollution,
Temp and Industry, I can get that with

cor(pollute[,1:3])

or with

cor(pollute[1:3])

Similarly, I can see the correlations between Temp, Population and  
Rain with


cor(pollute[,c(2,4,6)])

or with

cor(pollute[c(2,4,6)])

This is fine for a seven-variable dataset. When I have 250 variables,
though, I start to pale at looking up column indexes over and over. I
know from reading the list archives that I can extract the column
index of Industry, for example, by typing

which("Industry"==names(pollute))

but doing that before each command seems dire. Trained to using Stata
as I am, I am inclined to check the correlation of the first three or
the second, fourth and sixth columns by substituting the column names
for the column indexes--something like the following:

cor(pollute[Pollution:Industry])
cor(pollute[c(Temp,Population,Rain)])

These however throw errors.

I know that many commands in R are perfectly happy to take variable
names--the regression models, for example--but that some do not. And
so I ask you two general questions:

1. Is there a syntax for referring to variable names rather than
column indexes in situations like these?
2. Is there something that I should look for in a command's help file
that often indicates whether it can take column names rather than
indexes?

Again, apologies for asking something that has likely been asked
before. I would appreciate any suggestions that you have.

Best,
John-Paul Ferguson
Assistant Professor of Organizational Behavior
Stanford University Graduate School of Business
518 Memorial Way, K313
Stanford, CA 94305

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Referencing variable names rather than column numbers

2009-12-05 Thread Marc Schwartz
Alternatively, you can use subset(), which supports the ":" operator  
for the 'select' argument:


> cor(subset(iris, select = Sepal.Length:Petal.Length))
 Sepal.Length Sepal.Width Petal.Length
Sepal.Length1.000  -0.11756980.8717538
Sepal.Width-0.1175698   1.000   -0.4284401
Petal.Length0.8717538  -0.42844011.000


which is equivalent to:

> cor(iris[, 1:3])
 Sepal.Length Sepal.Width Petal.Length
Sepal.Length1.000  -0.11756980.8717538
Sepal.Width-0.1175698   1.000   -0.4284401
Petal.Length0.8717538  -0.42844011.000


So for the pollute data:

  cor(subset(pollute, select = Pollution:Industry))

should work.

Note also that the 'select' argument to subset can take non-contiguous  
column names:


# Skip 'Sepal.Width'
> cor(subset(iris, select = c(Sepal.Length, Petal.Length:Petal.Width)))
 Sepal.Length Petal.Length Petal.Width
Sepal.Length1.0000.8717538   0.8179411
Petal.Length0.87175381.000   0.9628654
Petal.Width 0.81794110.9628654   1.000

So you have the option of specifying, by name, multiple series of  
contiguous and non-contiguous column names.


See ?subset

HTH,

Marc Schwartz


On Dec 5, 2009, at 10:43 AM, Ista Zahn wrote:


As baptiste noted, you can do

cor(pollute[ ,c("Pollution","Temp","Industry")]).

But

cor(pollute[,"Pollution":"Industry"])

will not work. For that you can do

cor 
(pollute 
[ ,which 
(names(pollute)=="Pollution"):which(names(pollute)=="Industry")])


-Ista

On Sat, Dec 5, 2009 at 11:22 AM, John-Paul Ferguson
 wrote:

I apologize for how basic a question this is. I am a Stata user who
has begun using R, and the syntax differences still trip me up. The
most basic questions, involving as they do general terms, can be the
hardest to find solutions for through search.

Assume for the moment that I have a dataset that contains seven
variables: Pollution, Temp, Industry, Population, Wind, Rain and
Wet.days. (This actual dataset is taken from Michael Crawley's
"Statistics: An Introduction Using R" and is available as
"pollute.txt" in
http://www.bio.ic.ac.uk/research/crawley/statistics/data/zipped.zip.)
Assume I have attached pollute. Then

cor(pollute)

will give me the correlation table for these seven variables. If I
would prefer only to see the correlations between, say, Pollution,
Temp and Industry, I can get that with

cor(pollute[,1:3])

or with

cor(pollute[1:3])

Similarly, I can see the correlations between Temp, Population and  
Rain with


cor(pollute[,c(2,4,6)])

or with

cor(pollute[c(2,4,6)])

This is fine for a seven-variable dataset. When I have 250 variables,
though, I start to pale at looking up column indexes over and over. I
know from reading the list archives that I can extract the column
index of Industry, for example, by typing

which("Industry"==names(pollute))

but doing that before each command seems dire. Trained to using Stata
as I am, I am inclined to check the correlation of the first three or
the second, fourth and sixth columns by substituting the column names
for the column indexes--something like the following:

cor(pollute[Pollution:Industry])
cor(pollute[c(Temp,Population,Rain)])

These however throw errors.

I know that many commands in R are perfectly happy to take variable
names--the regression models, for example--but that some do not. And
so I ask you two general questions:

1. Is there a syntax for referring to variable names rather than
column indexes in situations like these?
2. Is there something that I should look for in a command's help file
that often indicates whether it can take column names rather than
indexes?

Again, apologies for asking something that has likely been asked
before. I would appreciate any suggestions that you have.

Best,
John-Paul Ferguson
Assistant Professor of Organizational Behavior
Stanford University Graduate School of Business
518 Memorial Way, K313
Stanford, CA 94305

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





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

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


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


Re: [R] Referencing variable names rather than column numbers

2009-12-05 Thread Jorge Ivan Velez
Dear John-Paul,

Take a look at https://stat.ethz.ch/pipermail/r-help/2009-July/204027.html It
contains different ways to do (in part) what you want.

HTH,
Jorge

On Sat, Dec 5, 2009 at 11:22 AM, John-Paul Ferguson <> wrote:

> I apologize for how basic a question this is. I am a Stata user who
> has begun using R, and the syntax differences still trip me up. The
> most basic questions, involving as they do general terms, can be the
> hardest to find solutions for through search.
>
> Assume for the moment that I have a dataset that contains seven
> variables: Pollution, Temp, Industry, Population, Wind, Rain and
> Wet.days. (This actual dataset is taken from Michael Crawley's
> "Statistics: An Introduction Using R" and is available as
> "pollute.txt" in
> http://www.bio.ic.ac.uk/research/crawley/statistics/data/zipped.zip.)
> Assume I have attached pollute. Then
>
> cor(pollute)
>
> will give me the correlation table for these seven variables. If I
> would prefer only to see the correlations between, say, Pollution,
> Temp and Industry, I can get that with
>
> cor(pollute[,1:3])
>
> or with
>
> cor(pollute[1:3])
>
> Similarly, I can see the correlations between Temp, Population and Rain
> with
>
> cor(pollute[,c(2,4,6)])
>
> or with
>
> cor(pollute[c(2,4,6)])
>
> This is fine for a seven-variable dataset. When I have 250 variables,
> though, I start to pale at looking up column indexes over and over. I
> know from reading the list archives that I can extract the column
> index of Industry, for example, by typing
>
> which("Industry"==names(pollute))
>
> but doing that before each command seems dire. Trained to using Stata
> as I am, I am inclined to check the correlation of the first three or
> the second, fourth and sixth columns by substituting the column names
> for the column indexes--something like the following:
>
> cor(pollute[Pollution:Industry])
> cor(pollute[c(Temp,Population,Rain)])
>
> These however throw errors.
>
> I know that many commands in R are perfectly happy to take variable
> names--the regression models, for example--but that some do not. And
> so I ask you two general questions:
>
> 1. Is there a syntax for referring to variable names rather than
> column indexes in situations like these?
> 2. Is there something that I should look for in a command's help file
> that often indicates whether it can take column names rather than
> indexes?
>
> Again, apologies for asking something that has likely been asked
> before. I would appreciate any suggestions that you have.
>
> Best,
> John-Paul Ferguson
> Assistant Professor of Organizational Behavior
> Stanford University Graduate School of Business
> 518 Memorial Way, K313
> Stanford, CA 94305
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Referencing variable names rather than column numbers

2009-12-05 Thread Ista Zahn
As baptiste noted, you can do

cor(pollute[ ,c("Pollution","Temp","Industry")]).

But

cor(pollute[,"Pollution":"Industry"])

will not work. For that you can do

cor(pollute[ 
,which(names(pollute)=="Pollution"):which(names(pollute)=="Industry")])

-Ista

On Sat, Dec 5, 2009 at 11:22 AM, John-Paul Ferguson
 wrote:
> I apologize for how basic a question this is. I am a Stata user who
> has begun using R, and the syntax differences still trip me up. The
> most basic questions, involving as they do general terms, can be the
> hardest to find solutions for through search.
>
> Assume for the moment that I have a dataset that contains seven
> variables: Pollution, Temp, Industry, Population, Wind, Rain and
> Wet.days. (This actual dataset is taken from Michael Crawley's
> "Statistics: An Introduction Using R" and is available as
> "pollute.txt" in
> http://www.bio.ic.ac.uk/research/crawley/statistics/data/zipped.zip.)
> Assume I have attached pollute. Then
>
> cor(pollute)
>
> will give me the correlation table for these seven variables. If I
> would prefer only to see the correlations between, say, Pollution,
> Temp and Industry, I can get that with
>
> cor(pollute[,1:3])
>
> or with
>
> cor(pollute[1:3])
>
> Similarly, I can see the correlations between Temp, Population and Rain with
>
> cor(pollute[,c(2,4,6)])
>
> or with
>
> cor(pollute[c(2,4,6)])
>
> This is fine for a seven-variable dataset. When I have 250 variables,
> though, I start to pale at looking up column indexes over and over. I
> know from reading the list archives that I can extract the column
> index of Industry, for example, by typing
>
> which("Industry"==names(pollute))
>
> but doing that before each command seems dire. Trained to using Stata
> as I am, I am inclined to check the correlation of the first three or
> the second, fourth and sixth columns by substituting the column names
> for the column indexes--something like the following:
>
> cor(pollute[Pollution:Industry])
> cor(pollute[c(Temp,Population,Rain)])
>
> These however throw errors.
>
> I know that many commands in R are perfectly happy to take variable
> names--the regression models, for example--but that some do not. And
> so I ask you two general questions:
>
> 1. Is there a syntax for referring to variable names rather than
> column indexes in situations like these?
> 2. Is there something that I should look for in a command's help file
> that often indicates whether it can take column names rather than
> indexes?
>
> Again, apologies for asking something that has likely been asked
> before. I would appreciate any suggestions that you have.
>
> Best,
> John-Paul Ferguson
> Assistant Professor of Organizational Behavior
> Stanford University Graduate School of Business
> 518 Memorial Way, K313
> Stanford, CA 94305
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

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


Re: [R] categorical vs numerical

2009-12-05 Thread Peter Ehlers

pkg:lattice is installed as part of the base R distribution.
You don't need to install it.

DispersionMap wrote:

Thanks, ill give them whirl...when i was installing the lattice package i got
the error in bold below...why does it say permission denied and what effect
does this have?

I guess that you're on Vista and don't have write permission
for that directory.

 -Peter Ehlers



utils:::menuInstallLocal()

package 'lattice' successfully unpacked and MD5 sums checked
updating HTML package descriptions
Warning message:
In file.create(f.tg) :
  cannot create file 'C:\PROGRA~1\R\R-29~1.2/doc/html/packages.html', reason
'Permission denied'


local({pkg <- select.list(sort(.packages(all.available = TRUE)))

+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
Warning message:
package 'lattice' was built under R version 2.10.0 

I have it loaded 




Peter Ehlers wrote:

Whoops, that should be

  densityplot(~y|g, data=dat, plot.points=FALSE, layout=c(1,4))

  -Peter Ehlers

Peter Ehlers wrote:

You could try density plots:
If dat is your dataframe, y is your numerical vector and
g is your factor,

library(lattice)
trellis.device(height=9, width=7)
densityplot(~g|y, data=dat, plot.points=FALSE, layout=c(1,4))

See ?densityplot, ?panel.densityplot

 -Peter Ehlers

DispersionMap wrote:

Thanks, however the group sizes are really big (each a,b,c.. category
has
60,000 observations). Its hard to see whats going on withe the jittered
stripchart, i just get big black blobs.

Any other suggestions?




Peter Ehlers wrote:

If your group sizes are not too large, I would use jittered
stripcharts.
They're more informative than boxplots and much less subject to
misinterpretation. One warning, I'm not fond of the default pch=0.

 -Peter Ehlers

DispersionMap wrote:

What ways are there to plot categorical vs numerical data in R.


I have two columns: one with categorical data in 5 categories 
a,b,c,d,e,

and
a numerical column with integers between 1 and 100.

I have used a boxplot with a,b,c,d,e on the x-axis and an increasing
numerical scale on the y-axis. This look fine but im looking for other
ways
to present the data.


What other ways can i do this???


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

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

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


Re: [R] Referencing variable names rather than column numbers

2009-12-05 Thread baptiste auguie
Hi,

Try this,

cor(pollute[ ,c("Pollution","Temp","Industry")])

and ?"[" in particular,
"Character vectors will be matched to the names of the object "

HTH,

baptiste

2009/12/5 John-Paul Ferguson :
> I apologize for how basic a question this is. I am a Stata user who
> has begun using R, and the syntax differences still trip me up. The
> most basic questions, involving as they do general terms, can be the
> hardest to find solutions for through search.
>
> Assume for the moment that I have a dataset that contains seven
> variables: Pollution, Temp, Industry, Population, Wind, Rain and
> Wet.days. (This actual dataset is taken from Michael Crawley's
> "Statistics: An Introduction Using R" and is available as
> "pollute.txt" in
> http://www.bio.ic.ac.uk/research/crawley/statistics/data/zipped.zip.)
> Assume I have attached pollute. Then
>
> cor(pollute)
>
> will give me the correlation table for these seven variables. If I
> would prefer only to see the correlations between, say, Pollution,
> Temp and Industry, I can get that with
>
> cor(pollute[,1:3])
>
> or with
>
> cor(pollute[1:3])
>
> Similarly, I can see the correlations between Temp, Population and Rain with
>
> cor(pollute[,c(2,4,6)])
>
> or with
>
> cor(pollute[c(2,4,6)])
>
> This is fine for a seven-variable dataset. When I have 250 variables,
> though, I start to pale at looking up column indexes over and over. I
> know from reading the list archives that I can extract the column
> index of Industry, for example, by typing
>
> which("Industry"==names(pollute))
>
> but doing that before each command seems dire. Trained to using Stata
> as I am, I am inclined to check the correlation of the first three or
> the second, fourth and sixth columns by substituting the column names
> for the column indexes--something like the following:
>
> cor(pollute[Pollution:Industry])
> cor(pollute[c(Temp,Population,Rain)])
>
> These however throw errors.
>
> I know that many commands in R are perfectly happy to take variable
> names--the regression models, for example--but that some do not. And
> so I ask you two general questions:
>
> 1. Is there a syntax for referring to variable names rather than
> column indexes in situations like these?
> 2. Is there something that I should look for in a command's help file
> that often indicates whether it can take column names rather than
> indexes?
>
> Again, apologies for asking something that has likely been asked
> before. I would appreciate any suggestions that you have.
>
> Best,
> John-Paul Ferguson
> Assistant Professor of Organizational Behavior
> Stanford University Graduate School of Business
> 518 Memorial Way, K313
> Stanford, CA 94305
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Referencing variable names rather than column numbers

2009-12-05 Thread John-Paul Ferguson
I apologize for how basic a question this is. I am a Stata user who
has begun using R, and the syntax differences still trip me up. The
most basic questions, involving as they do general terms, can be the
hardest to find solutions for through search.

Assume for the moment that I have a dataset that contains seven
variables: Pollution, Temp, Industry, Population, Wind, Rain and
Wet.days. (This actual dataset is taken from Michael Crawley's
"Statistics: An Introduction Using R" and is available as
"pollute.txt" in
http://www.bio.ic.ac.uk/research/crawley/statistics/data/zipped.zip.)
Assume I have attached pollute. Then

cor(pollute)

will give me the correlation table for these seven variables. If I
would prefer only to see the correlations between, say, Pollution,
Temp and Industry, I can get that with

cor(pollute[,1:3])

or with

cor(pollute[1:3])

Similarly, I can see the correlations between Temp, Population and Rain with

cor(pollute[,c(2,4,6)])

or with

cor(pollute[c(2,4,6)])

This is fine for a seven-variable dataset. When I have 250 variables,
though, I start to pale at looking up column indexes over and over. I
know from reading the list archives that I can extract the column
index of Industry, for example, by typing

which("Industry"==names(pollute))

but doing that before each command seems dire. Trained to using Stata
as I am, I am inclined to check the correlation of the first three or
the second, fourth and sixth columns by substituting the column names
for the column indexes--something like the following:

cor(pollute[Pollution:Industry])
cor(pollute[c(Temp,Population,Rain)])

These however throw errors.

I know that many commands in R are perfectly happy to take variable
names--the regression models, for example--but that some do not. And
so I ask you two general questions:

1. Is there a syntax for referring to variable names rather than
column indexes in situations like these?
2. Is there something that I should look for in a command's help file
that often indicates whether it can take column names rather than
indexes?

Again, apologies for asking something that has likely been asked
before. I would appreciate any suggestions that you have.

Best,
John-Paul Ferguson
Assistant Professor of Organizational Behavior
Stanford University Graduate School of Business
518 Memorial Way, K313
Stanford, CA 94305

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


Re: [R] Partial correlations and p-values

2009-12-05 Thread Juliet Hannah
Your R code looks correct.

Because this is a straightforward calculation, I would be surprised if there
were any differences with SPSS. It may be worthwhile to check
if SPSS  gives partial correlations or semipartial correlations. For example,
if you take the correlation between

py <- resid(lm(y ~ z1 + z2,data=mydat2))

and

x

where mydat2 has missing values removed, you get 0.47.

On Tue, Dec 1, 2009 at 8:24 PM, dadrivr  wrote:
>
> I am trying to calculate a partial correlation and p-values.  Unfortunately,
> the results in R are different than what SPSS gives.
>
> Here is an example in R (calculating the partial correlation of x and y,
> controlling for z1 and z2):
>
> x <- c(1,20,14,30,9,4,8)
> y <- c(5,6,7,9,NA,10,6)
> z1 <- c(13,8,16,14,26,13,20)
> z2 <- c(12,NA,2,5,8,16,13)
> fmx <- lm(x ~ z1 + z2, na.action = na.exclude)
> fmy <- lm(y ~ z1 + z2, na.action = na.exclude)
> yres <- resid(fmy)
> xres <- resid(fmx)
> cor(xres, yres, use = "p")
> ct <- cor.test(xres, yres)
> ct$estimate
> ct$p.value
>
> R give me:
> r = .65, p = .23
>
> However, SPSS calculates:
> r = .46, p = .70
>
> I think something may be different with R's handling of missing data, as
> when I replace the NA's with values, R and SPSS give the same r-values,
> albeit different p-values still.  I am doing pairwise case exclusion in both
> R and SPSS.  Any ideas why I'm getting different values?  Is something wrong
> with my formula in R?  Any help would be greatly appreciated.  Thanks!
>

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


Re: [R] "R CMD BATCH" continue after an error in the script

2009-12-05 Thread David Winsemius


On Dec 5, 2009, at 9:21 AM, Veronesi, Fabio wrote:

Hi,
I have a problem with R CMD BATCH, because I created a .bat file to  
run a script:


C:\R\R-2.9.2\bin\R CMD BATCH C:\Scrip_test.R

It work perfectly but after 3 lines of script there is a line with a  
nls() function that cannot be fitted and this end in an error message.
I'm not bother by the error message, I just want that the script  
continue.


The try function will provide a mechaism for gracefully "stepping  
around" coding potholes.


?try

If I use the R windows GUI the script show the error message but it  
continue till the very end.
I want that the script continue to run also in BATCH mode, How can I  
do that?


Many thanks in advance,
Fabio


Fabio Veronesi
Ph.D Student

Cranfield University
School of Applied Sciences



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] "R CMD BATCH" continue after an error in the script

2009-12-05 Thread Hrishi Mittal

Fabio,

If you're not using the nls() function's result, then why don't you comment
it out from the script? That way, there will be no error and the script will
work fine.

Please post your script if you need further help.


Veronesi, Fabio wrote:
> 
> 
> Hi,
> I have a problem with R CMD BATCH, because I created a .bat file to run a
> script:
> 
> C:\R\R-2.9.2\bin\R CMD BATCH C:\Scrip_test.R
> 
> It work perfectly but after 3 lines of script there is a line with a nls()
> function that cannot be fitted and this end in an error message.
> I'm not bother by the error message, I just want that the script continue.
> 
> If I use the R windows GUI the script show the error message but it
> continue till the very end. 
> I want that the script continue to run also in BATCH mode, How can I do
> that?
> 
> Many thanks in advance,
> Fabio
> 
> 
> Fabio Veronesi
> Ph.D Student
> 
> Cranfield University
> School of Applied Sciences
> Building 37
> Cranfield, Bedforshire
> MK43 0AL
> 
> tel. +4407984049316
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://n4.nabble.com/R-CMD-BATCH-continue-after-an-error-in-the-script-tp949199p949207.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] "R CMD BATCH" continue after an error in the script

2009-12-05 Thread Veronesi, Fabio

Hi,
I have a problem with R CMD BATCH, because I created a .bat file to run a 
script:

C:\R\R-2.9.2\bin\R CMD BATCH C:\Scrip_test.R

It work perfectly but after 3 lines of script there is a line with a nls() 
function that cannot be fitted and this end in an error message.
I'm not bother by the error message, I just want that the script continue.

If I use the R windows GUI the script show the error message but it continue 
till the very end. 
I want that the script continue to run also in BATCH mode, How can I do that?

Many thanks in advance,
Fabio


Fabio Veronesi
Ph.D Student

Cranfield University
School of Applied Sciences
Building 37
Cranfield, Bedforshire
MK43 0AL

tel. +4407984049316

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


Re: [R] paste adjacent elements matching string

2009-12-05 Thread Henrique Dallazuanna
Try this also:

sapply(grep("string$", vec), function(idx)paste(vec[idx + 0:1], collapse = ""))


On Fri, Dec 4, 2009 at 11:42 PM, Jill Hollenbach  wrote:
> Hi all,
> I would like to combine elements of a vector:
>
> vec <- c("astring",  "b", "cstring",  "d", "e")
>  > vec
> [1] "astring" "b"       "cstring" "d"       "e"
>
> such that for every element that contains  "string" at the end, it is
> combined with the next element, so that I get this:
>
>  > res
> [1] "astringb" "cstringd" "e"
>
> Any help is much appreciated, still learning.
>
> Many thanks,
> Jill
>
>
>
>
> 
>     Jill Hollenbach, PhD, MPH
>     Associate Staff Scientist
>     Center for Genetics
>     Children's Hospital Oakland Research Institute
>     jhollenb...@chori.org
>     skype: jillah11
>
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

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


Re: [R] paste adjacent elements matching string

2009-12-05 Thread Gray Calhoun
A different approach than those other people listed would be to change
the vector into a matrix (by setting its dimension, if you don't need
to keep the original vector) and then applying paste along one of the
dimensions.  Obviously, you'd need to pad the end of the vector with
NAs or empty strings.  Since you have a working solution, I won't
write code... but this approach might be a little easier to scale if,
for example, you need to concatenate every three elements of the
vector.
Best,
Gray

On Fri, Dec 4, 2009 at 5:42 PM, Jill Hollenbach  wrote:
> Hi all,
> I would like to combine elements of a vector:
>
> vec <- c("astring",  "b", "cstring",  "d", "e")
>  > vec
> [1] "astring" "b"       "cstring" "d"       "e"
>
> such that for every element that contains  "string" at the end, it is
> combined with the next element, so that I get this:
>
>  > res
> [1] "astringb" "cstringd" "e"
>
> Any help is much appreciated, still learning.
>
> Many thanks,
> Jill
>
>
>
>
> 
>     Jill Hollenbach, PhD, MPH
>     Associate Staff Scientist
>     Center for Genetics
>     Children's Hospital Oakland Research Institute
>     jhollenb...@chori.org
>     skype: jillah11
>
>
>
>
>
>
>        [[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.
>



-- 
Gray Calhoun

Assistant Professor of Economics
Iowa State 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] HELP boxplot for time class

2009-12-05 Thread Gabor Grothendieck
Try this:

Lines <- " protokollid datestart  end
4 2/23/2009  8:50:10 15:17:30
4 2/24/2009  9:47:00 13:52:25
5 3/22/2009  8:51:25 12:00:05"

library(chron)
skiers <- read.table(textConnection(Lines), header = TRUE, as.is = TRUE)
skiers <- transform(skiers, date = dates(date),
start = times(start), end = times(end))

bp <- boxplot(as.numeric(skiers$start), yaxt = "n")
axis(2, bp$stats, times(bp$stats), las = 2, cex.axis = 0.5)


On Sat, Dec 5, 2009 at 6:52 AM, uvilla  wrote:

>
> hi again
>
> I will try this time to explain my problem clearly
> I have the following data from the file skiing.csv (3 first rows)
>
>  protokollid datestart  end
> 14 2/23/2009  8:50:10 15:17:30
> 24 2/24/2009  9:47:00 13:52:25
> 35 3/22/2009  8:51:25 12:00:05
>
>
> I have the following script
>
> library(chron)
>
> skiers=read.csv("skiing.csv")
> strptime("08:50:10","%H:%M:%S")
>
> start=times(skiers[,3])
> strptime(start,"%H:%M:%S")
> end=times(skiers[,4])
> strptime(end,"%H:%M:%S")
>
> #calc lenght of the route
> length.route=end-start
>
> #calc medians
> median(start)
> median(length.route)
>
> Then I want to do a box plot of the staring time
> when I use:
>
> boxplot(start)
>
> this error appears: Warning message:
> In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
>
> when I try to convert start as POSIXct
>
> > start=as.POSIXct(start)
> Error in as.POSIXct.default(start) :
>  do not know how to convert 'start' to class "POSIXlt"
>
> and when I try to convert skiers[,3] as POSIXct
>
> > skiers[,3]=as.POSIXct(skiers[,3])
> Error in as.POSIXlt.character(as.character(x)) :
>  character string is not in a standard unambiguous format
>
> start is of "times" class and skiers[,3] of "factor" class
>
> I want to do a boxplot of the starting time of my data, which reflect the
> median " 08:36:45", and all O get in the y axis are decimal numbers :(
> Help please
>
> Best regards
>
> Maria Stauss
>
>
> --
> View this message in context:
> http://n4.nabble.com/HELP-boxplot-for-time-class-tp949154p949154.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] categorical vs numerical

2009-12-05 Thread DispersionMap

Thanks, ill give them whirl...when i was installing the lattice package i got
the error in bold below...why does it say permission denied and what effect
does this have?

> utils:::menuInstallLocal()
package 'lattice' successfully unpacked and MD5 sums checked
updating HTML package descriptions
Warning message:
In file.create(f.tg) :
  cannot create file 'C:\PROGRA~1\R\R-29~1.2/doc/html/packages.html', reason
'Permission denied'

> local({pkg <- select.list(sort(.packages(all.available = TRUE)))
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
Warning message:
package 'lattice' was built under R version 2.10.0 

I have it loaded 



Peter Ehlers wrote:
> 
> Whoops, that should be
> 
>   densityplot(~y|g, data=dat, plot.points=FALSE, layout=c(1,4))
> 
>   -Peter Ehlers
> 
> Peter Ehlers wrote:
>> You could try density plots:
>> If dat is your dataframe, y is your numerical vector and
>> g is your factor,
>> 
>> library(lattice)
>> trellis.device(height=9, width=7)
>> densityplot(~g|y, data=dat, plot.points=FALSE, layout=c(1,4))
>> 
>> See ?densityplot, ?panel.densityplot
>> 
>>  -Peter Ehlers
>> 
>> DispersionMap wrote:
>>> Thanks, however the group sizes are really big (each a,b,c.. category
>>> has
>>> 60,000 observations). Its hard to see whats going on withe the jittered
>>> stripchart, i just get big black blobs.
>>>
>>> Any other suggestions?
>>>
>>>
>>>
>>>
>>> Peter Ehlers wrote:
 If your group sizes are not too large, I would use jittered
 stripcharts.
 They're more informative than boxplots and much less subject to
 misinterpretation. One warning, I'm not fond of the default pch=0.

  -Peter Ehlers

 DispersionMap wrote:
> What ways are there to plot categorical vs numerical data in R.
>
>
> I have two columns: one with categorical data in 5 categories 
> a,b,c,d,e,
> and
> a numerical column with integers between 1 and 100.
>
> I have used a boxplot with a,b,c,d,e on the x-axis and an increasing
> numerical scale on the y-axis. This look fine but im looking for other
> ways
> to present the data.
>
>
> What other ways can i do this???
>
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 Ehlers
> University of Calgary
> 403.202.3936
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://n4.nabble.com/categorical-vs-numerical-tp948817p949178.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Using rgl to put a graphic beneath a plot

2009-12-05 Thread Duncan Murdoch

On 05/12/2009 3:07 AM, Colin Wyers wrote:

I've written a very simple bit of code to plot a trajectory using rgl:

 


x <- 
(c(0,-5.947,-11.496,-16.665,-21.474,-25.947,-30.116,-34.017,-37.684,-41.148,-44.435,-47.568,-50.567,-53.448,-56.223,-58.906))
y <- 
(c(0,33.729,65.198,94.514,121.784,147.151,170.797,192.920,213.717,233.360,252.003,269.774,286.781,303.117,318.858,334.071))
z <- 
(c(3,11.914,19.629,26.066,31.167,34.902,37.262,38.257,37.903,36.221,33.233,28.964,23.442,16.696,8.761,-0.325))
plot3d(x,y,z, type='l',axes=FALSE, box=FALSE)

 


I have a PNG file that I want to place the plot on top of. I've arranged the 
image so that the point at x=282 px and y=52 px should correspond with the 
origin of the graph.


One way is to use the PNG file as a texture on a rectangle behind the 
line.  demo(flag) does a fairly elaborate example of this.  See 
?rgl.surface for the description of how to do it.


Another way is to use the image on the background sphere; example(bg3d) 
and demo(envmap) do this.


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] Using rgl to put a graphic beneath a plot

2009-12-05 Thread Colin Wyers

I've written a very simple bit of code to plot a trajectory using rgl:

 

x <- 
(c(0,-5.947,-11.496,-16.665,-21.474,-25.947,-30.116,-34.017,-37.684,-41.148,-44.435,-47.568,-50.567,-53.448,-56.223,-58.906))
y <- 
(c(0,33.729,65.198,94.514,121.784,147.151,170.797,192.920,213.717,233.360,252.003,269.774,286.781,303.117,318.858,334.071))
z <- 
(c(3,11.914,19.629,26.066,31.167,34.902,37.262,38.257,37.903,36.221,33.233,28.964,23.442,16.696,8.761,-0.325))
plot3d(x,y,z, type='l',axes=FALSE, box=FALSE)

 

I have a PNG file that I want to place the plot on top of. I've arranged the 
image so that the point at x=282 px and y=52 px should correspond with the 
origin of the graph.

 

Thanks in advance for your help,

--CW
  
_


id=1&media=aero-shake-7second&listid=1&stop=1&ocid=PID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_7secdemo:122009
[[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] categorical vs numerical

2009-12-05 Thread Peter Ehlers

Whoops, that should be

 densityplot(~y|g, data=dat, plot.points=FALSE, layout=c(1,4))

 -Peter Ehlers

Peter Ehlers wrote:

You could try density plots:
If dat is your dataframe, y is your numerical vector and
g is your factor,

library(lattice)
trellis.device(height=9, width=7)
densityplot(~g|y, data=dat, plot.points=FALSE, layout=c(1,4))

See ?densityplot, ?panel.densityplot

 -Peter Ehlers

DispersionMap wrote:

Thanks, however the group sizes are really big (each a,b,c.. category has
60,000 observations). Its hard to see whats going on withe the jittered
stripchart, i just get big black blobs.

Any other suggestions?




Peter Ehlers wrote:

If your group sizes are not too large, I would use jittered stripcharts.
They're more informative than boxplots and much less subject to
misinterpretation. One warning, I'm not fond of the default pch=0.

 -Peter Ehlers

DispersionMap wrote:

What ways are there to plot categorical vs numerical data in R.


I have two columns: one with categorical data in 5 categories 
a,b,c,d,e,

and
a numerical column with integers between 1 and 100.

I have used a boxplot with a,b,c,d,e on the x-axis and an increasing
numerical scale on the y-axis. This look fine but im looking for other
ways
to present the data.


What other ways can i do this???


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

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

2009-12-05 Thread uvilla

hi again

I will try this time to explain my problem clearly
I have the following data from the file skiing.csv (3 first rows)

 protokollid datestart  end
14 2/23/2009  8:50:10 15:17:30
24 2/24/2009  9:47:00 13:52:25
35 3/22/2009  8:51:25 12:00:05


I have the following script

library(chron) 

skiers=read.csv("skiing.csv")
strptime("08:50:10","%H:%M:%S") 

start=times(skiers[,3])
strptime(start,"%H:%M:%S")  
end=times(skiers[,4])
strptime(end,"%H:%M:%S") 

#calc lenght of the route
length.route=end-start

#calc medians
median(start)
median(length.route) 

Then I want to do a box plot of the staring time
when I use:

boxplot(start)   

this error appears: Warning message:
In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'

when I try to convert start as POSIXct

> start=as.POSIXct(start)
Error in as.POSIXct.default(start) : 
  do not know how to convert 'start' to class "POSIXlt"

and when I try to convert skiers[,3] as POSIXct

> skiers[,3]=as.POSIXct(skiers[,3])
Error in as.POSIXlt.character(as.character(x)) : 
  character string is not in a standard unambiguous format

start is of "times" class and skiers[,3] of "factor" class

I want to do a boxplot of the starting time of my data, which reflect the
median " 08:36:45", and all O get in the y axis are decimal numbers :(
Help please

Best regards

Maria Stauss


-- 
View this message in context: 
http://n4.nabble.com/HELP-boxplot-for-time-class-tp949154p949154.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] categorical vs numerical

2009-12-05 Thread Peter Ehlers

You could try density plots:
If dat is your dataframe, y is your numerical vector and
g is your factor,

library(lattice)
trellis.device(height=9, width=7)
densityplot(~g|y, data=dat, plot.points=FALSE, layout=c(1,4))

See ?densityplot, ?panel.densityplot

 -Peter Ehlers

DispersionMap wrote:

Thanks, however the group sizes are really big (each a,b,c.. category has
60,000 observations). Its hard to see whats going on withe the jittered
stripchart, i just get big black blobs.

Any other suggestions?




Peter Ehlers wrote:

If your group sizes are not too large, I would use jittered stripcharts.
They're more informative than boxplots and much less subject to
misinterpretation. One warning, I'm not fond of the default pch=0.

 -Peter Ehlers

DispersionMap wrote:

What ways are there to plot categorical vs numerical data in R.


I have two columns: one with categorical data in 5 categories a,b,c,d,e,
and
a numerical column with integers between 1 and 100.

I have used a boxplot with a,b,c,d,e on the x-axis and an increasing
numerical scale on the y-axis. This look fine but im looking for other
ways
to present the data.


What other ways can i do this???


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

2009-12-05 Thread DispersionMap

Thanks, however the group sizes are really big (each a,b,c.. category has
60,000 observations). Its hard to see whats going on withe the jittered
stripchart, i just get big black blobs.

Any other suggestions?




Peter Ehlers wrote:
> 
> If your group sizes are not too large, I would use jittered stripcharts.
> They're more informative than boxplots and much less subject to
> misinterpretation. One warning, I'm not fond of the default pch=0.
> 
>  -Peter Ehlers
> 
> DispersionMap wrote:
>> What ways are there to plot categorical vs numerical data in R.
>>
>>
>> I have two columns: one with categorical data in 5 categories a,b,c,d,e,
>> and
>> a numerical column with integers between 1 and 100.
>>
>> I have used a boxplot with a,b,c,d,e on the x-axis and an increasing
>> numerical scale on the y-axis. This look fine but im looking for other
>> ways
>> to present the data.
>>
>>
>> What other ways can i do this???
>>
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://n4.nabble.com/categorical-vs-numerical-tp948817p949117.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] paste adjacent elements matching string

2009-12-05 Thread Jill Hollenbach

thanks so much, this did the trick!
Jill


Gabor Grothendieck wrote:
> 
> Try this which assumes that comma does not appear in any of the strings.
> You can substitute a different non-appearing character if a comma does
> appear in any of the strings:
> 
> strsplit(gsub("string,", "string", paste(vec, collapse = ",")), ",")[[1]]
> 
> It first runs all the strings together into a single comma-separate string
> using paste and then replaces each occurrence of "string," with "string"
> using gsub.  Finally it breaks the long string back up into individual
> strings using strsplit.
> 
> On Fri, Dec 4, 2009 at 8:42 PM, Jill Hollenbach
> wrote:
> 
>> Hi all,
>> I would like to combine elements of a vector:
>>
>> vec <- c("astring",  "b", "cstring",  "d", "e")
>>  > vec
>> [1] "astring" "b"   "cstring" "d"   "e"
>>
>> such that for every element that contains  "string" at the end, it is
>> combined with the next element, so that I get this:
>>
>>  > res
>> [1] "astringb" "cstringd" "e"
>>
>> Any help is much appreciated, still learning.
>>
>> Many thanks,
>> Jill
>>
>>
>>
>>
>> 
>> Jill Hollenbach, PhD, MPH
>> Associate Staff Scientist
>> Center for Genetics
>> Children's Hospital Oakland Research Institute
>> jhollenb...@chori.org
>> skype: jillah11
>>
>>
>>
>>
>>
>>
>>[[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.
> 
> 

-- 
View this message in context: 
http://n4.nabble.com/paste-adjacent-elements-matching-string-tp949036p949111.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.