[R] regression questions (lm, lmer)

2011-04-15 Thread Iasonas Lamprianou
Dear all, 

I hope this is the right place to ask this question.

I am reviewing a research where the analyst(s) are using a linear regression 
model. The dependent variable (DV) is a continuous measure. The independent 
variables (IVs) are a mixture of linear and categorical variables.

The author investigates whether performance (DV - continuous linear) is a 
function of age (continuous IV1 - measured in years), previous performance 
(continuous IV2), country (categorical IV3 - six countries), the percentage of 
PhD graduates in each country (continuous IV4 - country level data - apparently 
only six different percentages since we have only six countries) and population 
of country (continuous IV5 - country level data - again only six numbers here, 
one for each country population).

My own opinion is that the lm function cannot be used with country level data 
as IVs (for example IV4 and IV5 cannot be entered into the model because they 
are country level data). If IV4 and IV5 are included in the model, it is 
possible that the model will not be able to be defined because we only have six 
countries and it is very likely that the levels of counties (IV3) may be 
confounding with IV4 and IV5. This also calls for multicollinearity issues, 
right? I would like to suggest to the analyst to use lmer using the IV3 as a 
random variable and  IV4 and IV5 as IV at the second level of the two-level 
model. 


The questions are: (a) Is it true that IV4 and IV5 cannot be entered in a 
one-level regression if we also have IV3?, (b) can I use an lm function to 
check for multicollinearity between IV3, IV4 and IV5?  and (c) If we use a 
two-level regression model, does lmer cope well with only six coutnries as a 
random effect?

Thank you for your help

Jason
[[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] Launcher for Rattle?

2011-04-15 Thread Prof Brian Ripley

This is a result of bugs in rattle.

The first bug is that you are explicitly asked on its help page not to 
use installed.packages() in that way.


Second, packages should be able to be loaded in a session with just 
base loaded, so rattle's startup code should have 
utils::installed.packages().  (In this case it is invoked from 
rattle(), AFAICS, hence not invoked in the loading tests in R CMD 
check.)


However, your startup code is wrong: from ?options

 ‘defaultPackages’: the packages that are attached by default when
  R starts up.  Initially set from value of the environment
  variable ‘R_DEFAULT_PACKAGES’, or if that is unset to
  ‘c("datasets", "utils", "grDevices", "graphics", "stats",
  "methods")’.  (Set ‘R_DEFAULT_PACKAGES’ to ‘NULL’ or a
  comma-separated list of package names.)
  ^^^

And by default, R_DEFAULT_PACKAGES is unset.  Try

sh -c 'R_DEFAULT_PACKAGES="datasets,utils,grDevices,graphics,stats,rattle" R 
"$@"'

(You may or may not need 'methods' as well.)

On Sat, 16 Apr 2011, Iurie Malai wrote:


I tried this:

sh -c 'R_DEFAULT_PACKAGES="$R_DEFAULT_PACKAGES rattle" R "$@"'

but without success. I get this message:

R version 2.13.0 (2011-04-13)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i486-pc-linux-gnu (32-bit)

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.

Rattle: A free graphical interface for data mining with R.
Version 2.6.6 Copyright (c) 2006-2011 Togaware Pty Ltd.
Error : .onAttach failed in attachNamespace() for 'rattle', details:
 call: rownames(installed.packages())
 error: could not find function "installed.packages"
Rattle: A free graphical interface for data mining with R.
Version 2.6.6 Copyright (c) 2006-2011 Togaware Pty Ltd.
Error : .onAttach failed in attachNamespace() for 'rattle', details:
 call: rownames(installed.packages())
 error: could not find function "installed.packages"
In addition: Warning message:
package ???rattle??? in options("defaultPackages") was not found
During startup - Warning message:
package ???rattle??? in options("defaultPackages") was not found


2011/4/16 Iurie Malai 


How to make a launcher for Rattle?

Regards,
Iurie Malai
Moldova Pedagogical State University



[[alternative HTML version deleted]]




--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] is "Gb" gigabyte or gigabit?

2011-04-15 Thread Mike Miller

I sometimes get errors of this form:

Error: cannot allocate vector of size 13.8 Gb


I've also seen "Gb" used in R documents.  Is "Gb" being used to refer to 
gigabyte?  We usually refer to bytes and gigabytes when discussing memory 
usage, but the lowercase "b" more often refers to bits.  According to 
Wikipedia:


  http://en.wikipedia.org/wiki/Gigabyte

  "The unit symbol for the gigabyte is GB or Gbyte, but not Gb (lower
  case b) which is typically used for the gigabit."

If "Gb" means gigabyte in R, I can live with that, but I think it is 
ambiguous and confusing.  If it does mean gigabit, I think we should refer 
to gigabytes instead when discussing memory usage.


Mike

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 add two data.frame with the same column but different row numbers

2011-04-15 Thread zhenjiang xu
Thanks, Gabor. It's a nice workaround. I'll look more at zoo library.

On Fri, Apr 15, 2011 at 7:10 PM, Gabor Grothendieck  wrote:

> On Fri, Apr 15, 2011 at 6:10 PM, zhenjiang xu 
> wrote:
> > Thanks, Dennis! I'll go with it. It's surprising there is no ready way to
> do
> > that. I imagine it should be a common data manipulation to add two
> > data.frame from two different sources. It could happen that one
> data.frame
> > is missing some rows while the other have some more.
> >
>
> If you represent them as zoo series then you can do it using +
> (although the definition of + is different than in your post).   Here
> "a", "b" and "c" are the "times":
>
> library(zoo)
> a <- zoo(1:3, letters[1:3])
> b <- zoo(c(6, 1), c("a", "c"))
> a+b
>
> The last line gives:
>
> > a+b
> a c
> 7 4
>
> To use the definition in your post one could do this (which has the
> effect of modifying b so that a+b works as in your post):
>
> merge(a, b, fill = 0, retclass = NULL)
> a+b
>
> The last line gives:
>
> > a+b
> a b c
> 7 2 4
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>



-- 
Best,
Zhenjiang

[[alternative HTML version deleted]]

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


[R] How to make truncated y axis (cut mark) in R plot?

2011-04-15 Thread Bill Hyman
Hi friends,

Does anyone know how to make truncated y axis with cut mark (\\) in R plot? 
Many 
thanks!

Bill

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


Re: [R] Conveting SAS Proc mixed to R code

2011-04-15 Thread RKinzer
I am desperate for help and thank you to everyone providing input.

I am using lme4 for a mixed linear model, and trying to replicate a SAS
analysis (see thread below).

Variables:
Dependent = logrkm; Independent = Group (Streams grouped by similarity),
Treatment (3 treatments), Stream, Time (1 or 2; before treatment and after),
Year (-8, -7,...7, 8; each yearly observation;negs before treatment and
positive after).

Design:
Blocking by stream group results in unbalanced repeated measures with 3
treatments arranged in blocks with various numbers of observations (Streams)
per treatment-block.  Stream, Group, and Year are random variables and
Treatment and Time are fixed effects.

I have tried the following code, but can't seem to replicate the SAS
results.  Please correct the model below if you see where I am wrong, I am
also open to other suggestions.  

m2<-lmer(logrkm~Treatment*Time+(Treatment|Stream:Group)+(1|Year),data=prototype)

Thank you.

--
View this message in context: 
http://r.789695.n4.nabble.com/Conveting-SAS-Proc-mixed-to-R-code-tp3450626p3452937.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] lme4 problem: model defining and effect estimation ------ question from new bird to R community from SAS community

2011-04-15 Thread Nilaya Sharma
My question was how can we estimate effects and define correct
model equivalent to SAS code provided.

On Fri, Apr 15, 2011 at 10:21 PM, Nilaya Sharma wrote:

> Hi R community,
>
> I am new bird to R and moved recently from SAS. I am no means expert on
> either but very curious learner. So your help crucial for me to learn R.
> I have already got positive expression.
>
> I was trying to fit a mixed model in animal experiment but stuck at simple
> point. The following similar example is from SAS mixed model pp 212.
>
> # data
>
> genetic_evaluation <- read.table(textConnection("
> sire dam adg
> 1  1  2.24
> 1  1  1.85
> 1  2  2.05
> 1  2  2.41
> 2  1  1.99
> 2  1  1.93
> 2  2  2.72
> 2  2  2.32
> 3  1  2.33
> 3  1  2.68
> 3  2  2.69
> 3  2  2.71
> 4  1  2.42
> 4  1  2.01
> 4  2  1.86
> 4  2  1.79
> 5  1  2.82
> 5  1  2.64
> 5  2  2.58
> 5  2  2.56"), header = TRUE)
>
> # my R practice codes
> require (lme4)
>  lmer(adg ~ 1 + (1|sire) + (1|dam/sire), data=genetic_evaluation)
>
>  error message88
>  Error: length(f1) == length(f2) is not TRUE
> In addition: Warning messages:
> 1: In sire:dam : numerical expression has 20 elements: only the first used
> 2: In sire:dam : numerical expression has 20 elements: only the first used
>
> **how can I estimate the BLUP effects?*
> #equavalent code in SAS
> proc mixed data=genetic_evaluation;
>class sire dam;
>model adg= / ddfm=kr;
>random sire dam(sire);
>estimate 'sire 1 BLUP "broad" '
> intercept 1 | sire 1 0;
>estimate 'sire 1 BLUP "narrow" '
> intercept 2 | sire 2 0
> dam(sire) 1 1  0 0  0 0  0 0  0 0  / divisor=2;
>estimate 'sire 1 BLUP with dam 1'
> intercept 1 | sire 1 0
> dam(sire) 1 0;
>ods select CovParms Estimates;
> run;
>
> # Estimate statement define predictable functions. All fixed effect
> cofficient must appear first and then random effect coefficients. The fixed
> and random
> #effect cofficient are seperated by |
>
> Expected outputs according to SAS
> *
>   Estimate
> sire 1 BLUP "broad2.2037
> sire 1 BLUP "narrow"  2.1609
> sire 1 BLUP with dam1 2.1002
>
>  Data details:
> The data is animal science data in which five sires were randomly sampled
> from the population and were randomly mated with two dams.
> Two offspring per sire dam combination were measured. Average daily gain
> was recorded. We are interested in breeding value of ith sire(means that
> which
> gives offsprings with higher gain
>
> NIL
>

[[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] patterned non-random jitter

2011-04-15 Thread Daryl Morris

Hi,

Is there a function somewhere that does a "patterned" jitter of data?  
I've googled and the problem is that I don't know what to google for.


The setting is in grouped data.  I have plots which overlay jittered 
points on a boxplot.  I simply jitter the "x-value", and the "y-value" 
has no effect.


Scientists I work with frequently show plots made by another software 
where the jitter looks like a bunch smiles stacked on top of each 
other.  The jitter isn't random, but instead depends on the "y-value" 
somehow.


thanks, Daryl
SCHARP, FHCRC, UW Biostatistics

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


[R] lme4 problem: model defining and effect estimation ------ question from new bird to R community from SAS community

2011-04-15 Thread Nilaya Sharma
Hi R community,

I am new bird to R and moved recently from SAS. I am no means expert on
either but very curious learner. So your help crucial for me to learn R.
I have already got positive expression.

I was trying to fit a mixed model in animal experiment but stuck at simple
point. The following similar example is from SAS mixed model pp 212.

# data

genetic_evaluation <- read.table(textConnection("
sire dam adg
1  1  2.24
1  1  1.85
1  2  2.05
1  2  2.41
2  1  1.99
2  1  1.93
2  2  2.72
2  2  2.32
3  1  2.33
3  1  2.68
3  2  2.69
3  2  2.71
4  1  2.42
4  1  2.01
4  2  1.86
4  2  1.79
5  1  2.82
5  1  2.64
5  2  2.58
5  2  2.56"), header = TRUE)

# my R practice codes
require (lme4)
 lmer(adg ~ 1 + (1|sire) + (1|dam/sire), data=genetic_evaluation)

 error message88
 Error: length(f1) == length(f2) is not TRUE
In addition: Warning messages:
1: In sire:dam : numerical expression has 20 elements: only the first used
2: In sire:dam : numerical expression has 20 elements: only the first used

**how can I estimate the BLUP effects?*
#equavalent code in SAS
proc mixed data=genetic_evaluation;
   class sire dam;
   model adg= / ddfm=kr;
   random sire dam(sire);
   estimate 'sire 1 BLUP "broad" '
intercept 1 | sire 1 0;
   estimate 'sire 1 BLUP "narrow" '
intercept 2 | sire 2 0
dam(sire) 1 1  0 0  0 0  0 0  0 0  / divisor=2;
   estimate 'sire 1 BLUP with dam 1'
intercept 1 | sire 1 0
dam(sire) 1 0;
   ods select CovParms Estimates;
run;

# Estimate statement define predictable functions. All fixed effect
cofficient must appear first and then random effect coefficients. The fixed
and random
#effect cofficient are seperated by |

Expected outputs according to SAS
*
  Estimate
sire 1 BLUP "broad2.2037
sire 1 BLUP "narrow"  2.1609
sire 1 BLUP with dam1 2.1002

 Data details:
The data is animal science data in which five sires were randomly sampled
from the population and were randomly mated with two dams.
Two offspring per sire dam combination were measured. Average daily gain was
recorded. We are interested in breeding value of ith sire(means that which
gives offsprings with higher gain

NIL

[[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] Rsquared for anova

2011-04-15 Thread Dorien Herremans
Hi,

Thank you for your suggestion.

I am stil quite new to the syntax of R. I tried in a few ways but all
produced errors:

> fit <- lm((tos~nh1*nh2*nh3*randsize*aweights*tt1*tt2*tt3*iters*length,
data=expdata))
Error: unexpected ',' in "fit <-
lm((tos~nh1*nh2*nh3*randsize*aweights*tt1*tt2*tt3*iters*length,"
> fit <- lm(tos~nh1*nh2*nh3*randsize*aweights*tt1*tt2*tt3*iters*length)
Error in eval(expr, envir, enclos) : object 'tos' not found
> summary.lm(tos~nh1*nh2*nh3*randsize*aweights*tt1*tt2*tt3*iters*length)
Error in if (p == 0) { : argument is of length zero

Thanks for any additional insight...

Dorien

On 15 April 2011 18:07, Dieter Menne  wrote:

>
> dorien wrote:
> >
> > I calculate an anova test in the following way:
> >
> > ... aov example
> >
> > I want to check the fit of the model with Rsquared
> >
>
> Try summary(lm(...)) instead.
>
> Dieter
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Rsquared-for-anova-tp3452399p3452434.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.
>



-- 
Dorien Herremans

[[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] 'tcltk' does not have a name space

2011-04-15 Thread annihination
I am having the same problem on R-2.13.0. Anybody have ideas? Thanks!

--
View this message in context: 
http://r.789695.n4.nabble.com/tcltk-does-not-have-a-name-space-tp3020504p3452810.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] Cannot access to PDF manuals from R console

2011-04-15 Thread Duncan Murdoch

On 11-04-15 10:20 PM, Fred wrote:

I recently installed version 2.13, however when I click the manual
from the console, the error message appears


Error: 'doc\manual\refman.pdf' not found
Error: 'doc\manual\R-intro.pdf' not found


Does anyone know about what's happening?


We just noticed this as well.  It appears to only affect some Windows 
versions.  It should be fixed in R-patched from revision r55459 or 
higher.  Binary builds of those will be available within a few days.


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] spatstat regression troubles

2011-04-15 Thread Gregory Ryslik
Hi Everyone,

I am trying to figure out the spatstat package for the first time and am having 
some trouble. Unfortunately, I can't post my data set but I'll hopefully post 
enough details for some help.

I want to model the intensity of a spatial point process using 2 covariates 
from my data. After reading through the documentation, I have successfully 
created 2 "ppp" objects. The first ppp object is a list of coordinates where 
people exist and the second is where people do not exist as follows:

> people_exist
 planar point pattern: 944 points 
window: rectangle = [73, 135] x [18, 54] units  
> people_empty
 planar point pattern: 2828 points 
window: rectangle = [73, 135] x [18, 54] units  
> 


Now, I also have observed values for two covariates, Z1 and Z2 for both the 944 
and 2828 points in dataframe form. Finally, following the documentation, I was 
able to create one quadrature Q, with 944 points and 2828 dummy points that 
correctly takes the points where we had an event (people_exist) and the points 
where we don't have an event (people_empty).

> people_quadrature
Quadrature scheme
944 data points,  2828 dummy points
Total weight  1098.64 

How do I use the Quadrature to model my intensity based off of those two 
covariates and an intercept term alpha? In mathematical terms, if \lambda is my 
intensity function, I want to estimate \lambda(s;b) = exp(alpha + b_1 * Z_1 + 
b_2 * Z_2).

Thank you for your help! I really appreciate it.

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


[R] Cannot access to PDF manuals from R console

2011-04-15 Thread Fred
I recently installed version 2.13, however when I click the manual
from the console, the error message appears


Error: 'doc\manual\refman.pdf' not found
Error: 'doc\manual\R-intro.pdf' not found


Does anyone know about what's happening?

Thank you very much

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


Re: [R] Sweave Executes Package Functions Twice

2011-04-15 Thread Rolf Turner

On 16/04/11 00:38, Duncan Murdoch wrote:


In version 2.14.0 in the fall, this will no longer be the default 
behaviour.  Perhaps it will be possible to suppress the multiple runs 
before then, but I think it is unlikely that the default will change.




It already ***is*** the fall (or autumn, more properly speaking), on the
***good*** side of the world! :-)  R is bihemispherical. :-)

cheers,

Rolf

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


Re: [R] Idetntifying nearest topographic contours to data points

2011-04-15 Thread Rolf Turner

On 16/04/11 04:18, sam.e wrote:

Hi there,
I have two data sets, one of locations at different elevations (x,y,z) and
the other of points that make up topographic contours (also x,y,z). I have
used:

result<-apply(distppll(data2,cbind(topocon[-nrow(topocon),],topocon[-1,])),1,min)

where 'data2' are my measurement coordinates (x, y) and 'topocon' are my
topographic contours (x,y). While this gives me an output of the distance
from each data point to the nearest topographic contour point, I would also
like to output the 'z' value of the nearest topographic point to each data
point. Does anyone know how I could go about this?

Ideally what I would like to output is a matrix which has:
data elevation (data2$z) distance to nearest contourelevation of
nearest contour (topocon$z)

Any help would be much appreciated.


I presume you are using the distppll() function from the "spatstat" package.

If so I believe that you can get at what you want by setting the "mintype"
argument of this function equal to 2:

distppll(whatever,mintype=2)

This will cause disppll() to return the index of the line segment which 
is nearest
to each point.  You can then, with a modicum of effort, extract the 
associated

altitude (i.e. z) value.

This leaves the somewhat vexing issue of which *end* of the segment to use
to determine z.  Presumably there will be at least a slight difference 
between
the altitudes of the endpoints, and disppll() just gives the distance 
from the
point to the segment; it doesn't --- as it stands --- tell you which 
endpoint of

the segment is nearest to the point in question.  (It may of course be the
case that the point on the segment which is nearest to the point in question
is *not* an endpoint of the segment.)

Presuming that you are satisfied with obtaining the endpoint of each segment
which is nearest each of your locations and then obtaining the altitude 
of that

endpoint, may I suggest that you

* convert the collection of segments to a point pattern, using the
   endpoints() function

* use crossdist() to obtain the distances from each location 
(having represented

   the collections of locations as a point pattern) to each endpoint

* use which.min() applied to the rows of the resulting matrix of 
distances

   to find the index of the endpoint which achieves the minimum, whence
   you can work out the associated altitude.

It might be convenient to make the associated altitude values into the 
"marks"

component of the respective point patterns.

HTH.

cheers,

Rolf Turner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 add two data.frame with the same column but different row numbers

2011-04-15 Thread Gabor Grothendieck
On Fri, Apr 15, 2011 at 6:10 PM, zhenjiang xu  wrote:
> Thanks, Dennis! I'll go with it. It's surprising there is no ready way to do
> that. I imagine it should be a common data manipulation to add two
> data.frame from two different sources. It could happen that one data.frame
> is missing some rows while the other have some more.
>

If you represent them as zoo series then you can do it using +
(although the definition of + is different than in your post).   Here
"a", "b" and "c" are the "times":

library(zoo)
a <- zoo(1:3, letters[1:3])
b <- zoo(c(6, 1), c("a", "c"))
a+b

The last line gives:

> a+b
a c
7 4

To use the definition in your post one could do this (which has the
effect of modifying b so that a+b works as in your post):

merge(a, b, fill = 0, retclass = NULL)
a+b

The last line gives:

> a+b
a b c
7 2 4

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

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


Re: [R] Monte Carlo Simulation

2011-04-15 Thread MacQueen, Don
The filenames can be done within a loop, like this:

for (id in 1:1000) {
  ## the filename
  fname <- paste('sample', formatC(id,width=4,flag='0'),'.tsv',sep='')

   ## more stuff
}


-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





-Original Message-
From: Shane Phillips 
Date: Fri, 15 Apr 2011 11:49:48 -0700
To: "r-help@r-project.org" 
Subject: [R] Monte Carlo Simulation

>Hello, R friends...
>
>I am very new to R, and I need some help.  I am trying to construct a
>simulation for my dissertation.
>
>I need to create 1000 datasets of 1000 subjects with the following
>variables...
>
>Treatment variable - Drawn from a binomial distribution (1 run, prob=.13)
>Covariate 1 - Drawn from a normal distribution (mean=100, sd=16)
>Covariate 2 - Drawn from a normal distribution (mean=200, sd=9)
>Covariates 1 and 2 need to be correlated (say, r=.80)
>Covariate 3 - Drawn from a binomial distribution (1 run, prob=.5)
>Covariate 4 - Drawn from a distribution of discrete variables where 1 has
>an 80% chance of being selected, 2  - 10%, 3 - 5% and 4 - 5%.  This
>variable would need to be recoded into 4 binary variables.
>Covariate 5 - Drawn from a normal distribution (mean=84, sd=2)
>Covariate 6 - Drawn from a binomial distribution (1 run, prob=.15)
>Covariate 6 needs to correlate with Covariate 2 (r=.70, or so)
>
>I need each dataset saved as a new datafile with an iterative filename
>(e.g. sample1, sample2, etc.).
>
>Please help!
>
>Thanks!
>
>Shane
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/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] Monte Carlo Simulation

2011-04-15 Thread MacQueen, Don
See below:

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





-Original Message-
From: Jeremy Miles 
Date: Fri, 15 Apr 2011 14:17:13 -0700
To: Shane Phillips 
Cc: "r-help@r-project.org" 
Subject: Re: [R] Monte Carlo Simulation

>On 15 April 2011 12:03, Shane Phillips  wrote:
>> Here's a script of what I have so far.  I have a few problems.  First,
>>the correlations.  Next, recoding that categorical variable into
>>dichotomous variables.  Finally, the iterative filename thing.
>>
>
> Where?
>
>Perhaps give the list one question at a time?
>
>Here's a start for one of the questions, selected (almost) at random.
>Give 80% of people a score of 1 on a x1, and 20% of people zero.
>
>tempVar <- runif(1000)
>x1 <- ifelse(tempVar < 0.8, 1, 0)
>rm(tempVar)

x1 <- rbinom(1000,1,0.8)

>
>
>Tell us how far you've got.  Do you need to know about write.table()
>for the saving the files, or is the problem with splitting a large
>file, or generating the 1000 names ...
>
>
>Jeremy
>
>
>
>-- 
>Jeremy Miles
>Psychology Research Methods Wiki: www.researchmethodsinpsychology.com
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] GLM and normality of predictors

2011-04-15 Thread Ben Bolker
Sacha Viquerat  web.de> writes:

> 
> Am 15.04.2011 20:14, schrieb Christian Hennig:
> > Normality of the predictors doesn't belong to the assumptions of the
> > GLM, so you don't have to check this.
> >
> > On Fri, 15 Apr 2011, Simone Santoro wrote:
> >
> >> I want to estimate the possible effects of some predictors on my
> >> response variable that is n? of males and n? of females
> >> (cbind(males,females)), so, it would be:
> >>
> >> fullmodel<-glm(cbind(males,females)~pred1+pred2+pred3, binomial)
> >>
> if you count no of males and females, shouldn't you choose the poisson 
> family? maybe whoever you told you to check for normality referred to 
> that, since count data are not normally distributed (neither are their 
> errors)! maybe thats all he/she wants!


I think the original model using the binomial distribution
for the response seems entirely appropriate.

  I agree with the comment about tiny data sets:
the usual rule of thumb is that (# parameters) should 
be <(effective N)/10 -- so in practice estimating
anything more than a single binary or continuous predictor (both
of which require a single parameter to estimate) would be pushing
it.

  (Sad but true.)

  Ben Bolker

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


Re: [R] Monte Carlo Simulation

2011-04-15 Thread Shane Phillips
I apologize for my last post.  here is the script I forgot to paste!

subject=1:1000
treat=rbinom(1*1000,1,.13)
gender=rbinom(1*1000,1,.5)
eth=runif(1*1000, min=1, max=4)
cogat=rnorm(1*1000, 100, 16)
map=rnorm(1*1000, 200, 9)
growth=0
simtest=data.frame (subject=subject, treat=treat, gender=gender, 
eth=round(eth,digits=0), 
cogat=round(cogat,digits=0),map=round(map,digits=0),growth)
simtest<-transform(simtest, 
growth=rnorm(1000,m=ifelse(treat==0,0.1,0.5),s=0.03))
simtest

Once again the issues are the correlations, the recoding of the categorical 
variable and the iterations.

Thanks to all who have helped so far!  You are all so smart!

S

From: Charles Annis, P.E. [charles.an...@statisticalengineering.com]
Sent: Friday, April 15, 2011 3:00 PM
To: Shane Phillips; r-help@r-project.org
Subject: RE: [R] Monte Carlo Simulation

What have you tried so far?

It is often helpful to begin with a much simpler problem, then add
complexity incrementally until you've constructed the desired model.

Best wishes.

Charles Annis, P.E.

charles.an...@statisticalengineering.com
561-352-9699
http://www.StatisticalEngineering.com


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Shane Phillips
Sent: Friday, April 15, 2011 2:50 PM
To: r-help@r-project.org
Subject: [R] Monte Carlo Simulation

Hello, R friends...

I am very new to R, and I need some help.  I am trying to construct a
simulation for my dissertation.

I need to create 1000 datasets of 1000 subjects with the following
variables...

Treatment variable - Drawn from a binomial distribution (1 run, prob=.13)
Covariate 1 - Drawn from a normal distribution (mean=100, sd=16)
Covariate 2 - Drawn from a normal distribution (mean=200, sd=9)
Covariates 1 and 2 need to be correlated (say, r=.80)
Covariate 3 - Drawn from a binomial distribution (1 run, prob=.5)
Covariate 4 - Drawn from a distribution of discrete variables where 1 has an
80% chance of being selected, 2  - 10%, 3 - 5% and 4 - 5%.  This variable
would need to be recoded into 4 binary variables.
Covariate 5 - Drawn from a normal distribution (mean=84, sd=2)
Covariate 6 - Drawn from a binomial distribution (1 run, prob=.15)
Covariate 6 needs to correlate with Covariate 2 (r=.70, or so)

I need each dataset saved as a new datafile with an iterative filename (e.g.
sample1, sample2, etc.).

Please help!

Thanks!

Shane

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

2011-04-15 Thread Iurie Malai
I tried this:

sh -c 'R_DEFAULT_PACKAGES="$R_DEFAULT_PACKAGES rattle" R "$@"'

but without success. I get this message:

R version 2.13.0 (2011-04-13)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i486-pc-linux-gnu (32-bit)

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.

Rattle: A free graphical interface for data mining with R.
Version 2.6.6 Copyright (c) 2006-2011 Togaware Pty Ltd.
Error : .onAttach failed in attachNamespace() for 'rattle', details:
  call: rownames(installed.packages())
  error: could not find function "installed.packages"
Rattle: A free graphical interface for data mining with R.
Version 2.6.6 Copyright (c) 2006-2011 Togaware Pty Ltd.
Error : .onAttach failed in attachNamespace() for 'rattle', details:
  call: rownames(installed.packages())
  error: could not find function "installed.packages"
In addition: Warning message:
package ‘rattle’ in options("defaultPackages") was not found
During startup - Warning message:
package ‘rattle’ in options("defaultPackages") was not found


2011/4/16 Iurie Malai 

> How to make a launcher for Rattle?
>
> Regards,
> Iurie Malai
> Moldova Pedagogical State University
>

[[alternative HTML version deleted]]

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


Re: [R] Whole genome searching of 100bp "D" sequence

2011-04-15 Thread Ben Bolker
Amos Folarin  gmail.com> writes:

> I was wondering I'm going about this in the correct way. I need to test if
> there are coding sequences or exons in hg19 which match a string of 100bp
> "D" i.e. [A,G or T]. However I'm getting a strange result.
> 
> I get a hit on chr7, using the 100bp search however when I search with 60bp
> sequence of "D" I don't get any hits.
> 

  Try posting this to the Bioconductor e-mail list, where you will
have a much better likelihood of getting useful advice. Only a few
hard-core bioinformatics people on this list.  (Do mention that you
posted here first.)

  Ben Bolker

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


Re: [R] Function for deleting variables with >=50% missing obs from a data frame

2011-04-15 Thread Ben Bolker
Rita Carreira  hotmail.com> writes:

> I have several data frames where some of the variables have many
>  missing observations. For example, Q1 in
> one of my data frames has over 66% of its observations missing.
> I have tried imputation with mice but it does
> not work for all the data frames and I get the following
> message or a similar message to this:
>

  How about

missing_prop <- sapply(orig_data,function(x) { mean(is.na(x)) })
good_data <- orig_data[missing_prop>0.5]

 (untested)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 add two data.frame with the same column but different row numbers

2011-04-15 Thread zhenjiang xu
Thanks, Dennis! I'll go with it. It's surprising there is no ready way to do
that. I imagine it should be a common data manipulation to add two
data.frame from two different sources. It could happen that one data.frame
is missing some rows while the other have some more.

On Fri, Apr 15, 2011 at 5:10 PM, Dennis Murphy  wrote:

> Hi:
>
> Here's one approach:
>
> > df1 <- data.frame(x = letters[1:3], y = 1:3)
> > df2 <- data.frame(x = c('a', 'c'), z = c(6, 1))
> > dfm <- merge(df1, df2, all.x = TRUE)
> > dfm
>  x y  z
> 1 a 1  6
> 2 b 2 NA
> 3 c 3  1
> sumdf <- data.frame(x = dfm$x, y = rowSums(dfm[, -1], na.rm = TRUE))
>  x y
> 1 a 7
> 2 b 2
> 3 c 4
>
> HTH,
> Dennis
>
> On Fri, Apr 15, 2011 at 1:31 PM, zhenjiang xu 
> wrote:
> > Hi all,
> >
> > Suppose I have 2 data.frame , a and b, how can I add them together to get
> c?
> > Thanks
> >> a
> >  A
> > a 1
> > b 2
> > c 3
> >
> >> b
> >  A
> > a 6
> > c 1
> >
> >> c
> >   A
> > a 7
> > b 2
> > c 4
> >
> > --
> > Best,
> > Zhenjiang
> >
> >[[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.
> >
>



-- 
Best,
Zhenjiang

[[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] Function for deleting variables with >=50% missing obs from a data frame

2011-04-15 Thread Rita Carreira

Hello R users!
I have several data frames where some of the variables have many missing 
observations. For example, Q1 in one of my data frames has over 66% of its 
observations missing. I have tried imputation with mice but it does not work 
for all the data frames and I get the following message or a similar message to 
this:
 iter imp variable
  1   1  Q1  Q2  Q3  Q4  Q5  Q6  Q7  Q8  Q9  Q10  Q11  Q12  Q13  Q14  Q15  Q19  
Q36  Q47  Q52  Q79  Q80  Q94  Q97  Q104  Q108  Q122  Q131  Q134  P1  P2  P3  P4 
 P5  P6Error in solve.default(xtx + diag(pen)) : 
  system is computationally singular: reciprocal condition number = 1.83044e-16
In addition: Warning messages:
1: In sqrt((sum(residuals^2))/(sum(ry) - ncol(x) - 1)) : NaNs produced
...
7: In sqrt((sum(residuals^2))/(sum(ry) - ncol(x) - 1)) : NaNs produced
Note: warnings 2 to 6 suppressed by me.
I would like to try a different approach where I delete the variables that have 
more than 50% missing observations from the data frame (well, the actual 
percentage might change). I have already deleted from the data frame the 
variables that were all missing and for this I used the following code, which 
was kindly suggested by one of you:
## Data frame after removing any blank columns:dfQ <- dfQtemp[ , 
sapply(dfQtemp, function(x) !all(is.na(x)))]
 Any ideas or suggestons for deleting variables with partially missing data? 
Thanks and have a great weekend!
Rita = "If you think education is 
expensive, try ignorance."--Derek Bok


  
[[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] Launcher for Rattle?

2011-04-15 Thread Iurie Malai
How to make a launcher for Rattle?

Regards,
Iurie Malai
Moldova Pedagogical State University

[[alternative HTML version deleted]]

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


Re: [R] how to add two data.frame with the same column but different row numbers

2011-04-15 Thread Dennis Murphy
Hi:

Here's one approach:

> df1 <- data.frame(x = letters[1:3], y = 1:3)
> df2 <- data.frame(x = c('a', 'c'), z = c(6, 1))
> dfm <- merge(df1, df2, all.x = TRUE)
> dfm
  x y  z
1 a 1  6
2 b 2 NA
3 c 3  1
sumdf <- data.frame(x = dfm$x, y = rowSums(dfm[, -1], na.rm = TRUE))
  x y
1 a 7
2 b 2
3 c 4

HTH,
Dennis

On Fri, Apr 15, 2011 at 1:31 PM, zhenjiang xu  wrote:
> Hi all,
>
> Suppose I have 2 data.frame , a and b, how can I add them together to get c?
> Thanks
>> a
>  A
> a 1
> b 2
> c 3
>
>> b
>  A
> a 6
> c 1
>
>> c
>   A
> a 7
> b 2
> c 4
>
> --
> Best,
> Zhenjiang
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] prediction error in ROCR package when sampled y consists of only one class

2011-04-15 Thread Saeed Abu Nimeh
Try performing stratified sampling when doing cv.
cran.r-project.org/web/packages/ipred

On Fri, Apr 15, 2011 at 11:00 AM, Soyeon Kim  wrote:
> Dear R users,
>
> Hi. I am using prediction function in ROCR package.
> y consists of two classes 0 and 1.
> However, since I am using cross-validation, a sampled small number of
> y may consist of only one class
>>y
>  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> In this case, prediction function gives an error:
> Error in prediction(predic, y) : Number of classes is not equal to 2.
> ROCR currently supports only evaluation of binary classification tasks.
>
> How can I solve this problem?
>
> Thank you,
> Soyeon Kim
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Monte Carlo Simulation

2011-04-15 Thread Jeremy Miles
On 15 April 2011 12:03, Shane Phillips  wrote:
> Here's a script of what I have so far.  I have a few problems.  First, the 
> correlations.  Next, recoding that categorical variable into dichotomous 
> variables.  Finally, the iterative filename thing.
>

 Where?

Perhaps give the list one question at a time?

Here's a start for one of the questions, selected (almost) at random.
Give 80% of people a score of 1 on a x1, and 20% of people zero.

tempVar <- runif(1000)
x1 <- ifelse(tempVar < 0.8, 1, 0)
rm(tempVar)


Tell us how far you've got.  Do you need to know about write.table()
for the saving the files, or is the problem with splitting a large
file, or generating the 1000 names ...


Jeremy



-- 
Jeremy Miles
Psychology Research Methods Wiki: www.researchmethodsinpsychology.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] how to add two data.frame with the same column but different row numbers

2011-04-15 Thread zhenjiang xu
Hi all,

Suppose I have 2 data.frame , a and b, how can I add them together to get c?
Thanks
> a
  A
a 1
b 2
c 3

> b
  A
a 6
c 1

> c
   A
a 7
b 2
c 4

-- 
Best,
Zhenjiang

[[alternative HTML version deleted]]

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


Re: [R] How to view only error messages on R install in Ubuntu?

2011-04-15 Thread Iurie Malai
Sorry,
I meant:  when installing R packages with 'install.packages()'.

2011/4/15 Iurie Malai 

> Hi,
>
> When I install R in Ubuntu/Linux, is it possible to view only the error
> messages without the installation progress? And how?
>
> Regards,
> Iurie Malai
> Moldova Pedagogical State University
>

[[alternative HTML version deleted]]

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


[R] How to view only error messages on R install in Ubuntu?

2011-04-15 Thread Iurie Malai
Hi,

When I install R in Ubuntu/Linux, is it possible to view only the error
messages without the installation progress? And how?

Regards,
Iurie Malai
Moldova Pedagogical State University

[[alternative HTML version deleted]]

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


Re: [R] Extract information from the names of a list within lapply

2011-04-15 Thread Jun Shen
Thanks, Joshua and Henrique.

Henrique's solution is very interesting. Could you explain a bit more? What
does this grammar mean?

match.call()[[2]][[3]]

Jun

On Fri, Apr 15, 2011 at 1:27 PM, Henrique Dallazuanna wrote:

> Try this:
>
> lapply(mtcars, function(.)names(mtcars)[match.call()[[2]][[3]]])
>
> On Fri, Apr 15, 2011 at 3:14 PM, Jun Shen  wrote:
> > Dear list,
> >
> > I want to loop over a list through lapply and at the same time I want to
> > extract some information from the names of the list elements. lapply does
> > not seem to carry the names. Is there anyway to access the names of a
> list
> > within lapply? Thanks.
> >
> > Jun
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>

[[alternative HTML version deleted]]

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


Re: [R] Monte Carlo Simulation

2011-04-15 Thread Ista Zahn
Hi Shane,
See ?rbinom, ?rnorm, ?mvrnorm (in the MASS package), ?sample, ?for and
?write.table

Best,
Ista

On Fri, Apr 15, 2011 at 2:49 PM, Shane Phillips
 wrote:
> Hello, R friends...
>
> I am very new to R, and I need some help.  I am trying to construct a 
> simulation for my dissertation.
>
> I need to create 1000 datasets of 1000 subjects with the following 
> variables...
>
> Treatment variable - Drawn from a binomial distribution (1 run, prob=.13)
> Covariate 1 - Drawn from a normal distribution (mean=100, sd=16)
> Covariate 2 - Drawn from a normal distribution (mean=200, sd=9)
> Covariates 1 and 2 need to be correlated (say, r=.80)
> Covariate 3 - Drawn from a binomial distribution (1 run, prob=.5)
> Covariate 4 - Drawn from a distribution of discrete variables where 1 has an 
> 80% chance of being selected, 2  - 10%, 3 - 5% and 4 - 5%.  This variable 
> would need to be recoded into 4 binary variables.
> Covariate 5 - Drawn from a normal distribution (mean=84, sd=2)
> Covariate 6 - Drawn from a binomial distribution (1 run, prob=.15)
> Covariate 6 needs to correlate with Covariate 2 (r=.70, or so)
>
> I need each dataset saved as a new datafile with an iterative filename (e.g. 
> sample1, sample2, etc.).
>
> Please help!
>
> Thanks!
>
> Shane
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] GLM and normality of predictors

2011-04-15 Thread Sacha Viquerat

Am 15.04.2011 20:14, schrieb Christian Hennig:

Normality of the predictors doesn't belong to the assumptions of the
GLM, so you don't have to check this.

Note, however, that there are all kinds of potential problems which to
detect is fairly hopeless with n=11 and three predictors, so you
shouldn't be too confident about your results anyway.

Christian

On Fri, 15 Apr 2011, Simone Santoro wrote:



Hi,

I have found quite a few posts on normality checking of response
variables, but I am still in doubt about that. As it is easy to
understand I'm not a statistician so be patient please.
I want to estimate the possible effects of some predictors on my
response variable that is n? of males and n? of females
(cbind(males,females)), so, it would be:

fullmodel<-glm(cbind(males,females)~pred1+pred2+pred3, binomial)

I have n= 11 (ecological data, small sample size is a a frequent
problem!).

Someone told me that I have to check for normality of the predictors
(and in case transform to reach normality) but I am in doubt about the
fact that a normality test can be very informative with such a small
sample size.
Also, I have read that a normality test (Shapiro, Kolmogornov, Durbin,
etc.) can't tell you anything about the fact that the distribution is
normal but just that there is no evidence for non-normality.
Anyway, I am still looking for some sort of thumb of rule to be used
in these cases.

The question: is there some simple advice on the way one should
proceed in this cases to be reasonably confident of the results?

Thanks for any help you might provide

[[alternative HTML version deleted]]




*** --- ***
Christian Hennig
University College London, Department of Statistical Science
Gower St., London WC1E 6BT, phone +44 207 679 1698
chr...@stats.ucl.ac.uk, www.homepages.ucl.ac.uk/~ucakche

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

if you count no of males and females, shouldn't you choose the poisson 
family? maybe whoever you told you to check for normality referred to 
that, since count data are not normally distributed (neither are their 
errors)! maybe thats all he/she wants!


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


Re: [R] Monte Carlo Simulation

2011-04-15 Thread Shane Phillips
Here's a script of what I have so far.  I have a few problems.  First, the 
correlations.  Next, recoding that categorical variable into dichotomous 
variables.  Finally, the iterative filename thing.

Thanks!

S

-Original Message-
From: Charles Annis, P.E. [mailto:charles.an...@statisticalengineering.com] 
Sent: Friday, April 15, 2011 3:01 PM
To: Shane Phillips; r-help@r-project.org
Subject: RE: [R] Monte Carlo Simulation

What have you tried so far?

It is often helpful to begin with a much simpler problem, then add
complexity incrementally until you've constructed the desired model.

Best wishes.

Charles Annis, P.E.

charles.an...@statisticalengineering.com
561-352-9699
http://www.StatisticalEngineering.com


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Shane Phillips
Sent: Friday, April 15, 2011 2:50 PM
To: r-help@r-project.org
Subject: [R] Monte Carlo Simulation

Hello, R friends...

I am very new to R, and I need some help.  I am trying to construct a
simulation for my dissertation.

I need to create 1000 datasets of 1000 subjects with the following
variables...

Treatment variable - Drawn from a binomial distribution (1 run, prob=.13)
Covariate 1 - Drawn from a normal distribution (mean=100, sd=16)
Covariate 2 - Drawn from a normal distribution (mean=200, sd=9)
Covariates 1 and 2 need to be correlated (say, r=.80)
Covariate 3 - Drawn from a binomial distribution (1 run, prob=.5)
Covariate 4 - Drawn from a distribution of discrete variables where 1 has an
80% chance of being selected, 2  - 10%, 3 - 5% and 4 - 5%.  This variable
would need to be recoded into 4 binary variables.
Covariate 5 - Drawn from a normal distribution (mean=84, sd=2)
Covariate 6 - Drawn from a binomial distribution (1 run, prob=.15)
Covariate 6 needs to correlate with Covariate 2 (r=.70, or so)

I need each dataset saved as a new datafile with an iterative filename (e.g.
sample1, sample2, etc.). 

Please help!

Thanks!

Shane

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

2011-04-15 Thread Charles Annis, P.E.
What have you tried so far?

It is often helpful to begin with a much simpler problem, then add
complexity incrementally until you've constructed the desired model.

Best wishes.

Charles Annis, P.E.

charles.an...@statisticalengineering.com
561-352-9699
http://www.StatisticalEngineering.com


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Shane Phillips
Sent: Friday, April 15, 2011 2:50 PM
To: r-help@r-project.org
Subject: [R] Monte Carlo Simulation

Hello, R friends...

I am very new to R, and I need some help.  I am trying to construct a
simulation for my dissertation.

I need to create 1000 datasets of 1000 subjects with the following
variables...

Treatment variable - Drawn from a binomial distribution (1 run, prob=.13)
Covariate 1 - Drawn from a normal distribution (mean=100, sd=16)
Covariate 2 - Drawn from a normal distribution (mean=200, sd=9)
Covariates 1 and 2 need to be correlated (say, r=.80)
Covariate 3 - Drawn from a binomial distribution (1 run, prob=.5)
Covariate 4 - Drawn from a distribution of discrete variables where 1 has an
80% chance of being selected, 2  - 10%, 3 - 5% and 4 - 5%.  This variable
would need to be recoded into 4 binary variables.
Covariate 5 - Drawn from a normal distribution (mean=84, sd=2)
Covariate 6 - Drawn from a binomial distribution (1 run, prob=.15)
Covariate 6 needs to correlate with Covariate 2 (r=.70, or so)

I need each dataset saved as a new datafile with an iterative filename (e.g.
sample1, sample2, etc.). 

Please help!

Thanks!

Shane

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Whole genome searching of 100bp "D" sequence

2011-04-15 Thread Amos Folarin
Hi,
I was wondering I'm going about this in the correct way. I need to test if
there are coding sequences or exons in hg19 which match a string of 100bp
"D" i.e. [A,G or T]. However I'm getting a strange result.

I get a hit on chr7, using the 100bp search however when I search with 60bp
sequence of "D" I don't get any hits.


library("BSgenome")
library("Biostrings")
library("BSgenome.Hsapiens.UCSC.hg19")
library("biomaRt")
library("GenomicFeatures")




#extract the alignments which match real genes
#(add this onto stefans script … req to buid the gr object using the regions
from the BSgenome alignment of the 100bp seqs.)

txdb <- makeTranscriptDbFromUCSC(genome = "hg19", tablename = "knownGene")
## do once locally & save



#query.plus <-
DNAString("")
# 100bp C free sequence
query.plus <-
DNAString("") #
60bp C free sequence
query.minus <- reverseComplement(query.plus)


chrList <- c("chr1", "chr2", "chr3", "chr4", "chr5", "chr6", "chr7", "chr8",
"chr9", "chr10", "chr11", "chr12", "chr13", "chr14", "chr15", "chr16",
"chr17", "chr18", "chr19", "chr20", "chr21", "chr22", "chrX", "chrY")

#access/group the by subset of annotation
annotGr <- exons(txdb)
#annotGr <- cds(txdb)

wholeGenomeMatch <- function()
{
for(i in chrList)
{
#matches on plus strand
matches.plus.strand <- matchPattern(query.plus, Hsapiens[[i]],
fixed=FALSE, max.mismatch=5)
mp <- as.matrix(matches.plus.strand)

#matches on minus strand
matches.minus.strand <- matchPattern(query.minus, Hsapiens[[i]],
fixed=FALSE, max.mismatch=5)
mm <- as.matrix(matches.minus.strand)

OL.p <- NULL
if(nrow(mp) > 0)
{
# MATCH THE POSITIVE STRAND ##
#need to get start and end positions (end = start + (length-1))
gr <- GRanges(
seqnames = rep(i,nrow(mp)),
ranges = IRanges(start = mp[[1]],
end = mp[[1]]+(mp[,2]-1)),
strand = rep("+", nrow(mp)))

#OL <- findOverlaps(query=gr, subject=annotGr)
OL.p <- annotGr[(!is.na(match(annotGr, gr)))]
#as.data.frame(OL) ## view the results

#tdata.p <- annotGr[unique(queryHits(OL)),]
#tdata.p <- as.data.frame(tdata.p, row.names = NULL, optional = FALSE)

#write.table(tdata.p, paste(i,"plus.txt"))
cat( paste(i,"plus.txt\n"))
}

OL.m <- NULL
if(nrow(mm) > 0)
{
# MATCH THE MINUS STRAND 
#need to get start and end positions (end = start + (length-1))
gr <- GRanges(
seqnames = rep(i,nrow(mm)),
ranges = IRanges(start = mm[[1]],
end = mm[[1]]+(mm[,2]-1)),
strand = rep("-", nrow(mm)))

#OL <- findOverlaps(query=gr, subject=annotGr)
OL.m <- annotGr[(!is.na(match(annotGr, gr)))]
#tdata.m <- annotGr[unique(queryHits(OL)),]
#tdata.m <- as.data.frame(tdata.m, row.names = NULL, optional = FALSE)

#write.table(tdata.m, paste(i,"minus.txt"))

cat( paste(i,"minus.txt\n"))

#write.table(rbind(tdata.p, tdata.p), paste(i, ".txt"))
}

##write all matching results into one file
write.table(rbind(as.data.frame(OL.p), as.data.frame(OL.m)),
file="60bp_v_exons_max-mismatch=5.txt", append=TRUE)

}

}

wholeGenomeMatch()




#in the first instance with the 100bp search I get 1 hit in the output file:
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"1" "chr7" 420815 422845 2031 "+" 97277
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"

#with the 60 bp query string my output file reads no hits
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start" "end" "width" "strand" "exon_id"
"seqnames" "start

[R] Monte Carlo Simulation

2011-04-15 Thread Shane Phillips
Hello, R friends...

I am very new to R, and I need some help.  I am trying to construct a 
simulation for my dissertation.

I need to create 1000 datasets of 1000 subjects with the following variables...

Treatment variable - Drawn from a binomial distribution (1 run, prob=.13)
Covariate 1 - Drawn from a normal distribution (mean=100, sd=16)
Covariate 2 - Drawn from a normal distribution (mean=200, sd=9)
Covariates 1 and 2 need to be correlated (say, r=.80)
Covariate 3 - Drawn from a binomial distribution (1 run, prob=.5)
Covariate 4 - Drawn from a distribution of discrete variables where 1 has an 
80% chance of being selected, 2  - 10%, 3 - 5% and 4 - 5%.  This variable would 
need to be recoded into 4 binary variables.
Covariate 5 - Drawn from a normal distribution (mean=84, sd=2)
Covariate 6 - Drawn from a binomial distribution (1 run, prob=.15)
Covariate 6 needs to correlate with Covariate 2 (r=.70, or so)

I need each dataset saved as a new datafile with an iterative filename (e.g. 
sample1, sample2, etc.). 

Please help!

Thanks!

Shane

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


Re: [R] Extract information from the names of a list within lapply

2011-04-15 Thread Henrique Dallazuanna
Try this:

lapply(mtcars, function(.)names(mtcars)[match.call()[[2]][[3]]])

On Fri, Apr 15, 2011 at 3:14 PM, Jun Shen  wrote:
> Dear list,
>
> I want to loop over a list through lapply and at the same time I want to
> extract some information from the names of the list elements. lapply does
> not seem to carry the names. Is there anyway to access the names of a list
> within lapply? Thanks.
>
> Jun
>
>        [[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] Extract information from the names of a list within lapply

2011-04-15 Thread Joshua Wiley
Hi Jun,

On Fri, Apr 15, 2011 at 11:14 AM, Jun Shen  wrote:
> Dear list,
>
> I want to loop over a list through lapply and at the same time I want to
> extract some information from the names of the list elements. lapply does
> not seem to carry the names. Is there anyway to access the names of a list
> within lapply? Thanks.

Not in the way you are probably trying to do it, but consider:

## 1 (what you are probably doing)
lapply(mtcars, mean)
## 2 (an alternative)
lapply(colnames(mtcars), function(x) {cat(x, fill = TRUE); mean(mtcars[, x])})

The main downside of #2 is that it takes more code, and the resulting
output is not named.  However, it gives you all the flexibility you
need.

HTH,

Josh


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



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

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


Re: [R] GLM and normality of predictors

2011-04-15 Thread Christian Hennig
Normality of the predictors doesn't belong to the assumptions of the GLM, 
so you don't have to check this.


Note, however, that there are all kinds of potential problems which to 
detect is fairly hopeless with n=11 and three predictors, so you shouldn't 
be too confident about your results anyway.


Christian

On Fri, 15 Apr 2011, Simone Santoro wrote:



Hi,

I have found quite a few posts on normality checking of response variables, but 
I am still in doubt about that. As it is easy to understand I'm not a 
statistician so be patient please.
I want to estimate the possible effects of some predictors on my response 
variable that is n? of males and n? of females (cbind(males,females)), so, it 
would be:

fullmodel<-glm(cbind(males,females)~pred1+pred2+pred3, binomial)

I have n= 11 (ecological data, small sample size is a a frequent problem!).

Someone told me that I have to check for normality of the predictors (and in 
case transform to reach normality) but I am in doubt about the fact that a 
normality test can be very informative with such a small sample size.
Also, I have read that a normality test (Shapiro, Kolmogornov, Durbin, etc.) 
can't tell you anything about the fact that the distribution is normal but just 
that there is no evidence for non-normality.
Anyway, I am still looking for some sort of thumb of rule to be used in these 
cases.

The question: is there some simple advice on the way one should proceed in this 
cases to be reasonably confident of the results?

Thanks for any help you might provide

[[alternative HTML version deleted]]




*** --- ***
Christian Hennig
University College London, Department of Statistical Science
Gower St., London WC1E 6BT, phone +44 207 679 1698
chr...@stats.ucl.ac.uk, www.homepages.ucl.ac.uk/~ucakche

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


[R] Extract information from the names of a list within lapply

2011-04-15 Thread Jun Shen
Dear list,

I want to loop over a list through lapply and at the same time I want to
extract some information from the names of the list elements. lapply does
not seem to carry the names. Is there anyway to access the names of a list
within lapply? Thanks.

Jun

[[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] GLM and normality of predictors

2011-04-15 Thread Simone Santoro

Hi,

I have found quite a few posts on normality checking of response variables, but 
I am still in doubt about that. As it is easy to understand I'm not a 
statistician so be patient please.
I want to estimate the possible effects of some predictors on my response 
variable that is nº of males and nº of females (cbind(males,females)), so, it 
would be:

fullmodel<-glm(cbind(males,females)~pred1+pred2+pred3, binomial)

I have n= 11 (ecological data, small sample size is a a frequent problem!).

Someone told me that I have to check for normality of the predictors (and in 
case transform to reach normality) but I am in doubt about the fact that a 
normality test can be very informative with such a small sample size.
Also, I have read that a normality test (Shapiro, Kolmogornov, Durbin, etc.) 
can't tell you anything about the fact that the distribution is normal but just 
that there is no evidence for non-normality.
Anyway, I am still looking for some sort of thumb of rule to be used in these 
cases.

The question: is there some simple advice on the way one should proceed in this 
cases to be reasonably confident of the results?

Thanks for any help you might provide
  
[[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] nesting multiple for loops

2011-04-15 Thread Ben Hunter
Thanks Petr,

Actually, I figured it out last night. Please read on only if you're sort of
interested.

You're absolutely right, I hastily changed my function to be more 'readable'
without thinking that I was using a name that was already a function.

What I wanted was a cross-tabulation of f1 and f2 as they appeared in the
lengthy header names of my data.

Using 'lapply' would definitely have saved me some trouble, but it didn't
come to mind. It would mean I only had to use 1 loop instead of 2.

Eventually, I built in an 'if' step to handle the case when there was no
intersection for that given cell in the table and it made sure all the NA's
in my data were set to zero.

Thanks much for getting back, Petr.

-Ben

On Fri, Apr 15, 2011 at 3:18 AM, Petr PIKAL  wrote:

> Hi
>
> r-help-boun...@r-project.org napsal dne 15.04.2011 01:34:22:
>
> > Hi everyone.
> >
> > I am quite frustrated that this doesn't work, as all the functions
> within
> > work fine by themselves. I'd also like any pointers to how to avoid
> 'for'
> > loops in my code. I understand it's less than desirable, but I'm still
> quite
> > new and use them a lot.
> >
> > I have a few wide datasets (90 to 120) with long column names, each name
> > contains a number of different 'markers'. Each could be considered a
> factor
> > variable within the column name. Their are two categories of factors,
> we'll
> > call them f1 and f2.
> >
> > The data frame names look something like this:
> >  'ace_van' , 'boy_van', 'car_xes' , 'ace_xes', 'dog_wall' , 'car_zounds'
> >
> > f1 <- c('ace', 'boy', 'car', 'dog')
> > f2 <- c('van', 'wall', 'xes', 'zounds')# actual vectors are length 6
> and
> > 7, so I don't want to individually sum the 42 combinations.
> >
> > > var.table <- function(data, vec1, vec2)
> > {
> >   table <- as.data.frame(matrix(nrow = length(vec1), ncol =
> length(vec2)),
> > row.names = vec1)
> >   names(table) <- vec2
> >   for (i in 1:length(vec1))
> >   {
> > for (j in 1:length(vec2))
> > {
> >   indices <- intersect(grep(vec1[j], names(data), value = TRUE),
> > grep(cats[i], names(data), value = TRUE))
> >   table[i,j] <- sum(data[ ,indices])
> > }
> >   }
> > table
> > }
> >
> > > var.table(mydf, f1, f2)
> >
> > Output:
> >
> > Error in FUN(X[[1L]], ...) :
> > only defined on a data frame with all numeric variables
> >
> >
> > Every entry in mydf is an integer with no missing values.
>
> I can not provide solution as I can not decipher what you want to do but
> here are few comments.
>
> Do not use names of functions for naming objects e.g. table, it can be
> quite confusing.
> What is cats??
> Are you sure that mydf values are numbers?
>
> What does str(mydf) say?
>
> Do I understand that you want summarise all values in columns of data
> frame that have some common name?
>
>
> lapply(f2, grep, names(mydf))
>
> will give you list of indices of columns in mydf matching particular f2
> item. From this you can continue. Maybe plyr package can also be used.
>
> Regards
>
> Petr
>
> >
> > Thanks a ton.
> >
> > -Ben
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>

[[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] Idetntifying nearest topographic contours to data points

2011-04-15 Thread sam.e
Hi there, 
I have two data sets, one of locations at different elevations (x,y,z) and
the other of points that make up topographic contours (also x,y,z). I have
used:

result<-apply(distppll(data2,cbind(topocon[-nrow(topocon),],topocon[-1,])),1,min)

where 'data2' are my measurement coordinates (x, y) and 'topocon' are my
topographic contours (x,y). While this gives me an output of the distance
from each data point to the nearest topographic contour point, I would also
like to output the 'z' value of the nearest topographic point to each data
point. Does anyone know how I could go about this?

Ideally what I would like to output is a matrix which has:
data elevation (data2$z) distance to nearest contourelevation of
nearest contour (topocon$z)

Any help would be much appreciated,
Sam

--
View this message in context: 
http://r.789695.n4.nabble.com/Idetntifying-nearest-topographic-contours-to-data-points-tp3452462p3452462.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] question

2011-04-15 Thread Duncan Murdoch

On 15/04/2011 12:05 PM, Pamela Santelices Elgueta wrote:

I have a question, What is the maximum storage capacity of data that  R has?



There isn't a simple answer to this question.  Vectors have a maximum 
length of about 2 billion entries, and matrices are stored as vectors.  
Most often you will run out of memory before you hit that limit, because 
most functions in R work on data that's held in memory.  However, on a 
64 bit system you could have a lot of memory, and then it would be 
important.


Dataframes are lists of vectors, so they can be *much* larger than matrices.

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] Rsquared for anova

2011-04-15 Thread Dieter Menne

dorien wrote:
> 
> I calculate an anova test in the following way:
> 
> ... aov example 
> 
> I want to check the fit of the model with Rsquared
> 

Try summary(lm(...)) instead.

Dieter



--
View this message in context: 
http://r.789695.n4.nabble.com/Rsquared-for-anova-tp3452399p3452434.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] modify particular factor levels

2011-04-15 Thread Dieter Menne

baptiste auguie-5 wrote:
> 
> 
> I wish to modify programmatically only a few factor levels, according
> to a named list. I came up with this function..
> 
> .
> It seems to work, but the original order of the levels is changed.
> 
> 

The split-and-unite policy you use makes it a bit difficult to re-unite. You
could keep a copy of the original sequence, but it's probably easier to do
it via match. Note also that it also works for simple named vectors, which I
would prefer (I hate these generic lists, lapply).

You should probably think of the error case below. Maybe it is best to keep
it an error.

Dieter



modify.levels <- function(f, modify=list()){
  levs = levels(f)
  m = match(modify,levs)
  levs[m] = names(modify)
  factor(f,labels=levs)
}

f <- factor(c(LETTERS[1:4],LETTERS[1:2]))# Added a few more to avoid special
case
modify.levels(f, list(aa = "A", cc="C"))
modify.levels(f, c(aa = "A", cc="C"))
modify.levels(f, c(aa = "G", cc="C")) # Gives an error



--
View this message in context: 
http://r.789695.n4.nabble.com/modify-particular-factor-levels-tp3450862p3452417.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] question

2011-04-15 Thread Pamela Santelices Elgueta
I have a question, What is the maximum storage capacity of data that  R has?
Thanks


Pamela Santelices Elgueta
Estadístico
Instituto Nacional de Estadísticas
Fono: (56-2) 7962491
Paseo Bulnes 209 oficina 82
Santiago


[[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] Rsquared for anova

2011-04-15 Thread Dorien Herremans
I calculate an anova test in the following way:

expdata<-read.table("/home/dorien/UA/meta-music/optimuse/optimuse1-build-desktop/results/results_processedCP",
header=TRUE)

names(expdata)<-c('nh1','nh2','nh3','randsize','aweights','tt1','tt2','tt3','path','iters','type','length','tos','tws','time')

fit<-(aov(tos~nh1*nh2*nh3*randsize*aweights*tt1*tt2*tt3*iters*length,
data=expdata))

summary(fit)

I want to check the fit of the model with Rsquared, but I cannot seem to
find a way to do this...


Any help is much appreciated...

Thanks,

Dorien

[[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] no solution yet, please help: extract p-value from mixed model in kinship package

2011-04-15 Thread Ram H. Sharma
 I am making the question clear. Please help.



> Dear R experts
>
> I was using kinship package to fit mixed model with kinship matrix.
> The package looks like lme4, but I could find a way to extract p-value
> out of it. I need to extract is as I need to analyse large number of
> variables (> 1).
>
> Please help me:
>
> require(kinship)
>
> #Generating random example  data
>


> #pedigree data*


id <- 1:100

dadid <- c(rep(0, 5), rep(1, 5), rep(3, 5), rep(5, 5), rep(7, 10),
rep(9, 10), rep(11, 10), rep(13, 10), rep(15, 10), rep(17, 10),
rep(19, 10), rep(21, 10))

momid <- c(rep(0, 5), rep(2, 5), rep(4, 5), rep(6, 5), rep(8, 10),
rep(10, 10), rep(12, 10), rep(14, 10), rep(16, 10), rep(18, 10),
rep(20, 10), rep(22, 10) )

ped <- data.frame(id, dadid, momid)

# *kmatrix**

> cfam <- makefamid(ped$id,ped$momid, ped$dadid)
>
> kmat <- makekinship(cfam, ped$id, ped$momid, ped$dadid)
>
> #*x and y variables
*

> set.seed(3456)
>
> dat <- sample(c(-1,0,1), 1, replace = TRUE)
>
> snpmat<- data.frame(matrix(dat, ncol = 100))
>
> names(snpmat) <- c(paste ("VR",1:100, sep='' ))
>
> yvar <- rnorm(100, 30, 5)
> covtrait <-  rnorm(100, 10, 5)
>
> mydata <- data.frame(id, yvar, covtrait, snpmat)
>
#**mixed model in lmekin
***

>
> fmod <- lmekin(yvar ~ mydata[,3] , data= mydata, random = ~1|id,
> varlist=list(kmat)) $coefficients[2,4] # does not work
>
> # **error
> message



> Error message:

Error in lmekin(yvar ~ mydata[, 3], data = mydata, random = ~1 | id, varlist
= list(kmat))$coefficients[2,  :
  incorrect number of dimensions
In addition: Warning message:
In coxme.varcheck(ncluster, varlist, n, gvars, groups, sparse, rescale,  :
  Diagonal of variance matrix is not constant

#**ultimate target: to put in
loop***

> Ultimately I want to put into the loop:
>
> for(i in 3:length(mydata)) {
>
> P <- vector (mode="numeric", length = 1000)
>
> P[i] <- lmekin(yvar~ mydata[,i] , data= mydata, random = ~1|id,
> varlist=list(kmat)) $coefficients[2,4]
>
> }
>


> Same errors: I tried lme4 conventioned but did not work !



> I can extract fixed effects as well as I do in lme4
>  b <- fixef(fit1)
>


> Error in UseMethod("fixef") :
>   no applicable method for 'fixef' applied to an object of class "lmekin"
>
>
> --
>
> Ram H
>



-- 

Ram H

[[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] boxplot with 2 treatments and 2 variables (with 2 corresponding y-axes)

2011-04-15 Thread Ellis, David
Hi,

I am a complete newcomer to R and although I can plot standard box-plots I am 
struggling with this...

I have two treatments - A & B, and 2 variables 1 & 2. I want to compare 
boxplots of variable 1 with variable 2 for each treatment. I would also like 
them to all be on the same graphic.

I would like treatment to be on the x axis (A and B) and above A and B have 
their corresponding boxplots for both variables.I would also like 2 seperate 
y-axes, one for each variable - Variable 1 has a continuous y axis, and 
variable 2 is a percentage (of variable 1 in-fact, not that this should make a 
difference).

It would also be helpful if the boxplots were a different colour for each 
variable and that this corresponded somehow to the relevant axis. Or if someone 
can think of another way to show which treatment each boxplot is that would be 
gratefully recieved

Hope this makes sense and isn't too much of a pain to answer!

Thanks in advance
Dave


[[alternative HTML version deleted]]

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


Re: [R] help on compare two ranks

2011-04-15 Thread Uwe Ligges
Sounds like homework. Anyway, lookup rank correlations (Spearman, 
Kendall, etc.) and correpsonding tests.


Uwe Ligges


On 14.04.2011 17:00, Baoqiang Cao wrote:

Hi,

I have to one set of inputs and their observed true values of each
input. Now I have a model takes the input and predict a value. I only
consider the ranks based on either the observed true values or the
predicted values. My question is how do I compare this two rank in R?
That is, how close the rank from prediction to the rank from true
observations?

x_1: y_1, p_1,
x_2: y_2, p_2,
...
x_m: y_m, p_m,

R_y is the ranking based on {y_1, y_2,..,y_m}. R_p is the ranking from
{p_1, p_2, ..., p_m}. How do I know in R how good/bad R_p is given
R_y?

I searched r-help and got some clue of using wilcox.test but still a
bit confused of how to compare the two ranking against the true
ranking. Any advice will be highly appreciated. I apologize if this is
a too statistics question.

Thanks in advance.
Baoqiang

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] prediction error in ROCR package when sampled y consists of only one class

2011-04-15 Thread Uwe Ligges



On 15.04.2011 17:00, Soyeon Kim wrote:

Dear R users,

Hi. I am using prediction function in ROCR package.
y consists of two classes 0 and 1.
However, since I am using cross-validation, a sampled small number of
y may consist of only one class

y

  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


If this is the output for your y, it is not even a classification task, 
since your y is probably numeric rather than a factor.


Hence:
1. make it a factor with the desired number of levels.
2. in this case, the only useful prediction is class "0", hence you can 
easily special case and predict the only available class if only one is 
present.


Best wishes,
Uwe Ligges





In this case, prediction function gives an error:
Error in prediction(predic, y) : Number of classes is not equal to 2.
ROCR currently supports only evaluation of binary classification tasks.

How can I solve this problem?

Thank you,
Soyeon Kim

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

2011-04-15 Thread Uwe Ligges



On 12.04.2011 21:52, Zd Gibbs wrote:

Sorry, the first version was incomplete. I'm trying again.

I am running a regression equation and i want to enter in 12 IV then stepwise
enter 8 variables and not have an origin.

DV is "shfl".
I  want to enter in the following 12 independent dummy variables
ajan
bfeb
cmar
dapr
emay
fjun

And then I want to enter in a stepwise fashion
slag6
slag7
slag8
slag9
slag10
slag11
slag12

And finally, I want there to be no origin.

I've done simple regression, but nothing quite like this.



See ?step which allows to specify minimal, maximal models as well as 
forward stepwise selection.


BTW: Someone called Frank Harrell will shortly let you know about 
possible problems in model interpretation when using stepwise variable 
selection.


Best,
Uwe Ligges


I would appreciate your help.

Thanks

Zeda
[[alternative HTML version deleted]]




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


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


Re: [R] plotting line graphs for output from crosstabs function

2011-04-15 Thread Uwe Ligges

On 14.04.2011 12:47, taby gathoni wrote:


Hi R-users,

This is a generic question, is there a way to plot a line graph for the output 
from crosstable function? one of the inputs to the crosstab function is 
categorical.



Generic answer:  probably yes.

According to the posting guide, you have been asked to give a 
reproducible example, I do not even fin d the function you are talking 
about:


From subject line ("crosstabs function"):
> crosstabs
Error: object 'crosstabs' not found

From sentence 1 of your message ("crosstable function"):
> crosstable
Error: object 'crosstable' not found

From sentence 2 of your message ("crosstab function"):
> crosstab
Error: object 'crosstab' not found

PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html and provide commented, 
minimal, self-contained, reproducible code.


and do not send HTML!



Uwe Ligges




Taby --








[[alternative HTML version deleted]]

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


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


Re: [R] Trouble using "duleg" from labdsv

2011-04-15 Thread Uwe Ligges



On 14.04.2011 19:48, droberts wrote:

I apologize for the slow response, but I just registered with Nabble.

>


The duleg function in labdsv was renamed indval to be more consistent with
its use in the literature.  Typing ?indval will provide more information.

As an aside, all R functions have an email for the author or  maintainer
specified in the help file, and writing directly to the author is generally
quicker and more direct than posting to a forum, although obviously lots of
users have broad experience t contribute as well.


Well, and since this is at first a mailing list that got some nabble 
interface later on, please


1. quote the original message, so that mailing list readers can learn 
from your answers
2. please reply to the person who asked who may not be subscribed to the 
list you were responding to.


Best,
Uwe Ligges




--
View this message in context: 
http://r.789695.n4.nabble.com/Trouble-using-duleg-from-labdsv-tp3306061p3450290.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] automate package installation

2011-04-15 Thread Uwe Ligges



On 13.04.2011 02:11, jkang wrote:

I have an ubuntu image with R installed.  I want to install a list of
packages that does not come with R. eg. cluster, gplots, hacks, mapdata.
etc.  Over time this list may grow.

Is there a config file that can tell R what and where to install additional
packages?  My goal is to store all R packages on a file server so that my
clients can install them on there workstation.  Any tips, advice, example
commands, and scripts are greatly appreciated!



If such a network server is available for the clients, why not make
a) a network installation of R
b) provide the relevant packages in a library on the network, so that 
all clients can use the same library of R packages. You only need to 
maintain that library.


See "R Installation and Administration" on hwo to manage libraries of R 
packages.


Uwe Ligges


--
View this message in context: 
http://r.789695.n4.nabble.com/automate-package-installation-tp3445938p3445938.html
Sent from the R help mailing list archive at Nabble.com.

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


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


[R] prediction error in ROCR package when sampled y consists of only one class

2011-04-15 Thread Soyeon Kim
Dear R users,

Hi. I am using prediction function in ROCR package.
y consists of two classes 0 and 1.
However, since I am using cross-validation, a sampled small number of
y may consist of only one class
>y
 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
In this case, prediction function gives an error:
Error in prediction(predic, y) : Number of classes is not equal to 2.
ROCR currently supports only evaluation of binary classification tasks.

How can I solve this problem?

Thank you,
Soyeon Kim

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


Re: [R] Can't use attributes from gml file in Cytoscape

2011-04-15 Thread Gábor Csárdi
Hi,

the problem is that igraph puts node colors into the GML file as
simple vertex attributes, but this is not what Cytoscape expects.
Plus, it seems that Cytoscape does not read all the node/edge
attributes from the GML file, only the ones it interprets, so the
color information is lost.

Sadly, there is no real workaround here, because Cytoscape uses
composite node attributes for storing the node color information, but
igraph cannot currently write composite node attributes to GML files.

Luckily, however, the GML file format is quite simple, so you can just
write your own GML export function:

exportGML <- function(graph, filename) {
  file <- file(filename, "w")
  cat("Creator \"igraph exportGML\"\n", file=file)
  cat("Version 1.0\n", file=file)
  cat("graph\n[\n", file=file)
  cat("  directed", as.integer(is.directed(graph)), "\n", file=file)
  for (i in seq_len(vcount(graph))) {
cat("  node\n  [\n", file=file)
cat("id", i-1, "\n", file=file)
cat("graphics\n[\n", file=file)
cat("  fill \"", V(graph)$color[i], "\"\n", sep="", file=file)
cat("  type \"rectangle\"\n", file=file)
cat("  outline \"#00\"\n", file=file)
cat("]\n", file=file)
cat("  ]\n", file=file)
  }
  el <- get.edgelist(graph, names=FALSE)
  for (i in seq_len(nrow(el))) {
cat("  edge\n  [\n", file=file)
cat("source", el[i,1], "\n", file=file)
cat("target", el[i,2], "\n", file=file)
cat("  ]\n", file=file)
  }
  cat("]\n", file=file)
  close(file)
}

You can modify it according to your needs, e.g. add layout
coordinates, etc. Look into a GML file, as exported from Cytoscape, to
see what else you can add to the file.

Best,
Gabor


On Fri, Apr 15, 2011 at 9:25 AM, Sandeep Amberkar  wrote:
> Hello,
>
> I am exporting a graph in "gml" format from igraph 0.5.5. When I open the
> file in Cytoscape v.2.7 I can't map the color attribute that I assign to the
> graph when I export it from igraph. Could anyone help me in this?
> Thanks.
>
>
> --
> Warm Regards,
> Sandeep Amberkar
> BioQuant,BQ26,
> Im Neuenheimer Feld 267,
> D-69120,Heidelberg
> Tel: +49-6221-5451354
>
>        [[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.
>



-- 
Gabor Csardi      MTA KFKI RMKI

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


[R] Adding Time Series to data.frame without knowing the name of teh time series

2011-04-15 Thread Paolo Rossi
Hello,

quick question I reckon.

Is there a way to add to time series to a dataframe without knowing their
name in advance?

I can figure it out the following but wondered if there is a better way

Thanks

Paolo



a = data.frame(i = rep(100, 12))
colnames(a)[length(colnames)] = i

[[alternative HTML version deleted]]

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


Re: [R] as.matrix strangeness

2011-04-15 Thread Ista Zahn
Hi Michael,
It helps to look at the "Usage" section of the help pages. There you
will see that matrix() has an ncol argument, but as.matrix() does not.

Best,
Ista

On Fri, Apr 15, 2011 at 7:08 AM, Michael Bach  wrote:
> Hi Adrian,
>
> thanks for the hint.  The problem was that it showed me help for matrix
> when I did ?as.matrix.  I thought it was some kind of convention that
> data type conversion functions start with "as.", so now I will take more
> care in the future.
>
> With matrix() it works as expected, thanks again.
>
> Michael
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] adding a name to cross tab margins

2011-04-15 Thread andrija djurovic
Sorry, I've just reversed the names of dimensions :)

addmargins(table(fS,fF),c(1,2),FUN=list(total.col=sum,total.row=sum))

Andrija




On Fri, Apr 15, 2011 at 3:50 PM, andrija djurovic wrote:

> Hi.
>
> Have a look also at ?addmargins.
>
> addmargins(table(fS,fF),c(1,2),FUN=list(total.row=sum,total.col=sum))
>
> Andrija
>  On Fri, Apr 15, 2011 at 3:29 PM, Dmitry Berman wrote:
>
>> Listers,
>>
>> I have created a cross-tab matrix using the following code:
>>
>> S <-
>>
>> c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,1,2,3,1,1,2,3,1,2,2)
>> F <-
>>
>> c(1,2,3,1,2,3,1,1,1,1,2,3,1,1,3,2,2,2,1,2,3,1,1,1,1,2,3,3,1,3,1,3,1,1,2,3,1,1,3,2,3,2,1,1,1,2,3,1,1,2)
>> table(S,F)
>> fF <-factor(F, labels = c("Dem","Ind","Rep"))
>> fS <-factor(S, labels = c("Dem","Ind","Rep"))
>> PiD <- table(fS,fF)
>> PiD <- cbind(PiD, margin.table(PiD,1))
>> PiD <- rbind(PiD, margin.table(PiD,2))
>>
>> Now I would like to add the Column Name and Row Name "Total" to the last
>> row
>> and last column (where the marginal totals now hang out). When I use the
>> command
>>
>> colnames(PiD[,4]) <- c("total") I get the error:
>>
>> Error in `colnames<-`(`*tmp*`, value = "WTF") :
>>  attempt to set colnames on object with less than two dimensions
>>
>>
>> Since I am still new to R, I can't really understand the error... Can
>> someone tell me what I am doing wrong here?
>>
>> Thanks
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[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 R 2.13.0 Task Views (on Mac)

2011-04-15 Thread Uwe Ligges



On 14.04.2011 18:14, rbali wrote:

Same problem with Vista


1. Please quote the original message, mailing list readers are not able 
to follow otherwise!
2. Peter Dalgaard wrote that it is a bug in the ctv package, so 
everything is said already. And rather than posting here, why not ask 
the ctv package maintainer for a fix (which has been done already and 
hence no need to do it *now*).


Uwe Ligges






--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-R-2-13-0-Task-Views-on-Mac-tp3449189p3450073.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] frailtypack

2011-04-15 Thread Uwe Ligges



On 14.04.2011 18:04, Paul78 wrote:

I have got the same problem. Can anybody help me why R just shuts down?


1. please quote the original message, mailing list readers do not see it 
and it is hard to access it.
2. please specify a reproducible example as the posting guide quoted 
below suggests.
3. since it seems to be a package related bug, please ask the package 
maintainer and report with a reproducible example.


Uwe Ligges



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

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


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


Re: [R] adding a name to cross tab margins

2011-04-15 Thread andrija djurovic
Hi.

Have a look also at ?addmargins.

addmargins(table(fS,fF),c(1,2),FUN=list(total.row=sum,total.col=sum))

Andrija
On Fri, Apr 15, 2011 at 3:29 PM, Dmitry Berman  wrote:

> Listers,
>
> I have created a cross-tab matrix using the following code:
>
> S <-
>
> c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,1,2,3,1,1,2,3,1,2,2)
> F <-
>
> c(1,2,3,1,2,3,1,1,1,1,2,3,1,1,3,2,2,2,1,2,3,1,1,1,1,2,3,3,1,3,1,3,1,1,2,3,1,1,3,2,3,2,1,1,1,2,3,1,1,2)
> table(S,F)
> fF <-factor(F, labels = c("Dem","Ind","Rep"))
> fS <-factor(S, labels = c("Dem","Ind","Rep"))
> PiD <- table(fS,fF)
> PiD <- cbind(PiD, margin.table(PiD,1))
> PiD <- rbind(PiD, margin.table(PiD,2))
>
> Now I would like to add the Column Name and Row Name "Total" to the last
> row
> and last column (where the marginal totals now hang out). When I use the
> command
>
> colnames(PiD[,4]) <- c("total") I get the error:
>
> Error in `colnames<-`(`*tmp*`, value = "WTF") :
>  attempt to set colnames on object with less than two dimensions
>
>
> Since I am still new to R, I can't really understand the error... Can
> someone tell me what I am doing wrong here?
>
> Thanks
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] Conveting SAS Proc mixed to R code

2011-04-15 Thread Ben Bolker
Kevin Wright  gmail.com> writes:

> 
> > I am trying to teach myself R and replicate some previous SAS analysis.
> > Could someone please help me translate the following SAS code into R.
> >
> > Proc mixed method=ml
> > Class Group Treatment Stream Time Year;
> > Model Logrpk=Treatment Time Treatment*Time;
> > Random Group Stream (Group Treatment) Year(Time);
> >
> 
> Assuming you have a data frame "dat" with these factors: Group Treatment
> Stream Time Year
> And continuous response: logrpk
> 
> This code is a starting point: (I'm not sure exactly what the SAS syntax
> means).
> 
> require(lme4)
> m1 = lmer(logrpk ~ treatment*time + (1|Group) + (1|Stream:Group:Treatment) +
> (1|Year:Time), data=dat)
> 

  Can I please suggest that (Treatment|Stream:Group) or something 
like it is more appropriate than (1|Stream:Group:Treatment)?  In
general, what goes on the LEFT of the bar is an intercept or fixed
effect (i.e. something that varies between groups); what goes on
the RIGHT of the bar is a grouping variable.  Thus if a fixed effect
terms ends up on the right of the bar, something funny is going on.

  Ben Bolker

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


Re: [R] str() on a data frame with 600 variables

2011-04-15 Thread zubin
perfect! thx

On 4/15/2011 8:43 AM, Duncan Murdoch wrote:
> On 15/04/2011 8:19 AM, zubin wrote:
>> Hello..
>>
>> How do I get str() to show all variables in a data frame? It seems to be
>> "list output truncated" at about 99 variables, the data frame has over
>> 600 but i can't seem to figure out how to show all variables, we see
>> list.len() but again can't seem to figure this out - help will be
>> appreciated.
>>
>> R>  str(raw)
>>
>> 'data.frame': 1201 obs. of  626 variables:
>>
>> .
>>
>> .
>>
>> $ varXYZ: int  0 0 0 0 0 0 0 0 0 0 ...
>>
>>[list output truncated]
>>
> Use str(raw, list.len=1000).
>
> 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] extract cells by columns/rows from matrix

2011-04-15 Thread Jannis

which(data==max(data),arr.ind=TRUE)

gives you the indices of the largest element.

which(data==data[order(data)[2]],arr.ind=TRUE)

the indices of the second largest.

Best
Jannis

On 04/14/2011 10:23 PM, Nicolas Gutierrez wrote:

hi All,

I have a matrix Ufi (x by y)

  1  2  3  4  5
1 0  0  0  0  3
2 0  0  0  9  0
3 0  2  0  0  3
4 0  0  1  0  0
5 0  1  0  0  0

And I need the x and y "coordinates" of those cells with maximum values:

First:

x=4; y=2  (Value=9)

Second:

x=5; y=3  (value=3)

Any help?
THANKS!

Nic

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] adding a name to cross tab margins

2011-04-15 Thread Sarah Goslee
Hi Dmitry,

Nothing is seriously wrong.

You want to set the fourth column name, so take column names THEN
the fourth element:

colnames(PiD)[4] <- "total"

Thank you for providing a clear and simple reproducible example.

Sarah

On Fri, Apr 15, 2011 at 9:29 AM, Dmitry Berman  wrote:
> Listers,
>
> I have created a cross-tab matrix using the following code:
>
> S <-
> c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,1,2,3,1,1,2,3,1,2,2)
> F <-
> c(1,2,3,1,2,3,1,1,1,1,2,3,1,1,3,2,2,2,1,2,3,1,1,1,1,2,3,3,1,3,1,3,1,1,2,3,1,1,3,2,3,2,1,1,1,2,3,1,1,2)
> table(S,F)
> fF <-factor(F, labels = c("Dem","Ind","Rep"))
> fS <-factor(S, labels = c("Dem","Ind","Rep"))
> PiD <- table(fS,fF)
> PiD <- cbind(PiD, margin.table(PiD,1))
> PiD <- rbind(PiD, margin.table(PiD,2))
>
> Now I would like to add the Column Name and Row Name "Total" to the last row
> and last column (where the marginal totals now hang out). When I use the
> command
>
> colnames(PiD[,4]) <- c("total") I get the error:
>
> Error in `colnames<-`(`*tmp*`, value = "WTF") :
>  attempt to set colnames on object with less than two dimensions
>
>
> Since I am still new to R, I can't really understand the error... Can
> someone tell me what I am doing wrong here?
>


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

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


[R] adding a name to cross tab margins

2011-04-15 Thread Dmitry Berman
Listers,

I have created a cross-tab matrix using the following code:

S <-
c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,1,2,3,1,1,2,3,1,2,2)
F <-
c(1,2,3,1,2,3,1,1,1,1,2,3,1,1,3,2,2,2,1,2,3,1,1,1,1,2,3,3,1,3,1,3,1,1,2,3,1,1,3,2,3,2,1,1,1,2,3,1,1,2)
table(S,F)
fF <-factor(F, labels = c("Dem","Ind","Rep"))
fS <-factor(S, labels = c("Dem","Ind","Rep"))
PiD <- table(fS,fF)
PiD <- cbind(PiD, margin.table(PiD,1))
PiD <- rbind(PiD, margin.table(PiD,2))

Now I would like to add the Column Name and Row Name "Total" to the last row
and last column (where the marginal totals now hang out). When I use the
command

colnames(PiD[,4]) <- c("total") I get the error:

Error in `colnames<-`(`*tmp*`, value = "WTF") :
  attempt to set colnames on object with less than two dimensions


Since I am still new to R, I can't really understand the error... Can
someone tell me what I am doing wrong here?

Thanks

[[alternative HTML version deleted]]

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


[R] Can't use attributes from gml file in Cytoscape

2011-04-15 Thread Sandeep Amberkar
Hello,

I am exporting a graph in "gml" format from igraph 0.5.5. When I open the
file in Cytoscape v.2.7 I can't map the color attribute that I assign to the
graph when I export it from igraph. Could anyone help me in this?
Thanks.


--
Warm Regards,
Sandeep Amberkar
BioQuant,BQ26,
Im Neuenheimer Feld 267,
D-69120,Heidelberg
Tel: +49-6221-5451354

[[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] [Rcpp-devel] Find number of elements less than some number: Elegant/fastsolution needed

2011-04-15 Thread Douglas Bates
On Thu, Apr 14, 2011 at 11:47 PM, Christian Gunning  wrote:
> On Thu, Apr 14, 2011 at 7:02 PM,
>  wrote:
>
>> I was able to write a very short C++ function using the Rcpp package
>> that provided about a 1000-fold increase in speed relative to the best
>> I could do in R.  I don't have the script on this computer so I will
>> post it tomorrow when I am back on the computer at the office.
>>
>> Apologies for cross-posting to the Rcpp-devel list but I am doing so
>> because this might make a good example of the usefulness of Rcpp and
>> inline.
>
> And RcppArmadillo, as the case may be.
>
> This is a cool little problem.  In the examples given, I'd caution
> people against comparing apples and durian.  The sort(x) is a cost
> that should be considered *within* each implementation. I used
> Armadillo to sort (src, f4), and get another 100% worth of speedup
> that I can't reproducing using R's sort (src1, f1-f3).  If i modify
> SEXP in-place (and this always confuses me, so I tend to avoid it),
> I'm seeing an additional ~5-10% speed gain (src2, f5) -- the advantage
> of this last seems to be primarily in memory-constrained applications.
>
> On to the code!
>
> src = '
> NumericVector xx_(clone(x)), yy_(clone(y));
> int nxx = xx_.size();
> int nyy = yy_.size();
> arma::vec xx(xx_), yy(yy_);
> yy = sort(yy);
> xx = sort(xx);
> //
> //
> int j = 0; //gt index for yy
> for (int i=0; i < nxx; i++) {
>    while ((j < nyy) && ( xx(i) > yy(j) ) ) {
>        j++;
>    }
>    xx_(i) = j;
>   }
> return (xx_);
> '
>
> src1 = '
> NumericVector xx_(clone(x)), yy_(clone(y));
> // assumes x & y are already sorted
> arma::vec xx(xx_), yy(yy_);
> int nxx = xx.n_elem;
> int nyy = yy.n_elem;
> int j = 0; //gt index for yy
> for (int i=0; i < nxx; i++) {
>    while ((j < nyy) && ( xx(i) > yy(j) ) ) {
>        j++;
>    }
>    xx_(i) = j;
>  }
> return (xx_);
> '
>
> src2 = '
> NumericVector xx_(x), yy_(y);  //kinda scary
> int nxx = xx_.size();
> int nyy = yy_.size();
> arma::vec xx(xx_.begin(), nxx, false), yy(yy_.begin(), nyy, false);
> //really kinda scary
> yy = sort(yy);
> xx = sort(xx);
> //
> //
> int j = 0; //gt index for yy
> for (int i=0; i < nxx; i++) {
>    while ((j < nyy) && ( xx(i) > yy(j) ) ) {
>        j++;
>    }
>    xx_(i) = j;
> }
> return (xx_);
> '
>
> require(inline)
> require(RcppArmadillo)
> f1 <- function(x, y) { sort(length(y) - findInterval(-x, rev(-sort(y;}
> f2 <- function(x, y) {x = sort(x); length(y) - findInterval(-x, 
> rev(-sort(y)))}
> f3.a <- cxxfunction(signature(x="numeric", y="numeric"), src1,
> plugin='RcppArmadillo')
> f3 <- function(x,y) {
>        x <- sort(x)
>        y <- sort(y)
>        return(f3.a(x,y))
> }
> f4 <- cxxfunction(signature(x="numeric", y="numeric"), src,
> plugin='RcppArmadillo')
> ##  danger -- violates R semantics
> f5 <- cxxfunction(signature(x="numeric", y="numeric"), src2,
> plugin='RcppArmadillo')
>
>
> ## this is a really ugly test. ygwypf, i suppose :)
>
> for (i in 1:5) {
>  x1 <- x <- rnorm(5e6)
>  y1 <- y <- rnorm(5e6)
>  print( cbind(
>    r1=system.time(r1 <- f1(x,y)),
>    r2=system.time(r2 <- f2(x,y)), r3=system.time(r3 <- f3(x1,y1)),
>    r4 = system.time(r4 <- f4(x,y)), r5 = system.time(r5 <- f5(x,y))
>  ))
> }
> print(all.equal(r1, r2))
> print(all.equal(r1, r3))
> print(all.equal(r1, r4))
> print(all.equal(r1, r5))

I agree that the cost of sorting should be taken into account but I
don't think you need to go to the RcppArmadillo package to get a sort
function.  Why not use std::sort?

Also, I did sequential comparisons as shown in your code but after
reading Bill Dunlap's response and looking at the documentation for
the findInterval  function in R I smacked myself on the forehead and
thought "Duh - binary search, of course".

I haven't looked at the C code underlying the findInterval function
yet so I don't know if Martin has clever tricks for sorted x and y.
However the documentation for the std::upper_bound template at
cplusplus.com shows how to use that for the case here.  The best I can
think of for sorted x and y is to pass the upper bound from x[i] as
the first argument in the call to std::upper_bound for x[i+1].

Unfortunately I am staring at a series of deadlines today so
implementations and comparisons may need to wait until tomorrow.

P.S. to Christian:  Check the archives for several of Dirk's posts to
the rcpp-devel list where he has used the rbenchmark package to
produce clean output from comparisons of  implementations of
algorithms.

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

2011-04-15 Thread Ben Bolker
On 04/15/2011 01:13 AM, Jurgens de Bruin wrote:
> Thanks for the reply...
> 
> with reproducible I am believe you require a dataset?

  yes -- but you can make one up if you like.  e.g.


dd <- expand.grid(drugclass=LETTERS[1:5],
   plant=c("cactus","sequoia","mistletoe"))
set.seed(101)
dd$fitvalue <- runif(nrow(dd))

library(ggplot2)
ggplot(dd,aes(x=drugclass,y=plant,colour=fitvalue,size=fitvalue))+
  geom_point()

  By the way, I think you could represent your data much more
clearly this way: the "Cleveland hierarchy" says that it's easier
to assess quantitative values plotted along a common scale than via
size or colour ...

ggplot(dd,aes(x=drugclass,y=fitvalue,colour=plant))+
  geom_point()+geom_line(aes(group=plant))



> The size of the bubbles will be related to the fitvalues.
> 
> 
> 
> On 14 April 2011 17:57, Ben Bolker  > wrote:
> 
> Jurgens de Bruin  gmail.com > writes:
> 
> >
> > Hi,
> >
> > I do not have much R experience just the basics, so please excuse
> > any obvious questions.
> >
> > I would like to create bubble plot that have Categorical data on
> the x and y
> > axis and then the diameter if the bubble the value related to x and y.
> >  Attached to the email is a pic of what I would like to do.
> >
> 
>  A reproducible example would be great.
> 
> something along the lines of
> 
> library(ggplot2)
> 
> ggplot(mydata,aes(x=drugclass,y=plant,colour=fitvalue,size=?))+geom_point()
> 
>  it's not clear from your description what determines the size.
>  From a labeling point of view, switching x and y might be useful.
> 
> __
> R-help@r-project.org  mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 
> 
> 
> -- 
> Regards/Groete/Mit freundlichen Grüßen/recuerdos/meilleures salutations/
> distinti saluti/siong/duì yú/привет
> 
> Jurgens de Bruin

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


Re: [R] Statistical Tables Really Fast

2011-04-15 Thread Michael Friendly

On 4/14/2011 7:22 PM, Dirk Eddelbuettel wrote:


Sorry, but this is the r-help list.  The 'R Spam' list is over at /dev/null.



Clearly a fortune candidate!


--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

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


Re: [R] str() on a data frame with 600 variables

2011-04-15 Thread Duncan Murdoch

On 15/04/2011 8:19 AM, zubin wrote:

Hello..

How do I get str() to show all variables in a data frame? It seems to be
"list output truncated" at about 99 variables, the data frame has over
600 but i can't seem to figure out how to show all variables, we see
list.len() but again can't seem to figure this out - help will be
appreciated.

R>  str(raw)

'data.frame': 1201 obs. of  626 variables:

.

.

$ varXYZ: int  0 0 0 0 0 0 0 0 0 0 ...

   [list output truncated]


Use str(raw, list.len=1000).

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] str() on a data frame with 600 variables

2011-04-15 Thread Marc Schwartz
On Apr 15, 2011, at 7:19 AM, zubin wrote:

> Hello..
> 
> How do I get str() to show all variables in a data frame? It seems to be
> "list output truncated" at about 99 variables, the data frame has over
> 600 but i can't seem to figure out how to show all variables, we see
> list.len() but again can't seem to figure this out - help will be
> appreciated. 
> 
> R> str(raw)
> 
> 'data.frame': 1201 obs. of  626 variables:
> 
> .
> 
> .
> 
> $ varXYZ: int  0 0 0 0 0 0 0 0 0 0 ...
> 
>  [list output truncated]

Try:

  str(raw, list.len = 999)



DF <- as.data.frame(matrix(1:1000, 50, 200))

> str(DF)
'data.frame':   50 obs. of  200 variables:
 $ V1  : int  1 2 3 4 5 6 7 8 9 10 ...
 $ V2  : int  51 52 53 54 55 56 57 58 59 60 ...
 $ V3  : int  101 102 103 104 105 106 107 108 109 110 ...
 $ V4  : int  151 152 153 154 155 156 157 158 159 160 ...
 $ V5  : int  201 202 203 204 205 206 207 208 209 210 ...
...
 $ V95 : int  701 702 703 704 705 706 707 708 709 710 ...
 $ V96 : int  751 752 753 754 755 756 757 758 759 760 ...
 $ V97 : int  801 802 803 804 805 806 807 808 809 810 ...
 $ V98 : int  851 852 853 854 855 856 857 858 859 860 ...
 $ V99 : int  901 902 903 904 905 906 907 908 909 910 ...
  [list output truncated]



> str(DF, list.len = 999)
'data.frame':   50 obs. of  200 variables:
 $ V1  : int  1 2 3 4 5 6 7 8 9 10 ...
 $ V2  : int  51 52 53 54 55 56 57 58 59 60 ...
 $ V3  : int  101 102 103 104 105 106 107 108 109 110 ...
 $ V4  : int  151 152 153 154 155 156 157 158 159 160 ...
 $ V5  : int  201 202 203 204 205 206 207 208 209 210 ...
...
 $ V195: int  701 702 703 704 705 706 707 708 709 710 ...
 $ V196: int  751 752 753 754 755 756 757 758 759 760 ...
 $ V197: int  801 802 803 804 805 806 807 808 809 810 ...
 $ V198: int  851 852 853 854 855 856 857 858 859 860 ...
 $ V199: int  901 902 903 904 905 906 907 908 909 910 ...
 $ V200: int  951 952 953 954 955 956 957 958 959 960 ...



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] Sweave Executes Package Functions Twice

2011-04-15 Thread Duncan Murdoch

On 15/04/2011 7:00 AM, Dario Strbenac wrote:

Hi,

I've got something strange going on. I'm trying to compile a vignette using 
Sweave("vignette.Rnw"), and in the first code chunk that illustrates an 
example, I noticed from the output text I have inside the function, that it is running it 
twice, because the sequence of message() statements is output on screen twice, and takes 
twice as long to do.

e.g.
Processing sample 1
Processing sample 2
Processing sample 3
Processing sample 1
Processing sample 2
Processing sample 3

If I open up a new R session, and copy and paste the lines of code from the 
.Rnw one by one, the function isn't called twice - only one complete set of 
progress outputs show.


This is standard behaviour for a chunk that is drawing figures.  The 
solution is to *only* draw the figure in such a chunk, do all your 
computation in other chunks.


In version 2.14.0 in the fall, this will no longer be the default 
behaviour.  Perhaps it will be possible to suppress the multiple runs 
before then, but I think it is unlikely that the default will change.


Duncan Murdoch


I tried using debug() to get more of an idea of what was happening. The function is called enrichmentPlot, so I 
did debug(enrichmentPlot), then Sweave("vignette.Rnw"). Execution pauses when it gets to the right 
code chunk, then I type in "n" at the Browse[2]>  prompt, but I don't get any output from debug, 
like "debugging in:", but it runs for a while and I get all of the messages from within my function, 
then execution pauses again. But just before it pauses I get the debug output :

debugging in: enrichmentPlot(samples.list, 300)
debug: standardGeneric("enrichmentPlot")
Browse[2]>

Then I enter "n", and it runs the same code all over again.

...   ... # Same progress outputs from inside my function.
exiting from: enrichmentPlot(samples.list, 300)

I have the current 2.13.0 version of R. I'm sure I've done something wrong, I 
just can't figure out what. Thanks for any help.

--
Dario Strbenac
Research Assistant
Cancer Epigenetics
Garvan Institute of Medical Research
Darlinghurst NSW 2010
Australia

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] GLM output for deviance and loglikelihood

2011-04-15 Thread Jeffrey Pollock
It has always been my understanding that deviance for GLMs is defined
by;

 

D =  -2(loglikelihood(model) - loglikelihood(saturated model))

 

and this can be calculated by (or at least usually is);

 

D = -2(loglikelihood(model))

 

As is done so in the code for 'polr' by Brian Ripley (in the package
'MASS') where the -loglikehood is minimised using optim;

 

res <- optim(s0, fmin, gmin, method = "BFGS", hessian = Hess, ...)

.

.

.

deviance <- 2 * res$value

 

If so, why is it that;

 

> x = rnorm(10)

> y = rpois(10,lam=exp(1 + 2*x))

> test = glm(formula = y ~ x, family = poisson)

> deviance(test)

[1] 5.483484

> -2*logLik(test)

[1] 36.86335

 

I'm clearly not understanding something here, can anyone shed any light?
Why is;

 

-2*logLik(test) =/= deviance(test) ???

 

I think this is something that is poorly understood all over the
internet (at least from my google searches anyway!)

 

Thanks,

 

Jeff

 

- 
** Confidentiality: The contents of 
this e-mail and any attachments transmitted with it are intended to be 
confidential to the intended recipient; and may be privileged or otherwise 
protected from disclosure. If you are not an intended recipient of this e-mail, 
do not duplicate or redistribute it by any means. Please delete it and any 
attachments and notify the sender that you have received it in error. This 
e-mail is sent by a William Hill PLC group company. The William Hill group 
companies include, among others, William Hill PLC (registered number 4212563), 
William Hill Organization Limited (registered number 278208), William Hill 
Credit Limited (registered number 413846), WHG (International) Limited 
(registered number 99191) and WHG Trading Limited (registered number 101439). 
Each of William Hill PLC, William Hill Organization Limited and William Hill 
Credit Limited is registered in Engl!
 and and Wales and has its registered office at Greenside House, 50 Station 
Road, Wood Green, London N22 7TP. Each of WHG (International) Limited and WHG 
Trading Limited is registered in Gibraltar and has its registered office at 6/1 
Waterport Place, Gibraltar. Unless specifically indicated otherwise, the 
contents of this e-mail are subject to contract; and are not an official 
statement, and do not necessarily represent the views, of William Hill PLC, its 
subsidiaries or affiliated companies. Please note that neither William Hill 
PLC, nor its subsidiaries and affiliated companies can accept any 
responsibility for any viruses contained within this e-mail and it is your 
responsibility to scan any emails and their attachments. William Hill PLC, its 
subsidiaries and affiliated companies may monitor e-mail traffic data and also 
the content of e-mails for effective operation of the e-mail system, or for 
security, purposes. *

[[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] Sweave Executes Package Functions Twice

2011-04-15 Thread Dario Strbenac
Hi,

I've got something strange going on. I'm trying to compile a vignette using 
Sweave("vignette.Rnw"), and in the first code chunk that illustrates an 
example, I noticed from the output text I have inside the function, that it is 
running it twice, because the sequence of message() statements is output on 
screen twice, and takes twice as long to do.

e.g. 
Processing sample 1
Processing sample 2
Processing sample 3
Processing sample 1
Processing sample 2
Processing sample 3

If I open up a new R session, and copy and paste the lines of code from the 
.Rnw one by one, the function isn't called twice - only one complete set of 
progress outputs show.

I tried using debug() to get more of an idea of what was happening. The 
function is called enrichmentPlot, so I did debug(enrichmentPlot), then 
Sweave("vignette.Rnw"). Execution pauses when it gets to the right code chunk, 
then I type in "n" at the Browse[2]> prompt, but I don't get any output from 
debug, like "debugging in:", but it runs for a while and I get all of the 
messages from within my function, then execution pauses again. But just before 
it pauses I get the debug output :

debugging in: enrichmentPlot(samples.list, 300)
debug: standardGeneric("enrichmentPlot")
Browse[2]>

Then I enter "n", and it runs the same code all over again.

...   ... # Same progress outputs from inside my function.
exiting from: enrichmentPlot(samples.list, 300)

I have the current 2.13.0 version of R. I'm sure I've done something wrong, I 
just can't figure out what. Thanks for any help.

--
Dario Strbenac
Research Assistant
Cancer Epigenetics
Garvan Institute of Medical Research
Darlinghurst NSW 2010
Australia

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] str() on a data frame with 600 variables

2011-04-15 Thread zubin
Hello..

How do I get str() to show all variables in a data frame? It seems to be
"list output truncated" at about 99 variables, the data frame has over
600 but i can't seem to figure out how to show all variables, we see
list.len() but again can't seem to figure this out - help will be
appreciated. 

R> str(raw)

'data.frame': 1201 obs. of  626 variables:

.

.

$ varXYZ: int  0 0 0 0 0 0 0 0 0 0 ...

  [list output truncated]



[[alternative HTML version deleted]]

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


Re: [R] How to generate a correlation matrix with restrictions on its eigenvalues

2011-04-15 Thread Ravi Varadhan
Generate random numbers from a multinomial.

?rmultinom
# The following will generate n multinomial vectors each of size m
rmultinom(n, size=m, prob=m^(-1/8))  # you need to specify probabilities 
appropriately

Ravi.

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
Chee Chen [chee.c...@yahoo.com]
Sent: Thursday, April 14, 2011 11:55 PM
To: r-help@r-project.org
Subject: [R] How to generate a correlation matrix with restrictions on its  
eigenvalues

Dear All,
I would like to generate m positive real numbers c_i, I=1,...,m, such that
(1) c_1 + c_2 + ... + c_m=m,
(1) after being ordered  into c_1 >= c_2 >=  >=c_m>0,  we have that c_m is 
of the same order of m^(-1/8), when m is sufficiently large.
Thanks,
-Chee



[[alternative HTML version deleted]]

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


Re: [R] predict

2011-04-15 Thread Paul Hiemstra
On 04/14/2011 10:49 PM, Serdar Akin wrote:
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


-- 
Paul Hiemstra, MSc
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

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

2011-04-15 Thread Felix Andrews
Hi,

Could you not simplify your a and b plots into one like

xyplot(NDVI_P10 + AVG_NDVI_P10 ~ dek_num | Year,
data=data, lty = 3:2, col = c("darkgrey", "black"), ..., [etc]
auto.key = list(lines = TRUE, points = FALSE))

Otherwise please provide a commented, minimal, self-contained,
reproducible example.

Regards
Felix


On 15 April 2011 18:25, Francesco Nutini  wrote:
>
>
>
>
>
>
>
>
>
> Sorry, my previous mail was incomplete.
>
> I mean, one of my xyplot is build with the command "doubleYScale" (in order 
> to overlap two line with different Y-axis).
> But  "doubleYScale"  doesn't run with the nice command that you have 
> suggested:
>
> first plot:
>
>
>
>
> a<-xyplot(NDVI_P10~dek_num
> | Year, type="a", data=data, xlim=c(1,37),  ylim=c(0.1,0.8), as.table = TRUE, 
> layout =
> c(13,1), aspect = 2, col="darkgrey",
> col.axis="black", lwd=3, grid=T, par.settings =
> list(strip.background = list(col = c("gray90"
> second plot:
>
>
>  b<-xyplot(AVG_NDVI_P10~dek_num | Year,
> type="a", data=data, xlim=c(1,37),
> ylim=c(0.1,0.8), as.table = TRUE, layout = c(13,1), aspect = 2,  col="black",
> col.axis="black", lwd=2)
> overlap first and second:
>
>
> double<- update(doubleYScale(a,
> b, add.ylab2 = TRUE), par.settings = simpleTheme(col =
> c("black","black")))
> third plot:
>
>
> z<- xyplot(z_NDVI_P10
> ~dek_num | Year, type="h", data=data, xlim=c(1,37),  ylim=c(-2.5,2.5), 
> as.table = TRUE, layout =
> c(13,1), aspect = 2, col="black",
> col.axis="black", lwd=3, grid=T, par.settings =
> list(strip.background = list(col = c("gray90"
> enclose (?c.trellis):
>
>
>
>
> c( z,double, x.same = TRUE, y.same = T, layout = c(13,2))
>
> Maybe there is no solution but, anyway, thanks for help!
> francesco
>
>
>
>
>
>
>
>
> From: nutini.france...@gmail.com
> To: baptiste.aug...@googlemail.com
> CC: r-help@r-project.org
> Subject: RE: [R]  how to enclose two xyplot
> Date: Thu, 14 Apr 2011 15:31:12 +
>
>
>
>
>
>
>
>
> ok ?c.trellis works well.
> But I still have a problem.
>
> One of my plot is a combination of two xyplot on different scales:
>
>
>
> a<-xyplot(NDVI_P10~dek_num
> | Year, type="a", data=data, xlim=c(1,37),  ylim=c(0.1,0.8), as.table = TRUE, 
> layout =
> c(13,1), aspect = 2, col="darkgrey",
> col.axis="black", lwd=3, grid=T, par.settings =
> list(strip.background = list(col = c("gray90"
>
> b<-xyplot(AVG_NDVI_P10~dek_num | Year,
> type="a", data=data, xlim=c(1,37),
> ylim=c(0.1,0.8), as.table = TRUE, layout = c(13,1), aspect = 2,  col="black",
> col.axis="black", lwd=2)
>
> update(doubleYScale(a, b, add.ylab2 =
> TRUE), par.settings = simpleTheme(col =
> c("black","black")))
>
>
>
>
>
> From: nutini.france...@gmail.com
> To: baptiste.aug...@googlemail.com
> CC: r-help@r-project.org
> Subject: RE: [R] FW: [r] how to enclose two xyplot
> Date: Thu, 14 Apr 2011 07:46:31 +
>
>
>
>
>
>
>
>
> Did you mean this?
> http://rgm2.lab.nig.ac.jp/RGM2/func.php?rd_id=latticeExtra:c.trellis
>
> In fact I'm already using latticeExtra package because my xyplot is little 
> bit complicated...
> So, I'm tring, thanks fro tricks baptiste!
>
> Francesco
>
>
>> Date: Thu, 14 Apr 2011 08:52:45 +1200
>> Subject: Re: [R] FW: [r] how to enclose two xyplot
>> From: baptiste.aug...@googlemail.com
>> To: nutini.france...@gmail.com
>> CC: r-help@r-project.org
>>
>> Hi,
>>
>> Have you tried ?c.trellis in the latticeExtra package?
>>
>> HTH,
>>
>> baptiste
>>
>> On 13 April 2011 23:36, Francesco Nutini  wrote:
>> >
>> >  Dear R-users,
>> >
>> > I have to plot two xyplot, and I wish to enclose this two graphs with just 
>> > one headline, the same x scale, the same grid etc.
>> > These parameters should tie in, in order to obtain, visually, a unique 
>> > graph formed by two xyplot.
>> >
>> > I try to give an idea:
>> >
>> > xyplot1: |_|_|_|
>> >
>> >
>> >
>> > xyplot2: |_|_|_|
>> >
>> >
>> >
>> > what i want: |  |  | |
>> >
>> >                   |_|_|_|
>> >
>> >
>> > I tried to use the command "par", but it's doesn't work with xyplot. The 
>> > two plot have, by default, the same x-axis scale.
>> > I know it's just a "visual solution", but it could be nice for a paper!
>> >
>> > Thanks a lot,
>> >
>> > Francesco Nutini
>> > PhD student
>> >
>> >
>> >
>> >
>> >
>> >        [[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.
>



-- 
Felix Andrews / 安福立
http://www.neurofractal.org/felix/

_

Re: [R] as.matrix strangeness

2011-04-15 Thread Michael Bach
Hi Adrian,

thanks for the hint.  The problem was that it showed me help for matrix
when I did ?as.matrix.  I thought it was some kind of convention that
data type conversion functions start with "as.", so now I will take more
care in the future.

With matrix() it works as expected, thanks again.

Michael

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

2011-04-15 Thread Jim Lemon

On 04/14/2011 11:48 PM, Jurgens de Bruin wrote:

Hi,

I do not have much R experience just the basics, so please excuse
any obvious questions.

I would like to create bubble plot that have Categorical data on the x and y
axis and then the diameter if the bubble the value related to x and y.
  Attached to the email is a pic of what I would like to do.


Hi Jurgens,
Below is a little demo of what you can do. Your example has more in it 
than you have described, so if you want the third dimension (Fit) you 
will have to expand this to multiple circles at one point. I will 
probably redo this plot and add it to the plotrix package sometime.


bubbleGumPlot<-function(xdiam,xcol,xlabels,ylabels,redrange=c(0,1),
 greenrange=c(0,1),bluerange=c(0,1),extremes=NA,na.color=NA,
 main="",xlab="",ylab="",staxx=FALSE,staxy=FALSE,srt=NA,...) {

 bubblecol<-color.scale(xcol,redrange=redrange,greenrange=greenrange,
  bluerange=bluerange,extremes=extremes,na.color=NA)
 bubblediam<-rescale(xdiam,c(0.05,0.5))
 dimx<-dim(xcol)
 plot(NA,xlim=c(0.5,dimx[2]+0.5),ylim=c(0.5,dimx[1]+0.5),type="n",
  main=main,xlab=xlab,ylab=ylab,axes=FALSE,...)
 if(staxx) staxlab(1,at=1:dimx[2],labels=colnames(xcol),srt=srt)
 else axis(1,at=1:dimx[2],labels=colnames(xcol))
 if(staxy) staxlab(2,at=1:dimx[1],labels=rownames(xcol))
 else axis(2,at=1:dimx[1],labels=rownames(xcol))
 box()
 for(row in dimx[1]:1) {
  for(column in 1:dimx[2])
   draw.circle(column,row,radius=bubblediam[dimx[1]-row+1,column],
col=bubblecol[dimx[1]-row+1,column])
 }
}
colmat<-matrix(runif(48),nrow=6,ncol=8)
diammat<-matrix(runif(48),nrow=6,ncol=8)
rownames(colmat)<-c("Apple","Blackberry","Blueberry","Cherry","Peach","Pear")
colnames(colmat)<-c("Sweet","Sour","Salty","Bitter","Pleasant","Bland","Smooth",
 "Pungent")
bubbleGumPlot(diammat,colmat,staxx=TRUE,staxy=TRUE,
 main="Test of bubbleGumPlot",xlab="Characteristics",ylab="Fruits")

Jim

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


Re: [R] Plotting an Underbrace in R

2011-04-15 Thread Michael McAssey
Baptiste,

Thank you.  The examples in the documentation for tikz helped me solve
this problem, and give me a good tool for future plots.  I only need
to figure out how to incorporate LaTeX packages like amssymb so that I
can use \mathbb{} to put the real numbers symbol in my plot.

Regards,

Michael

On Fri, Apr 15, 2011 at 10:48 AM, baptiste auguie
 wrote:
> Hi,
>
> Through pgfSweave you can use the tikz device, which is the one that
> can interpret Latex code (package tikzDevice). I would start with a
> minimal self-contained plot with this function. see ?tikz for
> examples.
>
> HTH,
>
> baptiste
>
>
>
>
> On 15 April 2011 20:03, Michael McAssey  wrote:
>> Ben,
>>
>> This example of pgfSweave looks like it would address my problem.  I
>> installed this package, but I cannot determine how to use it to make R
>> convert LaTeX commands into mathematical symbols on an R plot.  The
>> documentation does not seem to address this.  I tried to mimic the
>> example from Yihui Xie that you provided but R only puts the LaTeX
>> code on my plot without converting it.  That is, if in the R GUI I
>> have:
>>
>>> library(pgfSweave)
>>> plot(1:10, 1:10, "$Y=\\beta_0 + \\beta_1 x + \\epsilon$")
>>
>> then in the plot the y-axis label is $Y=\beta_0 + \beta_1 x +
>> \epsilon$ rather than what I want.  I can't find any useful help on
>> Google.  Any further suggestions?
>>
>> Thanks.
>>
>> Michael
>>
>>
>> On Thu, Apr 14, 2011 at 11:22 PM, Ben Bolker  wrote:
>>>
>>> Michael McAssey  gmail.com> writes:
>>>
>>> >
>>> > I need to include some mathematical expressions in a plot I am creating in
>>> > R, one of which requires an underbrace, which in LaTeX would be written 
>>> > like
>>> >
>>> > \underbrace{T \cdots T}_{n times}
>>> >
>>> > There does not appear to be a provision for this in plotmath, and I cannot
>>> > find anything on the topic in the R-help archive or in a Google search.  I
>>> > would appreciate some help with this.
>>>
>>>  Does
>>>
>>> 
>>>
>>>  help at all?
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>> --
>> Michael P. McAssey, Ph.D.
>> Statistics for Life Sciences, Department of Mathematics
>> Faculty of Sciences, Vrije Universiteit Amsterdam
>> De Boelelaan 1081a, 1081 HV Amsterdam, The Netherlands
>> Office: S-230, W&N building
>> Tel: +31 (0)20 598 7724
>> Fax: +31 (0)20 598 7653
>> Mobile: +31 (0)62 113 8600
>> http://www.few.vu.nl/~mmy700/
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>



-- 
Michael P. McAssey, Ph.D.
Statistics for Life Sciences, Department of Mathematics
Faculty of Sciences, Vrije Universiteit Amsterdam
De Boelelaan 1081a, 1081 HV Amsterdam, The Netherlands
Office: S-230, W&N building
Tel: +31 (0)20 598 7724
Fax: +31 (0)20 598 7653
Mobile: +31 (0)62 113 8600
http://www.few.vu.nl/~mmy700/

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

2011-04-15 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 15.04.2011 01:34:22:

> Hi everyone.
> 
> I am quite frustrated that this doesn't work, as all the functions 
within
> work fine by themselves. I'd also like any pointers to how to avoid 
'for'
> loops in my code. I understand it's less than desirable, but I'm still 
quite
> new and use them a lot.
> 
> I have a few wide datasets (90 to 120) with long column names, each name
> contains a number of different 'markers'. Each could be considered a 
factor
> variable within the column name. Their are two categories of factors, 
we'll
> call them f1 and f2.
> 
> The data frame names look something like this:
>  'ace_van' , 'boy_van', 'car_xes' , 'ace_xes', 'dog_wall' , 'car_zounds'
> 
> f1 <- c('ace', 'boy', 'car', 'dog')
> f2 <- c('van', 'wall', 'xes', 'zounds')# actual vectors are length 6 
and
> 7, so I don't want to individually sum the 42 combinations.
> 
> > var.table <- function(data, vec1, vec2)
> {
>   table <- as.data.frame(matrix(nrow = length(vec1), ncol = 
length(vec2)),
> row.names = vec1)
>   names(table) <- vec2
>   for (i in 1:length(vec1))
>   {
> for (j in 1:length(vec2))
> {
>   indices <- intersect(grep(vec1[j], names(data), value = TRUE),
> grep(cats[i], names(data), value = TRUE))
>   table[i,j] <- sum(data[ ,indices])
> }
>   }
> table
> }
> 
> > var.table(mydf, f1, f2)
> 
> Output:
> 
> Error in FUN(X[[1L]], ...) :
> only defined on a data frame with all numeric variables
> 
> 
> Every entry in mydf is an integer with no missing values.

I can not provide solution as I can not decipher what you want to do but 
here are few comments.

Do not use names of functions for naming objects e.g. table, it can be 
quite confusing.
What is cats??
Are you sure that mydf values are numbers?

What does str(mydf) say?

Do I understand that you want summarise all values in columns of data 
frame that have some common name?


lapply(f2, grep, names(mydf))

will give you list of indices of columns in mydf matching particular f2 
item. From this you can continue. Maybe plyr package can also be used.

Regards

Petr

> 
> Thanks a ton.
> 
> -Ben
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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

2011-04-15 Thread Francesco Nutini









Sorry, my previous mail was incomplete.

I mean, one of my xyplot is build with the command "doubleYScale" (in order to 
overlap two line with different Y-axis).
But  "doubleYScale"  doesn't run with the nice command that you have suggested:

first plot:




a<-xyplot(NDVI_P10~dek_num
| Year, type="a", data=data, xlim=c(1,37),  ylim=c(0.1,0.8), as.table = TRUE, 
layout =
c(13,1), aspect = 2, col="darkgrey", 
col.axis="black", lwd=3, grid=T, par.settings =
list(strip.background = list(col = c("gray90"
second plot:


 b<-xyplot(AVG_NDVI_P10~dek_num | Year,
type="a", data=data, xlim=c(1,37), 
ylim=c(0.1,0.8), as.table = TRUE, layout = c(13,1), aspect = 2,  col="black",
col.axis="black", lwd=2)
overlap first and second:


double<- update(doubleYScale(a,
b, add.ylab2 = TRUE), par.settings = simpleTheme(col =
c("black","black")))
third plot:


z<- xyplot(z_NDVI_P10
~dek_num | Year, type="h", data=data, xlim=c(1,37),  ylim=c(-2.5,2.5), as.table 
= TRUE, layout =
c(13,1), aspect = 2, col="black", 
col.axis="black", lwd=3, grid=T, par.settings =
list(strip.background = list(col = c("gray90"
enclose (?c.trellis):




c( z,double, x.same = TRUE, y.same = T, layout = c(13,2))

Maybe there is no solution but, anyway, thanks for help!
francesco








From: nutini.france...@gmail.com
To: baptiste.aug...@googlemail.com
CC: r-help@r-project.org
Subject: RE: [R]  how to enclose two xyplot
Date: Thu, 14 Apr 2011 15:31:12 +








ok ?c.trellis works well.
But I still have a problem. 

One of my plot is a combination of two xyplot on different scales:



a<-xyplot(NDVI_P10~dek_num
| Year, type="a", data=data, xlim=c(1,37),  ylim=c(0.1,0.8), as.table = TRUE, 
layout =
c(13,1), aspect = 2, col="darkgrey", 
col.axis="black", lwd=3, grid=T, par.settings =
list(strip.background = list(col = c("gray90"

b<-xyplot(AVG_NDVI_P10~dek_num | Year,
type="a", data=data, xlim=c(1,37), 
ylim=c(0.1,0.8), as.table = TRUE, layout = c(13,1), aspect = 2,  col="black",
col.axis="black", lwd=2)

update(doubleYScale(a, b, add.ylab2 =
TRUE), par.settings = simpleTheme(col =
c("black","black")))





From: nutini.france...@gmail.com
To: baptiste.aug...@googlemail.com
CC: r-help@r-project.org
Subject: RE: [R] FW: [r] how to enclose two xyplot
Date: Thu, 14 Apr 2011 07:46:31 +








Did you mean this?
http://rgm2.lab.nig.ac.jp/RGM2/func.php?rd_id=latticeExtra:c.trellis

In fact I'm already using latticeExtra package because my xyplot is little bit 
complicated...
So, I'm tring, thanks fro tricks baptiste!

Francesco


> Date: Thu, 14 Apr 2011 08:52:45 +1200
> Subject: Re: [R] FW: [r] how to enclose two xyplot
> From: baptiste.aug...@googlemail.com
> To: nutini.france...@gmail.com
> CC: r-help@r-project.org
> 
> Hi,
> 
> Have you tried ?c.trellis in the latticeExtra package?
> 
> HTH,
> 
> baptiste
> 
> On 13 April 2011 23:36, Francesco Nutini  wrote:
> >
> >  Dear R-users,
> >
> > I have to plot two xyplot, and I wish to enclose this two graphs with just 
> > one headline, the same x scale, the same grid etc.
> > These parameters should tie in, in order to obtain, visually, a unique 
> > graph formed by two xyplot.
> >
> > I try to give an idea:
> >
> > xyplot1: |_|_|_|
> >
> >
> >
> > xyplot2: |_|_|_|
> >
> >
> >
> > what i want: |  |  | |
> >
> >   |_|_|_|
> >
> >
> > I tried to use the command "par", but it's doesn't work with xyplot. The 
> > two plot have, by default, the same x-axis scale.
> > I know it's just a "visual solution", but it could be nice for a paper!
> >
> > Thanks a lot,
> >
> > Francesco Nutini
> > PhD student
> >
> >
> >
> >
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
  
[[alternative HTML version deleted]]

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


Re: [R] as.matrix strangeness

2011-04-15 Thread Adrian Duffner

Hallo Michael,

check ?matrix and compare to as.matrix.
as.matrix does not provide a ncol argument. To get a 2 by 2 matrix use

matrix(a, ncol=2)

Regards
Adrian

Am 15.04.2011 11:42, schrieb Michael Bach:

Dear R users,

I presume there is something foul with system:

a<- c(1,2,3,4)
as.matrix(a, ncol=2)

Output:

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

The vignette for as.matrix says nrow (ncol) will be deduced from length
and ncol (nrow).  It does not work even when I additionally specify
nrow=2.  It behaves as if I had not given the ncol argument.  Any hints
on what might be borked up here?

R.Version()$ver
[1] "R version 2.10.1 (2009-12-14)"

Thanks in advance,
Michael Bach

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

2011-04-15 Thread Brett Presnell

Liviu Andronic  writes:

> Not a solution that would work in all cases, have you tried reducing
> the font size?

Yes, I have done this.  I've also eliminated all the stuff that beamer
puts on the screen (title bars, navigation symbols, etc), to the point
that I probably shouldn't be using beamer at all (in fact I usually use
my own home grown latex macros for 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] as.matrix strangeness

2011-04-15 Thread Michael Bach
Dear R users,

I presume there is something foul with system:

a <- c(1,2,3,4)
as.matrix(a, ncol=2)

Output:

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

The vignette for as.matrix says nrow (ncol) will be deduced from length
and ncol (nrow).  It does not work even when I additionally specify
nrow=2.  It behaves as if I had not given the ncol argument.  Any hints
on what might be borked up here?

R.Version()$ver
[1] "R version 2.10.1 (2009-12-14)"

Thanks in advance,
Michael Bach

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


Re: [R] Automatically extract info from Granger causality output

2011-04-15 Thread Pfaff, Bernhard Dr.
Hello Ivan,

see example(causality) for the first question and use count[[i]] and not 
count$[[i]] for the second. The following works for me:

example(causality)
test1 <- causality(var.2c, "e")
test2 <- causality(var.2c, "prod")
tl <- list(test1, test2)
res <- matrix(NA, ncol = 1, nrow = length(tl))
for(i in 1:length(tl)){
res[i, ] <- tl[[i]]$Granger$p.value
}
res

hth,
Bernhard


> -Ursprüngliche Nachricht-
> Von: ivan [mailto:i.pet...@gmail.com] 
> Gesendet: Freitag, 15. April 2011 10:46
> An: Pfaff, Bernhard Dr.
> Cc: r-help@r-project.org
> Betreff: Re: [R] Automatically extract info from Granger 
> causality output
> 
> Dear Bernhard,
> 
> thank you very much for the response. Yes, I am using the 
> packsges "vars" with fuchrions VAR() and causality().
> 
> 1)Giving colnames to the objects does unfortunately not  
> change anything.
> 
> 2) I am not sure if I understood you right. Did you mean to 
> insert Countml$Granger$p.value rather than  
> Count$ml$Granger$p.value? This
> returns: Error: Object 'Countms' not found.
> 
> By the way, str(Count) produces the following:
> 
> > str(Count)
> List of 4
>  $ ml:List of 2
>   ..$ Granger:List of 5
>   .. ..$ statistic: num [1, 1] 0.277
>   .. .. ..- attr(*, "names")= chr "F-Test"
>   .. ..$ parameter: Named num [1:2] 1 122
>   .. .. ..- attr(*, "names")= chr [1:2] "df1" "df2"
>   .. ..$ p.value  : num [1, 1] 0.6
>   .. ..$ method   : chr "Granger causality H0: y1 do not 
> Granger-cause x"
>   .. ..$ data.name: chr "VAR object x"
>   .. ..- attr(*, "class")= chr "htest"
>   ..$ Instant:List of 5
>   .. ..$ statistic: num [1, 1] 19.7
>   .. .. ..- attr(*, "names")= chr "Chi-squared"
>   .. ..$ parameter: Named int 1
>   .. .. ..- attr(*, "names")= chr "df"
>   .. ..$ p.value  : num [1, 1] 8.86e-06
>   .. ..$ method   : chr "H0: No instantaneous causality 
> between: y1 and x"
>   .. ..$ data.name: chr "VAR object x"
>   .. ..- attr(*, "class")= chr "htest"
>  $ jp:List of 2
> .
> .
> .
> .
> 
> Best Regards,
> 
> Ivan
> 
> On Fri, Apr 15, 2011 at 10:13 AM, Pfaff, Bernhard Dr.
>  wrote:
> > Dear Ivan,
> >
> > first, it would pay-off in terms of readability to employ 
> line breaks and second to provide a reproducable code snippet 
> and third which package you have used. Now to your questions:
> > 1) What happens if you provide colnames for your objects?
> > 2) What happens if you omit the $ after count?
> >
> > Best,
> > Bernhard
> >
> > ps: the function seems to have been ported from the package 
> 'vars'. In this package the function causality() is included 
> which returns a named list with elements of class htest.
> >
> >> -Ursprüngliche Nachricht-
> >> Von: r-help-boun...@r-project.org
> >> [mailto:r-help-boun...@r-project.org] Im Auftrag von ivan
> >> Gesendet: Donnerstag, 14. April 2011 19:37
> >> An: r-help@r-project.org
> >> Betreff: [R] Automatically extract info from Granger 
> causality output
> >>
> >> Dear Community,
> >>
> >> this is my first programming in R and I am stuck with a problem. I 
> >> have the following code which automatically calculates Granger 
> >> causalities from a variable, say e.g. "bs"
> >> as below, to all other variables in the data frame:
> >>
> >> log.returns<-as.data.frame( lapply(daten, function(x)
> >> diff(log(ts(x) y1<-log.returns$bs
> >> y2<- log.returns[,!(names(log.returns) %in% "bs")]
> >> Granger<- function(y1,y2) {models=lapply(y2, function(x)
> >> VAR(cbind(x,y1),ic="SC") ); results=lapply(models,function(x) 
> >> causality(x,cause="y1")); print(results)}
> >> Count<-Granger(y1,y2)
> >>
> >> which produces the following output (I have printed only 
> part of it 
> >> (for Granger causality of bs on ml)):
> >>
> >> $ml
> >> $ml$Granger
> >>
> >>         Granger causality H0: y1 do not Granger-cause x
> >>
> >> data:  VAR object x
> >> F-Test = 0.2772, df1 = 1, df2 = 122, p-value = 0.5995
> >>
> >>
> >> $ml$Instant
> >>
> >>         H0: No instantaneous causality between: y1 and x
> >>
> >> data:  VAR object x
> >> Chi-squared = 19.7429, df = 1, p-value = 8.859e-06
> >>
> >> My questions:
> >>
> >> 1)How can I edit the function above so that the output writes: 
> >> Granger causality H0: bs do not Granger-cause ml   rather than  
> >> Granger causality H0: y1 do not Granger-cause x?
> >>
> >> 2) I want to extract the p-values of the tests into a data 
> frame for 
> >> instance. The problem is that the output has a 3 layer structure.
> >> Thus, for the above p-value I need to write 
> count$ml$Granger$p.value.
> >> I thought of a loop of something like for(i in
> >> 1:length(count)) {z=count$[[i]]$Granger$p.value} but it 
> didn't work.
> >>
> >> Thank you very much for your help.
> >>
> >> Best Regards.
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-con

Re: [R] Plotting an Underbrace in R

2011-04-15 Thread baptiste auguie
Hi,

Through pgfSweave you can use the tikz device, which is the one that
can interpret Latex code (package tikzDevice). I would start with a
minimal self-contained plot with this function. see ?tikz for
examples.

HTH,

baptiste




On 15 April 2011 20:03, Michael McAssey  wrote:
> Ben,
>
> This example of pgfSweave looks like it would address my problem.  I
> installed this package, but I cannot determine how to use it to make R
> convert LaTeX commands into mathematical symbols on an R plot.  The
> documentation does not seem to address this.  I tried to mimic the
> example from Yihui Xie that you provided but R only puts the LaTeX
> code on my plot without converting it.  That is, if in the R GUI I
> have:
>
>> library(pgfSweave)
>> plot(1:10, 1:10, "$Y=\\beta_0 + \\beta_1 x + \\epsilon$")
>
> then in the plot the y-axis label is $Y=\beta_0 + \beta_1 x +
> \epsilon$ rather than what I want.  I can't find any useful help on
> Google.  Any further suggestions?
>
> Thanks.
>
> Michael
>
>
> On Thu, Apr 14, 2011 at 11:22 PM, Ben Bolker  wrote:
>>
>> Michael McAssey  gmail.com> writes:
>>
>> >
>> > I need to include some mathematical expressions in a plot I am creating in
>> > R, one of which requires an underbrace, which in LaTeX would be written 
>> > like
>> >
>> > \underbrace{T \cdots T}_{n times}
>> >
>> > There does not appear to be a provision for this in plotmath, and I cannot
>> > find anything on the topic in the R-help archive or in a Google search.  I
>> > would appreciate some help with this.
>>
>>  Does
>>
>> 
>>
>>  help at all?
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Michael P. McAssey, Ph.D.
> Statistics for Life Sciences, Department of Mathematics
> Faculty of Sciences, Vrije Universiteit Amsterdam
> De Boelelaan 1081a, 1081 HV Amsterdam, The Netherlands
> Office: S-230, W&N building
> Tel: +31 (0)20 598 7724
> Fax: +31 (0)20 598 7653
> Mobile: +31 (0)62 113 8600
> http://www.few.vu.nl/~mmy700/
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Automatically extract info from Granger causality output

2011-04-15 Thread ivan
Dear Bernhard,

thank you very much for the response. Yes, I am using the packsges
"vars" with fuchrions VAR() and causality().

1)Giving colnames to the objects does unfortunately not  change anything.

2) I am not sure if I understood you right. Did you mean to insert
Countml$Granger$p.value rather than  Count$ml$Granger$p.value? This
returns: Error: Object 'Countms' not found.

By the way, str(Count) produces the following:

> str(Count)
List of 4
 $ ml:List of 2
  ..$ Granger:List of 5
  .. ..$ statistic: num [1, 1] 0.277
  .. .. ..- attr(*, "names")= chr "F-Test"
  .. ..$ parameter: Named num [1:2] 1 122
  .. .. ..- attr(*, "names")= chr [1:2] "df1" "df2"
  .. ..$ p.value  : num [1, 1] 0.6
  .. ..$ method   : chr "Granger causality H0: y1 do not Granger-cause x"
  .. ..$ data.name: chr "VAR object x"
  .. ..- attr(*, "class")= chr "htest"
  ..$ Instant:List of 5
  .. ..$ statistic: num [1, 1] 19.7
  .. .. ..- attr(*, "names")= chr "Chi-squared"
  .. ..$ parameter: Named int 1
  .. .. ..- attr(*, "names")= chr "df"
  .. ..$ p.value  : num [1, 1] 8.86e-06
  .. ..$ method   : chr "H0: No instantaneous causality between: y1 and x"
  .. ..$ data.name: chr "VAR object x"
  .. ..- attr(*, "class")= chr "htest"
 $ jp:List of 2
.
.
.
.

Best Regards,

Ivan

On Fri, Apr 15, 2011 at 10:13 AM, Pfaff, Bernhard Dr.
 wrote:
> Dear Ivan,
>
> first, it would pay-off in terms of readability to employ line breaks and 
> second to provide a reproducable code snippet and third which package you 
> have used. Now to your questions:
> 1) What happens if you provide colnames for your objects?
> 2) What happens if you omit the $ after count?
>
> Best,
> Bernhard
>
> ps: the function seems to have been ported from the package 'vars'. In this 
> package the function causality() is included which returns a named list with 
> elements of class htest.
>
>> -Ursprüngliche Nachricht-
>> Von: r-help-boun...@r-project.org
>> [mailto:r-help-boun...@r-project.org] Im Auftrag von ivan
>> Gesendet: Donnerstag, 14. April 2011 19:37
>> An: r-help@r-project.org
>> Betreff: [R] Automatically extract info from Granger causality output
>>
>> Dear Community,
>>
>> this is my first programming in R and I am stuck with a
>> problem. I have the following code which automatically
>> calculates Granger causalities from a variable, say e.g. "bs"
>> as below, to all other variables in the data frame:
>>
>> log.returns<-as.data.frame( lapply(daten, function(x)
>> diff(log(ts(x) y1<-log.returns$bs
>> y2<- log.returns[,!(names(log.returns) %in% "bs")]
>> Granger<- function(y1,y2) {models=lapply(y2, function(x)
>> VAR(cbind(x,y1),ic="SC") ); results=lapply(models,function(x)
>> causality(x,cause="y1")); print(results)}
>> Count<-Granger(y1,y2)
>>
>> which produces the following output (I have printed only part
>> of it (for Granger causality of bs on ml)):
>>
>> $ml
>> $ml$Granger
>>
>>         Granger causality H0: y1 do not Granger-cause x
>>
>> data:  VAR object x
>> F-Test = 0.2772, df1 = 1, df2 = 122, p-value = 0.5995
>>
>>
>> $ml$Instant
>>
>>         H0: No instantaneous causality between: y1 and x
>>
>> data:  VAR object x
>> Chi-squared = 19.7429, df = 1, p-value = 8.859e-06
>>
>> My questions:
>>
>> 1)How can I edit the function above so that the output writes: Granger
>> causality H0: bs do not Granger-cause ml   rather than  Granger
>> causality H0: y1 do not Granger-cause x?
>>
>> 2) I want to extract the p-values of the tests into a data
>> frame for instance. The problem is that the output has a 3
>> layer structure.
>> Thus, for the above p-value I need to write count$ml$Granger$p.value.
>> I thought of a loop of something like for(i in
>> 1:length(count)) {z=count$[[i]]$Granger$p.value} but it didn't work.
>>
>> Thank you very much for your help.
>>
>> Best Regards.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> *
> Confidentiality Note: The information contained in this message,
> and any attachments, may contain confidential and/or privileged
> material. It is intended solely for the person(s) or entity to
> which it is addressed. Any review, retransmission, dissemination,
> or taking of any action in reliance upon this information by
> persons or entities other than the intended recipient(s) is
> prohibited. If you received this in error, please contact the
> sender and delete the material from any computer.
> *
>
>

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

Re: [R] simulations with very large number of iterations (1 billion)

2011-04-15 Thread Viechtbauer Wolfgang (STAT)
We do not know the details of the kinds of computations you intend to do within 
each iteration, but if, let's say, each iterations takes around 1 second, then 
your simulation will run for the next 30+ years (on a single core). Even if 
each iteration only takes a fraction of a second, you are still looking at 
years here. If you can parallelize things, you may be able to make this work 
within a realistic time frame, but this assumes access to dozens of cores.

Good luck!

Best,

--
Wolfgang Viechtbauer
Department of Psychiatry and Neuropsychology
School for Mental Health and Neuroscience
Maastricht University, P.O. Box 616
6200 MD Maastricht, The Netherlands
Tel: +31 (43) 368-5248
Fax: +31 (43) 368-8689
Web: http://www.wvbauer.com



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Brian J Mingus
Sent: Friday, April 15, 2011 08:29
To: Marion Dumas
Cc: r-help@r-project.org
Subject: Re: [R] simulations with very large number of iterations (1 billion)


On Thu, Apr 14, 2011 at 7:41 PM, Marion Dumas  wrote:

> Hello R-help list
> I'm trying to run 1 billion iterations of a code with calls to random
> distributions to implement a data generating process and subsequent
> computation of various estimators that are recorded for further
> comparison of performance. I have two question about how to achieve
> this: 1. the most important: on my laptop, R gives me an error message
> saying that it cannot allocate sufficient space for the matrix that is
> meant to record the results (a 1 billion by 4 matrix). Is this
> computer-specific? Are there ways to circumvent this limit? Or is it
> hopeless to run 1 billion iterations in one batch? ( the alternative
> being to run, for example, 1000 iterations of a 1 million iteration
> process that spits out output files that can then be combined
> manually). 2. secondly: when I profile the code on a smaller number of
> iterations, it says that colSums is the function that has the longest
> self time. I am using this to compute  stratum-specific treatment
> effects. My thinking was that the fastest way to compute mean outcome
> conditional on treatment for each stratum would be to combine all
> strata in one matrix and apply colSums-type functions on it. Maybe I
> am wrong and there are better ways?
>
> Thank you in advance for any help you may provide.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


The first thing you need to do is estimate the amount of memory that is going 
to being needed. Then, estimate the amount of time it's going to take. You 
probably need a 64 bit computer and 4-8 GB of memory at least. You may not want 
to use R, insteading opting for C code and the GNU Scientific Library. If you 
can't write C code Lua is pretty easy to learn and GSL has been exposed through 
it in the GSL Shell: http://www.nongnu.org/gsl-shell/


--
Brian Mingus
Graduate student
Computational Cognitive Neuroscience Lab
University of Colorado at Boulder

[[alternative HTML version deleted]]

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

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


Re: [R] Plotting an Underbrace in R

2011-04-15 Thread Michael McAssey
Ben,

This example of pgfSweave looks like it would address my problem.  I
installed this package, but I cannot determine how to use it to make R
convert LaTeX commands into mathematical symbols on an R plot.  The
documentation does not seem to address this.  I tried to mimic the
example from Yihui Xie that you provided but R only puts the LaTeX
code on my plot without converting it.  That is, if in the R GUI I
have:

> library(pgfSweave)
> plot(1:10, 1:10, "$Y=\\beta_0 + \\beta_1 x + \\epsilon$")

then in the plot the y-axis label is $Y=\beta_0 + \beta_1 x +
\epsilon$ rather than what I want.  I can't find any useful help on
Google.  Any further suggestions?

Thanks.

Michael


On Thu, Apr 14, 2011 at 11:22 PM, Ben Bolker  wrote:
>
> Michael McAssey  gmail.com> writes:
>
> >
> > I need to include some mathematical expressions in a plot I am creating in
> > R, one of which requires an underbrace, which in LaTeX would be written like
> >
> > \underbrace{T \cdots T}_{n times}
> >
> > There does not appear to be a provision for this in plotmath, and I cannot
> > find anything on the topic in the R-help archive or in a Google search.  I
> > would appreciate some help with this.
>
>  Does
>
> 
>
>  help at all?
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



--
Michael P. McAssey, Ph.D.
Statistics for Life Sciences, Department of Mathematics
Faculty of Sciences, Vrije Universiteit Amsterdam
De Boelelaan 1081a, 1081 HV Amsterdam, The Netherlands
Office: S-230, W&N building
Tel: +31 (0)20 598 7724
Fax: +31 (0)20 598 7653
Mobile: +31 (0)62 113 8600
http://www.few.vu.nl/~mmy700/

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


Re: [R] Automatically extract info from Granger causality output

2011-04-15 Thread Pfaff, Bernhard Dr.
Dear Ivan,

first, it would pay-off in terms of readability to employ line breaks and 
second to provide a reproducable code snippet and third which package you have 
used. Now to your questions:
1) What happens if you provide colnames for your objects?
2) What happens if you omit the $ after count?

Best,
Bernhard

ps: the function seems to have been ported from the package 'vars'. In this 
package the function causality() is included which returns a named list with 
elements of class htest.  

> -Ursprüngliche Nachricht-
> Von: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] Im Auftrag von ivan
> Gesendet: Donnerstag, 14. April 2011 19:37
> An: r-help@r-project.org
> Betreff: [R] Automatically extract info from Granger causality output
> 
> Dear Community,
> 
> this is my first programming in R and I am stuck with a 
> problem. I have the following code which automatically 
> calculates Granger causalities from a variable, say e.g. "bs" 
> as below, to all other variables in the data frame:
> 
> log.returns<-as.data.frame( lapply(daten, function(x) 
> diff(log(ts(x) y1<-log.returns$bs
> y2<- log.returns[,!(names(log.returns) %in% "bs")]
> Granger<- function(y1,y2) {models=lapply(y2, function(x)
> VAR(cbind(x,y1),ic="SC") ); results=lapply(models,function(x) 
> causality(x,cause="y1")); print(results)}
> Count<-Granger(y1,y2)
> 
> which produces the following output (I have printed only part 
> of it (for Granger causality of bs on ml)):
> 
> $ml
> $ml$Granger
> 
> Granger causality H0: y1 do not Granger-cause x
> 
> data:  VAR object x
> F-Test = 0.2772, df1 = 1, df2 = 122, p-value = 0.5995
> 
> 
> $ml$Instant
> 
> H0: No instantaneous causality between: y1 and x
> 
> data:  VAR object x
> Chi-squared = 19.7429, df = 1, p-value = 8.859e-06
> 
> My questions:
> 
> 1)How can I edit the function above so that the output writes: Granger
> causality H0: bs do not Granger-cause ml   rather than  Granger
> causality H0: y1 do not Granger-cause x?
> 
> 2) I want to extract the p-values of the tests into a data 
> frame for instance. The problem is that the output has a 3 
> layer structure.
> Thus, for the above p-value I need to write count$ml$Granger$p.value.
> I thought of a loop of something like for(i in 
> 1:length(count)) {z=count$[[i]]$Granger$p.value} but it didn't work.
> 
> Thank you very much for your help.
> 
> Best Regards.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
*
Confidentiality Note: The information contained in this ...{{dropped:10}}

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


  1   2   >