[R] New random number generator (RNG)

2011-10-03 Thread dataguru
Based on very fast converging series for special transcendental
numbers. Is there some R code available?

See details about the RNG at
http://www.analyticbridge.com/profiles/blogs/new-state-of-the-art-random-number-generator-simple-strong-and-fa

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 format Rsuperscript 2 followed by = value

2011-10-03 Thread Nevil Amos

I am trying to put  an
R2 value with R2 formatted with a superscript 2 followed by "=" and the 
value :
the first mtext prints the R2 correctly formatted but follows it with 
"=round(summary(mylm)$r.squared,3)))" as text
the second prints "R^2 =" followed by the value of 
round(summary(mylm)$r.squared,3))).


how do I correctly write the expression to get formatted r2 followed by 
the value?





x=runif(10)
y=runif(10)
summary(mylm<-lm(y~x))
plot(x,y)
abline(mylm)
mtext(expression(paste(R^2,"=",round(summary(mylm)$r.squared,3))),1)
mtext(paste(expression(R^2),"=",round(summary(mylm)$r.squared,3)),3)



thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Unable to load local library via GUI

2011-10-03 Thread Noel Faux
Hi all,

Not sure if this is the best list, please point me to a more appropriate list 
if necessary.

Running Mac OSX 10.7.1
R version 2.13.1 Patched (2011-08-14 r56741)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

I have a locally developed library (libmlalgs), which I am able to install via 
the command line:
sudo R CMD INSTALL libmlalgs
In the 
/Library/Frameworks/R.framework/Versions/2.13/Resources/library/libmlalgs there 
is a .so file
/Library/Frameworks/R.framework/Versions/2.13/Resources/library/libmlalgs/libs/x86_64/libmlalgs.so

This runs and installs OK.
I am able to run R64 in the command line and load the libmlalgs library fine :)
I am able to use Rstudio and load the libmlalgs library fine.

However, when using the R64.app and try and load the library within the GUI I 
am getting the following error:
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object 
'/Library/Frameworks/R.framework/Versions/2.13/Resources/library/libmlalgs/libs/x86_64/libmlalgs.so':
  
dlopen(/Library/Frameworks/R.framework/Versions/2.13/Resources/library/libmlalgs/libs/x86_64/libmlalgs.so,
 6): Library not loaded: libRblas.dylib
  Referenced from: 
/Library/Frameworks/R.framework/Versions/2.13/Resources/library/libmlalgs/libs/x86_64/libmlalgs.so
  Reason: image not found
Error in library(libmlalgs) : .First.lib failed for 'libmlalgs'

I know the libmlalgs.so is in the right place and the permissions look OK:
-rwxr-xr-x  1 root  admin  58384  3 Oct 14:30 libmlalgs.so

So I am stumped as to why the GUI is unable to read the file.

Any pointers would very welcome. As I am a textmate user and it passes the code 
to the R64.app, I currently stuck with either command line or Rstudio (it's 
nice but is currently missing some key features textmate has)


Many thanks,
Noel Faux

NHMRC Post Doctoral Fellow
Australian Imaging Biomarker Lifestyle (AIBL) flagship
Mental Health Research Institute
The University of Melbourne

155 Oak St, Parkville
Victoria 3052
Australia
T: +613 9389 2943

National Neuroscience Facility
Level 3, Alan Gilbert Building
161 Barry Street, Carlton
Victoria 3010
Australia
T: +613 8344 1944
e-mail: nf...@unimelb.edu.au
www.mhri.edu.au
biocoder: http://biocoders.net/members/nfaux/

This email and any attachments are confidential. They ma...{{dropped:14}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] new standardised variable based on group membership

2011-10-03 Thread John.Morrongiello
Hi
I have a data comprised of repeated measures of growth (5-15 records per 
individual) for 580 fish (similar to Orange dataset from nlme library). I would 
like to standardise these growth measures (yi – ŷ/sd) using mean and 
standard deviation unique to each fish. Can someone suggest a function that 
would help me do this? I’ve had a look at scale and sweep but can’t find a 
worked example that does what I’m after

Cheers

John


[[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] deSolve - Function daspk on DAE system - Error (Vince)

2011-10-03 Thread Soetaert, Karline
Vince, 

When that happens, one possible reason is that your DAE is of index > 1,
which cannot be solved by daspk.

The solver radau, also from deSolve can handle DAEs up to index 3, but
you need to rewrite the problem in the form M*y' = f(x,y), where M is a
mass matrix.

If you do that for your problem, and solve it with radau, then radau
complains that the "matrix is repeatedly  singular", the problem is too
stiff, and it stops just like daspk. 
I think this means that this particular DAE is unsolvable, so you will
need to look at the formulation itself. 

By the way, there is a special R-mailinglist that deals with this type
of problems:
r-sig-dynamic-mod...@r-project.org


Hope this helps,


Karline

-
Original message:

Date: Sat, 1 Oct 2011 20:20:10 -0700 (PDT)
From: Vince 
To: r-help@r-project.org
Subject: [R] deSolve - Function daspk on DAE system - Error
Message-ID: <1317525610060-3864298.p...@n4.nabble.com>
Content-Type: text/plain; charset=us-ascii

I'm getting this error on the attached code and breaking my head but
can't
figure it out. Any help is much appreciated. Thanks, Vince

CODE:
library(deSolve)

Res_DAE=function(t, y, dy, pars) {
  with(as.list(c(y, dy, pars)), {
 
  res1 = -dS -dES-k2*ES
  res2 = -dP + k2*ES
 
  eq1 = Eo-E -ES
  eq2 = So-S -ES -P
  return(list(c(res1, res2, eq1, eq2)))
  })
}

pars <- c(Eo=0.02, So=0.02, k2=250, E=0.01); pars
yini <- c(S=0.01, ES = 0.01, P=0.0, E=0.01); yini
times <- seq(0, 0.01, by = 0.0001); times
dyini = c(dS=0.0, dES=0.0, dP=0.0)

## Tabular output check of matrix output

DAE <- daspk(y = yini, dy = dyini, times = times, res = Res_DAE, parms =
pars, atol = 1e-10, rtol = 1e-10)

ERROR:
daspk--  warning.. At T(=R1) and stepsize H (=R2) the  nonlinear
solver
f
  nonlinear solver failed to converge  repeatedly of with abs
(H) =
H
  repeatedly of with abs (H) = HMIN  preconditioner had repeated
failur
0.0D+00  0.5960464477539D-14

Warning messages:
1: In daspk(y = yini, dy = dyini, times = times, res = Res_DAE, parms =
pars,  :
  repeated convergence test failures on a step - inaccurate Jacobian or
preconditioner?
2: In daspk(y = yini, dy = dyini, times = times, res = Res_DAE, parms =
pars,  :
  Returning early. Results are accurate, as far as they go

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


Re: [R] new standardised variable based on group membership

2011-10-03 Thread ONKELINX, Thierry
Dear John,

You need to combine scale with a grouping function.

data(Orange)
library(plyr)
Orange <- ddply(Orange, .(Tree), function(x){
x$ddplyAge <- scale(x$age)[, 1]
x
})

Orange$aveAge <- ave(Orange$age, by = Orange$Tree, FUN = scale)

all.equal(Orange$ddplyAge, Orange$aveAge)

Best regards,

Thierry


> -Oorspronkelijk bericht-
> Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> Namens john.morrongie...@csiro.au
> Verzonden: maandag 3 oktober 2011 7:34
> Aan: r-help@r-project.org
> Onderwerp: [R] new standardised variable based on group membership
> 
> Hi
> I have a data comprised of repeated measures of growth (5-15 records per
> individual) for 580 fish (similar to Orange dataset from nlme library). I 
> would like
> to standardise these growth measures (yi – ŷ/sd) using mean and standard
> deviation unique to each fish. Can someone suggest a function that would help
> me do this? I’ve had a look at scale and sweep but can’t find a worked example
> that does what I’m after
> 
> Cheers
> 
> John
> 
> 
>   [[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] Understanding the workflow between sweave, R and Latex

2011-10-03 Thread Liviu Andronic
On Fri, Sep 30, 2011 at 2:41 PM, Duncan Murdoch
 wrote:
> As an aside, I don't recommend the workflow you describe:  it's very slow
> and cumbersome.  It's much better to tell your text editor how to run both
> Sweave and Latex in one command.  In the upcoming release of R 2.14.0, this
>
Another approach is to use LyX. The latest stable release comes with
an Sweave module that provides out-of-the box support for Sweave
documents. Once everything is configured, and on a Mac it should be
fairly straightforward in this case, then compiling documents is
usually a matter of pressing a button or activating a key combination.
LyX takes care of a lot of automation for you, including BibTeX et al.

Regards
Liviu

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

2011-10-03 Thread Liviu Andronic
Dear all
How does print.htest display the p-value in scientific notation?
> (x <- cor.test(iris[[1]], iris[[3]]))

Pearson's product-moment correlation

data:  iris[[1]] and iris[[3]]
t = 21.65, df = 148, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.8270 0.9055
sample estimates:
   cor
0.8718

Above the p-value comes as '< 2.2e-16', while inspecting the object I
get a good old '0'.
> x$p.value
[1] 0

I tried to inspect print.htest but couldn't find it. I also played
with format, round and the like to no avail. Any pointers?

Regards
Liviu


-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

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


Re: [R] Gstat - Installation Fail _ download source and compile help ...

2011-10-03 Thread Paul Hiemstra
Hi Sandeep,

You need to provide way more detail for us to be able to help you:

- Which version of gstat do you want to install, ?
- where did you get the sources, ?
- is it the version inside R or the standalone version?
- what version of R are you running?
- *what is the exact error that gstat gave*?
- have you tried the precompiled gstat standalone binaries?

Furthermore, this is not the correct forum to get help for gstat, this
is far more appropriate for the R-sig-geo mailing list. Another helpful
mailing list is:

http://www2.52north.org/mailman/listinfo/geostatistics

good luck,
Paul


On 10/01/2011 05:03 PM, Sandeep Patil wrote:
> Hello
>
> I have been trying to install gstat on university's unix based system ( i am
> not familiar with many technical aspects of installation) but i am getting a
> particular error which i could not find a solution to online. Here is what
> the technical support guy mailed me back, i am sure someone who understands
> the technicalities can explain me this procedure in a more lucid way.
> *
> **Technical Assistant's reply*
> *
> Unfortunately, the error is due to a type being used in one of the
> source files which has not yet been defined in an include file.
> The "u_int" type is defined in /usr/include/sys/types.h:
>
>typedef __u_int u_int;
>
> And, the "__u_int" type is defined in /usr/include/bits/types.h:
>
>typedef unsigned int __u_int;
>
> Note that  is included at the top of , so
> only the  would need to be included.
>
> Without including , the program won't recognize
> "u_int" as a valid type.  So, this is an issue with the configuration
> or perhaps source for the given program being compiled by the
> package installation function of R.
>
> My suggestion would be to search for the given error message on any
> support/help/discussion boards/websites related to the R program.
> Or, do a google search to see if anyone else has encountered the same
> error and find their suggested solution.
>
> Otherwise, you can manually download the source to your directory and
> attempt to tweak the "configure" command, which would generate a more
> correct Makefile.  Or, in the least desirable scenario, insert the
> needed "#include " in the given *.c file yourself and
> compile.
> *
> Can anyone make out anything from this , i want to tweak the configure
> command but do not know how to proceed.
>
>   [[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.


-- 
Paul Hiemstra, Ph.D.
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] extracting p-values in scientific notation

2011-10-03 Thread Rolf Turner


Isn't it true that 0 < 2.2e-16?

cheers,

Rolf Turner

On 03/10/11 20:53, Liviu Andronic wrote:

Dear all
How does print.htest display the p-value in scientific notation?

(x<- cor.test(iris[[1]], iris[[3]]))

Pearson's product-moment correlation

data:  iris[[1]] and iris[[3]]
t = 21.65, df = 148, p-value<  2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
  0.8270 0.9055
sample estimates:
cor
0.8718

Above the p-value comes as '<  2.2e-16', while inspecting the object I
get a good old '0'.

x$p.value

[1] 0

I tried to inspect print.htest but couldn't find it. I also played
with format, round and the like to no avail. Any pointers?

Regards
Liviu




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


Re: [R] extracting p-values in scientific notation

2011-10-03 Thread Kenn Konstabel
> is(x)
[1] "htest"
> # take a look at stats:::print.htest
> format.pval(x$p.value)
[1] "< 2.22e-16"

Does that answer your question?

KK

On Mon, Oct 3, 2011 at 10:53 AM, Liviu Andronic  wrote:
> Dear all
> How does print.htest display the p-value in scientific notation?
>> (x <- cor.test(iris[[1]], iris[[3]]))
>
>        Pearson's product-moment correlation
>
> data:  iris[[1]] and iris[[3]]
> t = 21.65, df = 148, p-value < 2.2e-16
> alternative hypothesis: true correlation is not equal to 0
> 95 percent confidence interval:
>  0.8270 0.9055
> sample estimates:
>   cor
> 0.8718
>
> Above the p-value comes as '< 2.2e-16', while inspecting the object I
> get a good old '0'.
>> x$p.value
> [1] 0
>
> I tried to inspect print.htest but couldn't find it. I also played
> with format, round and the like to no avail. Any pointers?
>
> Regards
> Liviu
>
>
> --
> Do you know how to read?
> http://www.alienetworks.com/srtest.cfm
> http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
> Do you know how to write?
> http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] patients.txt data

2011-10-03 Thread Paul Hiemstra
On 10/02/2011 08:00 PM, Nadine Melhem wrote:
> please send me the "patients.txt" data.
>
> thanks.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

I'm not really sure why you send this kind of e-mail to the R-help list.
If you need a dataset, aks your instructor to provide it for you. And:

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

Paul

-- 
Paul Hiemstra, Ph.D.
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] extracting p-values in scientific notation

2011-10-03 Thread Ted Harding
One point to note, for information, in this discussion is
that cor.test() has apparently returned the P-value as
an exact zero:

  x$p.value == 0
  # [1] TRUE

  identical(x$p.value, 0)
  # [1] TRUE

(which, by the way, I was led to after trying log10(x$p.value)
and getting -Inf). Perhaps a more interesting question is how
cor.test computes the P-value!

Ted.

On 03-Oct-11 08:48:31, Kenn Konstabel wrote:
>> is(x)
> [1] "htest"
>> # take a look at stats:::print.htest
>> format.pval(x$p.value)
> [1] "< 2.22e-16"
> 
> Does that answer your question?
> 
> KK
> 
> On Mon, Oct 3, 2011 at 10:53 AM, Liviu Andronic
>  wrote:
>> Dear all
>> How does print.htest display the p-value in scientific notation?
>>> (x <- cor.test(iris[[1]], iris[[3]]))
>>
>> _ _ _ _Pearson's product-moment correlation
>>
>> data: _iris[[1]] and iris[[3]]
>> t = 21.65, df = 148, p-value < 2.2e-16
>> alternative hypothesis: true correlation is not equal to 0
>> 95 percent confidence interval:
>> _0.8270 0.9055
>> sample estimates:
>> _ cor
>> 0.8718
>>
>> Above the p-value comes as '< 2.2e-16', while inspecting the object I
>> get a good old '0'.
>>> x$p.value
>> [1] 0
>>
>> I tried to inspect print.htest but couldn't find it. I also played
>> with format, round and the like to no avail. Any pointers?
>>
>> Regards
>> Liviu
>>
>>
>> --
>> Do you know how to read?
>> http://www.alienetworks.com/srtest.cfm
>> http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
>> Do you know how to write?
>> http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 03-Oct-11   Time: 10:05:50
-- XFMail --

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


Re: [R] ggplot2 - extracting values of smooth

2011-10-03 Thread Paul Hiemstra
On 09/30/2011 04:39 PM, dM/ wrote:
> Suppose that I'm working on Hadley's diamond dataset and I want to
> review the relationship between price, colour and carat.
>
> I might run the following:
>
> library(ggplot2)
>
> #plot scatter and add some hex binning
>  q<-qplot(carat,price,data=diamonds, geom=c("hex"),
>  main="Variability of Diamond Prices by Carat and Colour")
>
> #facet to get one scatter for each colour, plus overlay a black
> coloured loess smoothed line showing the trends in the data
>
> q +
> facet_wrap(~color,ncol=2)+geom_smooth(aes(group=1),colour=I("black"))
>
> Nice picture, but how do I extract the values of the smoothed line?
>
> Many thanks, dM/
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Hi,

geom_smooth uses R functions to calculate the smooth line. Check out
?stat_smooth for more details. You can run these command outside ggplot
to the values of the smoothed line. e.g.:

library(ggplot2)
# Make the plot
ggplot(aes(x = speed, y = dist), data = cars) + geom_point() +
stat_smooth(method = "loess")
# Get the values
smooth_vals = predict(loess(dist~speed,cars), cars$speed)

Getting the values for other smoothing functions follows this same recipe.

good luck,
Paul





-- 
Paul Hiemstra, Ph.D.
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] ggplot2 - extracting values of smooth

2011-10-03 Thread Paul Hiemstra
On 09/30/2011 04:39 PM, dM/ wrote:
> Suppose that I'm working on Hadley's diamond dataset and I want to
> review the relationship between price, colour and carat.
>
> I might run the following:
>
> library(ggplot2)
>
> #plot scatter and add some hex binning
>  q<-qplot(carat,price,data=diamonds, geom=c("hex"),
>  main="Variability of Diamond Prices by Carat and Colour")
>
> #facet to get one scatter for each colour, plus overlay a black
> coloured loess smoothed line showing the trends in the data
>
> q +
> facet_wrap(~color,ncol=2)+geom_smooth(aes(group=1),colour=I("black"))
>
> Nice picture, but how do I extract the values of the smoothed line?
>
> Many thanks, dM/
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

...and if you want to extract the smoothed lines per factor (as when
using facet_wrap) use ddply.

good luck,
Paul

-- 
Paul Hiemstra, Ph.D.
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] open source editor for r for beginners

2011-10-03 Thread Marion Wenty
dear users,
sorry for the late reply! thank you all very much for your input.
i think for now i will try rstudio which was recommended most and later on i
will start learning vim or emacs.
it was very interesting to read about your experiences. thanx!
marion

2011/9/20 Ken Hutchison 

> Rstudio and Rcmdr are very popular and for good reason, find a good book
> while the latter is installing though.
>  IF you are using linux, rkward is fantastic to woRk with.
>Ken Hutchison
>
> On Tue, Sep 20, 2011 at 11:21 AM, Steve Lianoglou <
> mailinglist.honey...@gmail.com> wrote:
>
> > I just wanted to second Rstudio:
> >
> > http://rstudio.org/
> >
> > Honestly, try this first -- it's an easy install, it just works, and
> > there's no real learning curve to the editor itself.  Very n00b
> > friendly.
> >
> > -steve
> >
> >
> > On Tue, Sep 20, 2011 at 9:28 AM, R. Michael Weylandt
> >  wrote:
> > > RStudio
> > >
> > >
> > > Hope this helps,
> > > Michael Weylandt
> > >
> > > On Tue, Sep 20, 2011 at 9:26 AM, Marion Wenty  > >wrote:
> > >
> > >> Hello all,
> > >>
> > >> I am looking for an editor for R which has got functions beyond the
> > normal
> > >> R
> > >> editor that is included in the program.
> > >>
> > >> I had a look at VIM but I think it's difficult if you are just
> starting
> > >> programming.
> > >>
> > >> Could anyone recommend an editor that is suitable for beginners?
> > >>
> > >> Thanks for your help.
> > >>
> > >> Marion
> > >>
> > >>[[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.
> > >
> >
> >
> >
> > --
> > Steve Lianoglou
> > Graduate Student: Computational Systems Biology
> >  | Memorial Sloan-Kettering Cancer Center
> >  | Weill Medical College of Cornell University
> > Contact Info: http://cbio.mskcc.org/~lianos/contact
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] extracting p-values in scientific notation

2011-10-03 Thread Liviu Andronic
Thanks all for your pointers. The following does trick:
> base::format.pval(x$p.value)  ##Hmisc also has such a function
[1] "<2e-16"


On Mon, Oct 3, 2011 at 10:25 AM, Rolf Turner  wrote:
> Isn't it true that 0 < 2.2e-16?
>

Yes, but it doesn't mean that the p-value actually hits absolute zero.
And cor.test, as Ted noticed, returns
> identical(x$p.value, 0)
[1] TRUE

Not that this makes a great practical difference in my case, but I
would still prefer to print "<2e-16" in my Sweave document.

Regards
Liviu

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

2011-10-03 Thread Petr PIKAL
Hi

> 
> I realize that this is terribly basic, but I just don't seem to see it 
at 
> this moment, so I would very much appreciate your help.
> 
> 
> How shall I transform this dataframe:
> 
> > df1
>   Name Index Value
> 1a 1   0.1
> 2a 2   0.2
> 3a 3   0.3
> 4a 4   0.4
> 5b 1   2.1
> 6b 2   2.2
> 7b 3   2.3
> 8b 4   2.4
> 
> 
> into this dataframe:
> 
> > df2
> Index  a   b
> 1  1 0.1 2.1
> 2  2 0.2 2.2
> 3  3 0.3 2.3
> 4  4 0.4 2.4
> 

I have not seen an answer so I believe you look for:

cast(df1, Index~Name, value = "Value")

Regards
Petr


> 
> df1 = data.frame(c("a", "a", "a", "a", "b", "b", "b", "b"), 
c(1,2,3,4,1,2,
> 3,4), c(0.1, 0.2, 0.3, 0.4, 2.1, 2.2, 2.3, 2.4))
> colnames(df1) = c("Name", "Index", "Value")
> 
> df2 = data.frame(c(1,2,3,4), c(0.1, 0.2, 0.3, 0.4), c(2.1, 2.2, 2.3, 
2.4))
> colnames(df2) = c("Index", "a", "b")
> 
> 
> Thank you very much.
> 
> Dana
> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Interaction plot type=o

2011-10-03 Thread Gavin Simpson
On Fri, 2011-09-30 at 12:33 -0400, David Winsemius wrote:
> On Sep 30, 2011, at 2:16 AM, Petr PIKAL wrote:
> 
> >>
> >> David,
> >> thank you for your reply
> >>
> >> I tried this
> >> attach(mtcars)
> >> interaction.plot(cyl, gear, mpg, type="o", pch=5:8, lty=1 )
> >>
> >> but I got this error:
> >> Error in match.arg(type) : 'arg' should be one of "l", "p", "b"
> >>
> >> and in ?interaction.plot, "o" it is not listed in type arguments.
> >> Is there any other way to force it to take the argument?
> >
> > As David suggested you need to change code for interaction.plot. If  
> > you
> > write
> >
> > interaction.plot
> >
> > you will get the code
> >
> >> interaction.plot
> > function (x.factor, trace.factor, response, fun = mean, type = c("l",
> >"p", "b"), legend = TRUE, trace.label =
> > deparse(substitute(trace.factor)),
> >fixed = FALSE, xlab = deparse(substitute(x.factor)), ylab = ylabel,
> >ylim = range(cells, na.rm = TRUE), lty = nc:1, col = 1, pch =  
> > c(1L:9,
> >0, letters), xpd = NULL, leg.bg = par("bg"), leg.bty = "n",
> >xtick = FALSE, xaxt = par("xaxt"), axes = TRUE, ...)
> > {...
> >
> > Copy it into some suitable text editor (not Word please) and change it
> > according to your wish.

Or use `fix()` or `fixInNamespace()` if this is just a one off.

G

> You can do it at the console on both the OS versions of R I have used.  
> just copy the code and paste. Add the "<-" and the ,"o" and hit enter.  
> Piece of cake.
> 
> > I would start with adding "o" to type in function
> > definition and see how it behaves.
> 
> I tested it. Worked as expected.
> 
> > Then you can copy the whole code to
> > your modified function e.g.
> >
> > my.int.plot <- function(x,
> >
> > and call
> > my.int.plot(cyl, gear, mpg, type="o", pch=5:8, lty=1 )
> >
> > Regards
> > Petr
> >
> >
> >>
> >> Thanks
> >> Claudio
> >>
> >> On Thu, Sep 29, 2011 at 9:00 PM, David Winsemius
> > wrote:
> >>
> >>>
> >>> On Sep 29, 2011, at 7:22 PM, Heverkuhn Heverkuhn wrote:
> >>>
> >>> Hello,
>  I was wondering if there is any equivalent of interaction.plot  
>  that allow
>  you to set type="o"
>  I tried to use interaction.plot and I have a gap between the  
>  symbols of
>  the points and the line.
> 
> 
> >>> If it's OK to have the lines going right though the symbols, then  
> >>> go ahead,
> >>> hack the code. All you need to do is add ,"o" to the type  
> >>> arguments in the
> >>> argument list. The code's not hidden or anything that gets in your  
> >>> way.
> >>>
> >>>
> >>> David Winsemius, MD
> >>> West Hartford, CT
> >>>
> >>>
> 
> David Winsemius, MD
> West Hartford, CT
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

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


Re: [R] extracting p-values in scientific notation

2011-10-03 Thread Erich Neuwirth
format.pval is documented and accessible from outside of base.
So you do not have to qualify it as base::format.pval

On 10/3/2011 11:24 AM, Liviu Andronic wrote:
> Thanks all for your pointers. The following does trick:
>> base::format.pval(x$p.value)  ##Hmisc also has such a function
> [1] "<2e-16"
> 
> 
> On Mon, Oct 3, 2011 at 10:25 AM, Rolf Turner  wrote:
>> Isn't it true that 0 < 2.2e-16?
>>
> 
> Yes, but it doesn't mean that the p-value actually hits absolute zero.
> And cor.test, as Ted noticed, returns
>> identical(x$p.value, 0)
> [1] TRUE
> 
> Not that this makes a great practical difference in my case, but I
> would still prefer to print "<2e-16" in my Sweave document.
> 
> Regards
> Liviu
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] New random number generator (RNG)

2011-10-03 Thread Ben Bolker
dataguru  gmail.com> writes:

> Based on very fast converging series for special transcendental
> numbers. Is there some R code available?
> 
> See details about the RNG at
> http://www.analyticbridge.com/profiles/blogs/new-state-of-the-art-
> random-number-generator-simple-strong-and-fa

  (Broken URL above to make Gmane happy.)

  This article seems to be about attempting to get better *cryptographic*
number generators.  This is not a very new idea ...

http://mathoverflow.net/questions/26942/is-pi-a-good-random-number-generator

  It could be a fun project, but I doubt it's better for practical
purposes than the well-tested existing RNG algorithms described in
?RNGkind ... 

  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] Unable to load local library via GUI

2011-10-03 Thread Ben Bolker
Noel Faux  unimelb.edu.au> writes:

> 
> Hi all,
> 
> Not sure if this is the best list, please point me to a more appropriate list
if necessary.
> 
> Running Mac OSX 10.7.1
> R version 2.13.1 Patched (2011-08-14 r56741)
> Copyright (C) 2011 The R Foundation for Statistical Computing
> ISBN 3-900051-07-0
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)


> However, when using the R64.app and try and load the [package]
>  within the GUI I am getting the following error:

> Error in dyn.load(file, DLLpath = DLLpath, ...) : 
>   unable to load shared object [snip]
> 
> dlopen([snip]): Library not loaded: libRblas.dylib
>   Referenced from:
/Library/Frameworks/R.framework/Versions/2.13/[...]/libmlalgs.so
>   Reason: image not found
> Error in library(libmlalgs) : .First.lib failed for 'libmlalgs'
> 
> I know the libmlalgs.so is in the right place and the permissions look OK:
> -rwxr-xr-x  1 root  admin  58384  3 Oct 14:30 libmlalgs.so
> 
> So I am stumped as to why the GUI is unable to read the file.
> Any pointers would very welcome. As I am a textmate user and it
> passes the code to the R64.app, I currently stuck with either
> command line or Rstudio (it's nice but is currently missing some key
> features textmate has)


 [snip snip snip]

  I'm not sure of the answer, but there has been a lot of discussion
of similar issues (showing up as problems loading libRblas.dylib) on
the R-sig-mac [r-sig-...@r-project.org] mailing list.  I would search
through the archives there and then ask on that list if you can't find
a suitable answer.

  Ben Bolker

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


[R] survexp with large dataframes

2011-10-03 Thread Terry Therneau
I've re-looked at survexp with the question of efficiency.  As it
stands, the code will have 3-4 (I think it's 4) active copies of the X
matrix at one point; this is likely the reason it takes so much memory
when you have a large data set.
  Some of this is history; key parts of the code were written long
before I understood all the "tricks" for smaller memory in S (Splus or
R), 1 copy is the loss of the COPY= argument when going from Splus to R.

 I can see how to redo it and reduce to 1 copy, but this involves 3 R
functions and 3 C routines.  I'll add it to my list but don't expect
quick results due to a long list in front of it.  It's been a good
summer, but as one of my colleagues put it "No vacation goes
unpunished."

As a mid term suggestion I would use a subsample of your data. With the
data set sizes you describe a 20% subsample will give all the precision
that you need.  Specifically:
   1. Save the results of your current Cox model, call it fit1
   2. Select a subset.
   3. Fit a new Cox model on the subset, with the options
  iter=0, init=fit1$coef
This ensures that the subset has exactly the same coefficients as the
original.
   4. Use survexp on the subset fit.

Terry Therneau

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 run Bibtex with pdfLatex in StatEt/MikTex on Windows ?

2011-10-03 Thread syrvn
Hello,

I have exactly the same problem that bibtex is not being called and so the
bibliography is not being processed...

Did you find any solution for that?

Many thanks
syrvn

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-run-Bibtex-with-pdfLatex-in-StatEt-MikTex-on-Windows-tp2271396p3867625.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] Sorting data in R according to the header of another table

2011-10-03 Thread Samir Benzerfa
Hi everyone,

 

My (simplified) problem is the following one: I have two tables. The first
table contains 5 columns with 5 values and the second table contains a
single value for each vector name of the first table (see tables below):

 

Table 1:

 

A B C D E

1 2 3 4 5

2 3 4 5 6

3 4 5 6 7

4 5 6 7 8

5 6 7 8 9

 

 

Table 2:

 

A B C D E

3 5 2 1 4

 

My goal is to first sort the values of Table 2 and then use the new header
of it to sort the columns of Table 1 according to that. I already sorted
Table 2 by using the sort(Table2) function getting the following result:

 

D C A E B

1 2 3 4 5

 

How can I now sort the columns in Table 1 according to the header of the new
sorted Table 2. That is, have column D in the first position of Table 1,
column C in the second, and forth.

 

Many thanks for your assistance!

S.B.

 


[[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 format Rsuperscript 2 followed by = value

2011-10-03 Thread sina.r
Hi Nevil,

the function bquote() should do what you want:
(found here: http://r.789695.n4.nabble.com/expression-td904189.html)

mtext(bquote(R^2==.(round(summary(mylm)$r.squared,3))),1)

Regards,
Sina Rüeger

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-format-Rsuperscript-2-followed-by-value-tp3866771p3867093.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] Assigning factor names to interaction plot

2011-10-03 Thread flokke
Hi everyone,
I have the following problem: 

I have three variables, 'group', 'city' and 'pressure'

There is an interaction effect between group and city and I'd like to show
this in an interaction plot:

interaction.plot(group, city, pressure, type="b", 
 col= c(1:2), 
 leg.bty="o", leg.bg="blue", lwd=1, pch=c(18,24,22), 
 xlab="Group", 
 ylab="Pressure", 
 main="Interaction Plot")

My problem is that I cant find a proper argument to pass factor names to the
variables 'group' and 'city'.

In the interaction plot now the groups are referred to as '1', '2' and '3'
and the citys are referred to '1', 2'. Hoewever, Id like to pass 
string character names to those ('Therapy 1, 'therapy 2 and therapy 3). I'd
also like to pass 
string character names to the varibale 'city' ('Amsterdam', "Rotterdam',
etc.)

I'm a quite new user (since two weeks), and normally I can easily find the
solution to my problems on 
the internet, but however this time I'm frustrated because I cant find
solutions that are helping me. 

I'd be very glad if you could give me a hint or could show me how to deal
with this problem.

Cheers,
Maria

--
View this message in context: 
http://r.789695.n4.nabble.com/Assigning-factor-names-to-interaction-plot-tp3867311p3867311.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] stl-decomposition with missing season

2011-10-03 Thread Martin B.

Dear all,

I have a time series with a frequency of 10 days (so 36 yearly). one year is
completely NA. Now I want to do a stl-decomposition, but using e.g.
na.action= na.approx makes no sense for a whole year, of course. Is there a
way of simulating this single year or to just make stl not using this year
for the decomposition?

--
View this message in context: 
http://r.789695.n4.nabble.com/stl-decomposition-with-missing-season-tp3867618p3867618.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] How to run Bibtex with pdfLatex in StatEt/MikTex on Windows ?

2011-10-03 Thread Duncan Murdoch

On 03/10/2011 10:12 AM, syrvn wrote:

Hello,

I have exactly the same problem that bibtex is not being called and so the
bibliography is not being processed...

Did you find any solution for that?



That sounds like a StatET question.  You should get bibtex if you run R 
CMD texi2dvi --pdf (or R CMD texi2pdf in the upcoming R 2.14).


But you can always just run bibtex manually...

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] Best method to add unit information to dataframe ?

2011-10-03 Thread bruno Piguet
Dear all,

  I'd like to have a dataframe store information about the units of
the data it contains.

  You'll find below a minimal exemple of the way I do, so far. I add a
"units" attribute to the dataframe. But  I dont' like the long syntax
needed to access to the unit of a given variable (namely, something
like :
   var_unit <- attr(my_frame, "units")[[match(var_name, attr(my_frame,
"names"))]]

  Can anybody point me to a better solution ?

Thanks in advance,

Bruno.


# Dataframe creation
x <- c(1:10)
y <- c(11:20)
z <- c(101:110)
my_frame <- data.frame(x, y, z)
attr(my_frame, "units") <- c("x_unit", "y_unit")

#
# later on, using dataframe
for (var_name in c("x", "y")) {
   idx <- match(var_name, attr(my_frame, "names"))
   var_unit <- attr(my_frame, "units")[[idx]]
   print (paste("max ", var_name, ": ", max(my_frame[[var_name]]), var_unit))
}

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


[R] Matrix/Vector manipulation

2011-10-03 Thread fernando.cabrera
Hi guys,

Have the following problem computing vectors with pure vector algebra and end 
up reverting to recursion or for-looping. 

Function my_cumsum calculates a weighted average (W) of ratios (R), but only up 
to the given size/volume (v). Now I recurse into the vector (from left to 
right) with what you have left from the difference of volume minus current 
weight, and stop when the difference is less than or equal to the current 
weight. 

Vectors W and R have the same length, and v is always a positive integer.

W: {w_1 w_2 .. w_m}
R: {r_1 r_2 .. r_m}

my_cumsum <- function(v, R, W) {
if (v <= W[1]) # check the head
v*R[1]
else
W[1]*R[1] + my_cumsum(v - W[1], R[2:length(R)], W[2:length(W)]) 
# recurse the tail
}

Any help is greatly appreciated!

Fernando Alvarez

"Great ideas originate in the muscles." ~ Thomas A. Edison

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


Re: [R] Keep ALL duplicate records

2011-10-03 Thread Erik Svensson
It worked, thank you Jim
Erik

--
View this message in context: 
http://r.789695.n4.nabble.com/Keep-ALL-duplicate-records-tp3865136p3867709.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] Find all duplicate records

2011-10-03 Thread Erik Svensson
It works, thanks a lot Gabor
Erik

--
View this message in context: 
http://r.789695.n4.nabble.com/Find-all-duplicate-records-tp3865139p3867724.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] Best method to add unit information to dataframe ?

2011-10-03 Thread Marc Schwartz

On Oct 3, 2011, at 9:35 AM, bruno Piguet wrote:

> Dear all,
> 
>  I'd like to have a dataframe store information about the units of
> the data it contains.
> 
>  You'll find below a minimal exemple of the way I do, so far. I add a
> "units" attribute to the dataframe. But  I dont' like the long syntax
> needed to access to the unit of a given variable (namely, something
> like :
>   var_unit <- attr(my_frame, "units")[[match(var_name, attr(my_frame,
> "names"))]]
> 
>  Can anybody point me to a better solution ?
> 
> Thanks in advance,
> 
> Bruno.
> 
> 
> # Dataframe creation
> x <- c(1:10)
> y <- c(11:20)
> z <- c(101:110)
> my_frame <- data.frame(x, y, z)
> attr(my_frame, "units") <- c("x_unit", "y_unit")
> 
> #
> # later on, using dataframe
> for (var_name in c("x", "y")) {
>   idx <- match(var_name, attr(my_frame, "names"))
>   var_unit <- attr(my_frame, "units")[[idx]]
>   print (paste("max ", var_name, ": ", max(my_frame[[var_name]]), var_unit))
> }

The problem is that there are operations on data frames (e.g. subset()) that 
will end up stripping your attributes. 

> str(my_frame)
'data.frame':   10 obs. of  3 variables:
 $ x: int  1 2 3 4 5 6 7 8 9 10
 $ y: int  11 12 13 14 15 16 17 18 19 20
 $ z: int  101 102 103 104 105 106 107 108 109 110
 - attr(*, "units")= chr  "x_unit" "y_unit"

newDF <- subset(my_frame, x <= 5)

> str(newDF)
'data.frame':   5 obs. of  3 variables:
 $ x: int  1 2 3 4 5
 $ y: int  11 12 13 14 15
 $ z: int  101 102 103 104 105


You might want to look at either ?comment or the ?label function in Frank's 
Hmisc package on CRAN, either to use or for example code on how he handles this.

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] Sorting data in R according to the header of another table

2011-10-03 Thread R. Michael Weylandt
Try this:

X = 1:5; names(X) = letters[sample(5)]
Y = matrix(1:25, 5); colnames(Y) = letters[1:5]

Y[ , names(X)]

Hope this helps,

Michael Weylandt

On Oct 3, 2011, at 6:20 AM, "Samir Benzerfa"  wrote:

> Hi everyone,
> 
> 
> 
> My (simplified) problem is the following one: I have two tables. The first
> table contains 5 columns with 5 values and the second table contains a
> single value for each vector name of the first table (see tables below):
> 
> 
> 
> Table 1:
> 
> 
> 
> A B C D E
> 
> 1 2 3 4 5
> 
> 2 3 4 5 6
> 
> 3 4 5 6 7
> 
> 4 5 6 7 8
> 
> 5 6 7 8 9
> 
> 
> 
> 
> 
> Table 2:
> 
> 
> 
> A B C D E
> 
> 3 5 2 1 4
> 
> 
> 
> My goal is to first sort the values of Table 2 and then use the new header
> of it to sort the columns of Table 1 according to that. I already sorted
> Table 2 by using the sort(Table2) function getting the following result:
> 
> 
> 
> D C A E B
> 
> 1 2 3 4 5
> 
> 
> 
> How can I now sort the columns in Table 1 according to the header of the new
> sorted Table 2. That is, have column D in the first position of Table 1,
> column C in the second, and forth.
> 
> 
> 
> Many thanks for your assistance!
> 
> S.B.
> 
> 
> 
> 
>[[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] difference between createPartition and createfold functions

2011-10-03 Thread bby2103

Hi Max,

Thanks for the note. In your last paragraph, did you mean "in  
createDataPartition"? I'm a little vague about what returnTrain option  
does.


Bonnie

Quoting Max Kuhn :


Basically, createDataPartition is used when you need to make one or
more simple two-way splits of your data. For example, if you want to
make a training and test set and keep your classes balanced, this is
what you could use. It can also make multiple splits of this kind (or
leave-group-out CV aka Monte Carlos CV aka repeated training test
splits).

createFolds is exclusively for k-fold CV. Their usage is simular when
you use the returnTrain = TRUE option in createFolds.

Max

On Sun, Oct 2, 2011 at 4:00 PM, Steve Lianoglou
 wrote:

Hi,

On Sun, Oct 2, 2011 at 3:54 PM,   wrote:

Hi Steve,

Thanks for the note. I did try the example and the result didn't make sense
to me. For splitting a vector, what you describe is a big difference btw
them. For splitting a dataframe, I now wonder if these 2 functions are the
wrong choices. They seem to split the columns, at least in the few things I
tried.


Sorry, I'm a bit confused now as to what you are after.

You don't pass in a data.frame into any of the
createFolds/DataPartition functions from the caret package.

You pass in a *vector* of labels, and these functions tells you which
indices into the vector to use as examples to hold out (or keep
(depending on the value you pass in for the `returnTrain` argument))
between each fold/partition of your learning scenario (eg. cross
validation with createFolds).

You would then use these indices to keep (remove) the rows of a
data.frame, if that is how you are storing your examples.

Does that make sense?

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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





--

Max




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


Re: [R] Best method to add unit information to dataframe ?

2011-10-03 Thread Joshua Wiley
Hi Bruno,

It sounds like what you want is really a separate class, one that has
stores information about units for each variable.  This is far from an
elegant example, but depending on your situation may be useful.  I
create a new class inheriting from the data frame class.  This is
likely fraught with problems because a formal S4 class is inheriting
from an informal S3.  Then a data frame can be stored in the .Data
slot (special---I did not make it), but character data can also be
stored in the units slot (which I did define).  You could get fancier
imposing constraints that the length of units be equal to the number
of columns in the data frame or the like.  S3 methods for data frames
should still mostly work, but you also have the ability to access the
new units slot.  You could define special S4 methods to do the
extraction then, if you wanted, so that your ultimate syntax to get
the units of a particular variable would be shorter.

setOldClass("data.frame")

setClass("mydf", representation(units = "character"),
  contains = "data.frame", S3methods = TRUE)

tmp <- new("mydf")

tmp@.Data <- mtcars
tmp@row.names <- rownames(mtcars)
tmp@units <- c("x", "y")

## data frameish
colMeans(tmp)
tmp + 10

# but
tmp@units

Cheers,

Josh

N.B. I've read once and skimmeda gain Chambers' book, but I still do
not have a solid grasp on S4 so I may have made some fundamental
blunder in the example.



On Mon, Oct 3, 2011 at 7:35 AM, bruno Piguet  wrote:
> Dear all,
>
>  I'd like to have a dataframe store information about the units of
> the data it contains.
>
>  You'll find below a minimal exemple of the way I do, so far. I add a
> "units" attribute to the dataframe. But  I dont' like the long syntax
> needed to access to the unit of a given variable (namely, something
> like :
>   var_unit <- attr(my_frame, "units")[[match(var_name, attr(my_frame,
> "names"))]]
>
>  Can anybody point me to a better solution ?
>
> Thanks in advance,
>
> Bruno.
>
>
> # Dataframe creation
> x <- c(1:10)
> y <- c(11:20)
> z <- c(101:110)
> my_frame <- data.frame(x, y, z)
> attr(my_frame, "units") <- c("x_unit", "y_unit")
>
> #
> # later on, using dataframe
> for (var_name in c("x", "y")) {
>   idx <- match(var_name, attr(my_frame, "names"))
>   var_unit <- attr(my_frame, "units")[[idx]]
>   print (paste("max ", var_name, ": ", max(my_frame[[var_name]]), var_unit))
> }
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://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] difference between createPartition and createfold functions

2011-10-03 Thread Max Kuhn
No, it is an argument to createFolds. Type ?createFolds to see the
appropriate syntax: "returnTrain a logical. When true, the values
returned are the sample positions corresponding to the data used
during training. This argument only works in conjunction with list =
TRUE"

On Mon, Oct 3, 2011 at 11:10 AM,   wrote:
> Hi Max,
>
> Thanks for the note. In your last paragraph, did you mean "in
> createDataPartition"? I'm a little vague about what returnTrain option does.
>
> Bonnie
>
> Quoting Max Kuhn :
>
>> Basically, createDataPartition is used when you need to make one or
>> more simple two-way splits of your data. For example, if you want to
>> make a training and test set and keep your classes balanced, this is
>> what you could use. It can also make multiple splits of this kind (or
>> leave-group-out CV aka Monte Carlos CV aka repeated training test
>> splits).
>>
>> createFolds is exclusively for k-fold CV. Their usage is simular when
>> you use the returnTrain = TRUE option in createFolds.
>>
>> Max
>>
>> On Sun, Oct 2, 2011 at 4:00 PM, Steve Lianoglou
>>  wrote:
>>>
>>> Hi,
>>>
>>> On Sun, Oct 2, 2011 at 3:54 PM,   wrote:

 Hi Steve,

 Thanks for the note. I did try the example and the result didn't make
 sense
 to me. For splitting a vector, what you describe is a big difference btw
 them. For splitting a dataframe, I now wonder if these 2 functions are
 the
 wrong choices. They seem to split the columns, at least in the few
 things I
 tried.
>>>
>>> Sorry, I'm a bit confused now as to what you are after.
>>>
>>> You don't pass in a data.frame into any of the
>>> createFolds/DataPartition functions from the caret package.
>>>
>>> You pass in a *vector* of labels, and these functions tells you which
>>> indices into the vector to use as examples to hold out (or keep
>>> (depending on the value you pass in for the `returnTrain` argument))
>>> between each fold/partition of your learning scenario (eg. cross
>>> validation with createFolds).
>>>
>>> You would then use these indices to keep (remove) the rows of a
>>> data.frame, if that is how you are storing your examples.
>>>
>>> Does that make sense?
>>>
>>> -steve
>>>
>>> --
>>> Steve Lianoglou
>>> Graduate Student: Computational Systems Biology
>>>  | Memorial Sloan-Kettering Cancer Center
>>>  | Weill Medical College of Cornell University
>>> Contact Info: http://cbio.mskcc.org/~lianos/contact
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>>
>> --
>>
>> Max
>>
>>
>
>
>



-- 

Max

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


Re: [R] Matrix/Vector manipulation

2011-10-03 Thread David Reiner
sum(ifelse(cumsum(W)<=v, W, 0) * R)

HTH,
David L. Reiner


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of fernando.cabr...@nordea.com
Sent: Monday, October 03, 2011 9:50 AM
To: r-help@r-project.org
Subject: [SPAM] - [R] Matrix/Vector manipulation - Bayesian Filter detected spam

Hi guys,

Have the following problem computing vectors with pure vector algebra and end 
up reverting to recursion or for-looping.

Function my_cumsum calculates a weighted average (W) of ratios (R), but only up 
to the given size/volume (v). Now I recurse into the vector (from left to 
right) with what you have left from the difference of volume minus current 
weight, and stop when the difference is less than or equal to the current 
weight.

Vectors W and R have the same length, and v is always a positive integer.

W: {w_1 w_2 .. w_m}
R: {r_1 r_2 .. r_m}

my_cumsum <- function(v, R, W) {
if (v <= W[1]) # check the head
v*R[1]
else
W[1]*R[1] + my_cumsum(v - W[1], R[2:length(R)], W[2:length(W)]) 
# recurse the tail }

Any help is greatly appreciated!

Fernando Alvarez

"Great ideas originate in the muscles." ~ Thomas A. Edison

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


This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, "XR Content") are confidential 
and proprietary to XR Trading, LLC ("XR") and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 get old packages to work on R 2.12.1

2011-10-03 Thread Joseph Boyer
That works great. Thanks, Rich.

From: Richard M. Heiberger [mailto:r...@temple.edu]
Sent: Wednesday, September 28, 2011 1:13 PM
To: Joseph Boyer
Cc: r-help@r-project.org
Subject: Re: [R] how to get old packages to work on R 2.12.1

Joe,

Most firewall issues can be resolved by entering


setInternet2(use = TRUE)


prior to the update.packges call.

Rich

On Wed, Sep 28, 2011 at 11:23 AM, Joseph Boyer 
mailto:joseph.g.bo...@gsk.com>> wrote:
Many thanks for all the suggestions.

For me, the update.packages command will not work behind the firewall at my 
workplace.

But the respondents have given me more than enough suggestions to work with.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Best method to add unit information to dataframe ?

2011-10-03 Thread Bert Gunter
Alternatively,  you can make a separate S3 class for a data frame with this
attribute -- and then have appropriate, print, plot, etc. methods that
access it. That way, your messy syntax has to be written only once in the
method functions.

-- Bert

On Mon, Oct 3, 2011 at 8:15 AM, Joshua Wiley  wrote:

> Hi Bruno,
>
> It sounds like what you want is really a separate class, one that has
> stores information about units for each variable.  This is far from an
> elegant example, but depending on your situation may be useful.  I
> create a new class inheriting from the data frame class.  This is
> likely fraught with problems because a formal S4 class is inheriting
> from an informal S3.  Then a data frame can be stored in the .Data
> slot (special---I did not make it), but character data can also be
> stored in the units slot (which I did define).  You could get fancier
> imposing constraints that the length of units be equal to the number
> of columns in the data frame or the like.  S3 methods for data frames
> should still mostly work, but you also have the ability to access the
> new units slot.  You could define special S4 methods to do the
> extraction then, if you wanted, so that your ultimate syntax to get
> the units of a particular variable would be shorter.
>
> setOldClass("data.frame")
>
> setClass("mydf", representation(units = "character"),
>  contains = "data.frame", S3methods = TRUE)
>
> tmp <- new("mydf")
>
> tmp@.Data <- mtcars
> tmp@row.names <- rownames(mtcars)
> tmp@units <- c("x", "y")
>
> ## data frameish
> colMeans(tmp)
> tmp + 10
>
> # but
> tmp@units
>
> Cheers,
>
> Josh
>
> N.B. I've read once and skimmeda gain Chambers' book, but I still do
> not have a solid grasp on S4 so I may have made some fundamental
> blunder in the example.
>
>
>
> On Mon, Oct 3, 2011 at 7:35 AM, bruno Piguet 
> wrote:
> > Dear all,
> >
> >  I'd like to have a dataframe store information about the units of
> > the data it contains.
> >
> >  You'll find below a minimal exemple of the way I do, so far. I add a
> > "units" attribute to the dataframe. But  I dont' like the long syntax
> > needed to access to the unit of a given variable (namely, something
> > like :
> >   var_unit <- attr(my_frame, "units")[[match(var_name, attr(my_frame,
> > "names"))]]
> >
> >  Can anybody point me to a better solution ?
> >
> > Thanks in advance,
> >
> > Bruno.
> >
> >
> > # Dataframe creation
> > x <- c(1:10)
> > y <- c(11:20)
> > z <- c(101:110)
> > my_frame <- data.frame(x, y, z)
> > attr(my_frame, "units") <- c("x_unit", "y_unit")
> >
> > #
> > # later on, using dataframe
> > for (var_name in c("x", "y")) {
> >   idx <- match(var_name, attr(my_frame, "names"))
> >   var_unit <- attr(my_frame, "units")[[idx]]
> >   print (paste("max ", var_name, ": ", max(my_frame[[var_name]]),
> var_unit))
> > }
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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
> Programmer Analyst II, ATS Statistical Consulting Group
> University of California, Los Angeles
> https://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.
>



-- 
"Men by nature long to get on to the ultimate truths, and will often be
impatient with elementary studies or fight shy of them. If it were possible
to reach the ultimate truths without the elementary studies usually prefixed
to them, these would not be preparatory studies but superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics
467-7374
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

[[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] getting list of data.frame names

2011-10-03 Thread David Reiner
I know you already got a good answer from Joshua Wiley.
Here is a function I find useful.
Anyone who wants to suggest improvements, please do so!

> my.ls
function(pos=1, sorted=FALSE, mode, class){
   .result <- sapply(ls(pos=pos, all.names=TRUE),
   function(..x)object.size(eval(as.symbol(..x
   if (sorted){
   .result <- rev(sort(.result))
   }
   .ls <- as.data.frame(rbind(as.matrix(.result),"**Total"=sum(.result)))
   names(.ls) <- "Size"
   .ls$Size <- formatC(.ls$Size, big.mark=',', digits=0, format='f')
   .ls$Mode <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
   function(x)base::mode(eval(as.symbol(x), '---')
   if (!missing(mode)) {
  .ls <- .ls[sapply(.ls$Mode, function(x) any(unlist(strsplit(x, ", "))  
%in% mode)), , drop=FALSE]
   }
   .ls$Class <- c(sapply(rownames(.ls)[-nrow(.ls)],
   function(x) paste(unlist(base::class(eval(as.symbol(x, collapse=", 
")), '---')
   if (!missing(class)) {
  .ls <- .ls[sapply(.ls$Class, function(x) any(unlist(strsplit(x, ", "))  
%in% class)), , drop=FALSE]
   }
   .ls
}

So:
> my.ls(class='data.frame')
 Size Mode  Class
df  1,320 list data.frame
DF648 list data.frame
DF2   712 list data.frame
geu1   72,864 list data.frame
result  1,384 list data.frame
t 896 list data.frame

HTH,
-- David L. Reiner


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Erin Hodgess
Sent: Saturday, October 01, 2011 10:38 PM
To: R help
Subject: [R] getting list of data.frame names

Dear R People:

This is probably a very simple question.  I know that if I want to get a list 
of the classes of the objects in the workspace, I can do this:

> sapply(ls(), function(x)class(get(x)))
   aa1.dfbd
  "list" "data.frame""integer""numeric"

Now I want to get just the data frames.
> sapply(ls(), function(x)class(get(x))=="data.frame")
a a1.df b d
FALSE  TRUE FALSE FALSE

However, I would like the names of the data frames, rather than the True/False 
for the objects.

I've been trying all sorts of combinations/permutations with no success.

Any suggestions would be much appreciated.

Thanks,
Sincerely,
Erin



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

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


This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, "XR Content") are confidential 
and proprietary to XR Trading, LLC ("XR") and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

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


Re: [R] Assigning factor names to interaction plot

2011-10-03 Thread Dennis Murphy
Hi:

A small toy example:

fakedata <- data.frame(group = factor(rep(1:3, each = 10), labels =
paste('Therapy', 1:3)),
  city = factor(rep(c('Amsterdam', 'Rotterdam'), each = 5)),
 pressure = rnorm(30))
with(fakedata, interaction.plot(group, city, pressure, type="b",
 col= c(1:2),
 leg.bty="o", leg.bg="skyblue", lwd=1, pch=c(18,24,22),
 xlab="Group",
 ylab="Pressure",
 main="Interaction Plot")
)

HTH,
Dennis

On Mon, Oct 3, 2011 at 5:11 AM, flokke  wrote:
> Hi everyone,
> I have the following problem:
>
> I have three variables, 'group', 'city' and 'pressure'
>
> There is an interaction effect between group and city and I'd like to show
> this in an interaction plot:
>
> interaction.plot(group, city, pressure, type="b",
>                 col= c(1:2),
>                 leg.bty="o", leg.bg="blue", lwd=1, pch=c(18,24,22),
>                 xlab="Group",
>                 ylab="Pressure",
>                 main="Interaction Plot")
>
> My problem is that I cant find a proper argument to pass factor names to the
> variables 'group' and 'city'.
>
> In the interaction plot now the groups are referred to as '1', '2' and '3'
> and the citys are referred to '1', 2'. Hoewever, Id like to pass
> string character names to those ('Therapy 1, 'therapy 2 and therapy 3). I'd
> also like to pass
> string character names to the varibale 'city' ('Amsterdam', "Rotterdam',
> etc.)
>
> I'm a quite new user (since two weeks), and normally I can easily find the
> solution to my problems on
> the internet, but however this time I'm frustrated because I cant find
> solutions that are helping me.
>
> I'd be very glad if you could give me a hint or could show me how to deal
> with this problem.
>
> Cheers,
> Maria
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Assigning-factor-names-to-interaction-plot-tp3867311p3867311.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] Best method to add unit information to dataframe ?

2011-10-03 Thread Steve Lianoglou
Hi,

If you want to take advantage of Josh's example below (using an S4
subclass of data.frame), perhaps you might be interested in taking
advantage of the multitude of useful objects/classes defined in the
bioconductor IRanges package:

http://www.bioconductor.org/packages/release/bioc/html/IRanges.html

It has no other bioconductor dependencies, so it's a "slim" install,
in that respect. It defines a DataFrame class which keeps "metadata"
around with as you subset/index/etc. it, eg:

R> library(IRanges)
R> DF <- DataFrame(a=1:10, b=letters[1:10])
R> metadata(DF) <- list(units=list(a=NA, b='inches'))

R> sub.1 <- subset(DF, a %% 2 == 0)
R> sub.1
DataFrame with 5 rows and 2 columns
  a   b
   
1 2   b
2 4   d
3 6   f
4 8   h
510   j

R> metadata(sub.1)
$units
$units$a
[1] NA

$units$b
[1] "inches"

(although I noticed that transform,DataFrame isn't defined actually ...)

Anyway, HTH.

-steve

On Mon, Oct 3, 2011 at 11:15 AM, Joshua Wiley  wrote:
> Hi Bruno,
>
> It sounds like what you want is really a separate class, one that has
> stores information about units for each variable.  This is far from an
> elegant example, but depending on your situation may be useful.  I
> create a new class inheriting from the data frame class.  This is
> likely fraught with problems because a formal S4 class is inheriting
> from an informal S3.  Then a data frame can be stored in the .Data
> slot (special---I did not make it), but character data can also be
> stored in the units slot (which I did define).  You could get fancier
> imposing constraints that the length of units be equal to the number
> of columns in the data frame or the like.  S3 methods for data frames
> should still mostly work, but you also have the ability to access the
> new units slot.  You could define special S4 methods to do the
> extraction then, if you wanted, so that your ultimate syntax to get
> the units of a particular variable would be shorter.
>
> setOldClass("data.frame")
>
> setClass("mydf", representation(units = "character"),
>  contains = "data.frame", S3methods = TRUE)
>
> tmp <- new("mydf")
>
> tmp@.Data <- mtcars
> tmp@row.names <- rownames(mtcars)
> tmp@units <- c("x", "y")
>
> ## data frameish
> colMeans(tmp)
> tmp + 10
>
> # but
> tmp@units
>
> Cheers,
>
> Josh
>
> N.B. I've read once and skimmeda gain Chambers' book, but I still do
> not have a solid grasp on S4 so I may have made some fundamental
> blunder in the example.
>
>
>
> On Mon, Oct 3, 2011 at 7:35 AM, bruno Piguet  wrote:
>> Dear all,
>>
>>  I'd like to have a dataframe store information about the units of
>> the data it contains.
>>
>>  You'll find below a minimal exemple of the way I do, so far. I add a
>> "units" attribute to the dataframe. But  I dont' like the long syntax
>> needed to access to the unit of a given variable (namely, something
>> like :
>>   var_unit <- attr(my_frame, "units")[[match(var_name, attr(my_frame,
>> "names"))]]
>>
>>  Can anybody point me to a better solution ?
>>
>> Thanks in advance,
>>
>> Bruno.
>>
>>
>> # Dataframe creation
>> x <- c(1:10)
>> y <- c(11:20)
>> z <- c(101:110)
>> my_frame <- data.frame(x, y, z)
>> attr(my_frame, "units") <- c("x_unit", "y_unit")
>>
>> #
>> # later on, using dataframe
>> for (var_name in c("x", "y")) {
>>   idx <- match(var_name, attr(my_frame, "names"))
>>   var_unit <- attr(my_frame, "units")[[idx]]
>>   print (paste("max ", var_name, ": ", max(my_frame[[var_name]]), var_unit))
>> }
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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
> Programmer Analyst II, ATS Statistical Consulting Group
> University of California, Los Angeles
> https://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.
>



-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 run Bibtex with pdfLatex in StatEt/MikTex on Windows ?

2011-10-03 Thread syrvn
Hi Duncan,

you were right. texi2dvi does latex + bibtex. Unfortunately I cannot get it
running.

When I run texi2dvi(file = "path/to/tex/file", pdf=TRUE, quiet=FALSE) then I
get the following error message:

___
Error in texi2dvi(file = "/Users/XXX/Desktop/test/body.tex", texinputs =
"/Library/Frameworks/R.framework/Resources/share/texmf/tex/latex/tex",  : 
  Running 'texi2dvi' on '/Users/XXX/Desktop/test/body.tex' failed.
Output:
You don't have a working TeX binary (tex) installed anywhere in
your PATH, and texi2dvi cannot proceed without one.  If you want to use
this script, you'll need to install TeX (if you don't have it) or change
your PATH or TEX environment variable (if you do).  See the --help
output for more details.

For information about obtaining TeX, please see http://www.tug.org.  If
you happen to be using Debian, you can get it with this command:
  apt-get install tetex-bin
__


So the output tells us it cannot find a a tex binary file. If I open my
terminal and type in:

/Library/Frameworks/R.framework/Resources/share/texmf/tex/latex/tex

I get the following output:

This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011)
**

which means the tex binary is there.


--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-run-Bibtex-with-pdfLatex-in-StatEt-MikTex-on-Windows-tp2271396p3868063.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] Best method to add unit information to dataframe ?

2011-10-03 Thread Gabor Grothendieck
On Mon, Oct 3, 2011 at 10:35 AM, bruno Piguet  wrote:
> Dear all,
>
>  I'd like to have a dataframe store information about the units of
> the data it contains.
>
>  You'll find below a minimal exemple of the way I do, so far. I add a
> "units" attribute to the dataframe. But  I dont' like the long syntax
> needed to access to the unit of a given variable (namely, something
> like :
>   var_unit <- attr(my_frame, "units")[[match(var_name, attr(my_frame,
> "names"))]]
>
>  Can anybody point me to a better solution ?
>
> Thanks in advance,
>
> Bruno.
>
>
> # Dataframe creation
> x <- c(1:10)
> y <- c(11:20)
> z <- c(101:110)
> my_frame <- data.frame(x, y, z)
> attr(my_frame, "units") <- c("x_unit", "y_unit")
>
> #
> # later on, using dataframe
> for (var_name in c("x", "y")) {
>   idx <- match(var_name, attr(my_frame, "names"))
>   var_unit <- attr(my_frame, "units")[[idx]]
>   print (paste("max ", var_name, ": ", max(my_frame[[var_name]]), var_unit))
> }

The Hmisc package has some support for this:

library(Hmisc)

DF <- data.frame(x, y, z)
units(DF$x) <- "my x units"
units(DF$y) <- "my y units"

units(DF$x)


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


[R] intensity map / plot

2011-10-03 Thread Martin Batholdy
Dear R-list,


I would like to generate an intensity map based on a x * y matrix.

Each point in the matrix should get plotted at the coordinate: x = column / y = 
row with 
a color-intensity (for example gray-value) based on the actual value of this 
point.

Is there a convenient package / function for this kind of plot?



example data:
x <- matrix(rnorm(100*100, 0, 2), 100, 100)


thanks!

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


Re: [R] How to run Bibtex with pdfLatex in StatEt/MikTex on Windows ?

2011-10-03 Thread syrvn
I am a bit confused...

I wrote a little shell script called tex2pdf which just calls: texi2pdf
body.tex and when I execute it
in a terminal it runs smoothly. If I type into R: system("/Path/to/tex2pdf")
I get the same error message:


You don't have a working TeX binary (tex) installed anywhere in
your PATH, and texi2dvi cannot proceed without one.  If you want to use
this script, you'll need to install TeX (if you don't have it) or change
your PATH or TEX environment variable (if you do).  See the --help
output for more details.

For information about obtaining TeX, please see http://www.tug.org.  If
you happen to be using Debian, you can get it with this command:
  apt-get install tetex-bin


How can this happen? I originally thought it's a problem with the texi2dvi
function in R but it seems to be something else...

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-run-Bibtex-with-pdfLatex-in-StatEt-MikTex-on-Windows-tp2271396p3868123.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] intensity map / plot

2011-10-03 Thread Uwe Ligges

See ?image

Uwe Ligges


On 03.10.2011 19:05, Martin Batholdy wrote:

Dear R-list,


I would like to generate an intensity map based on a x * y matrix.

Each point in the matrix should get plotted at the coordinate: x = column / y = 
row with
a color-intensity (for example gray-value) based on the actual value of this 
point.

Is there a convenient package / function for this kind of plot?



example data:
x<- matrix(rnorm(100*100, 0, 2), 100, 100)


thanks!

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


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


Re: [R] about the array transpose

2011-10-03 Thread Uwe Ligges



On 03.10.2011 03:29, venerealdisease wrote:

Hi, all,

I am a newbie for [R]
Would anyone help me how to transpose a 3x3x3 array for 1:27

Eg.
A<-array(1:27, c(3,3,3)

What is the logic to transpose it to B<-aperm(A, c(3,2,1))


It simply says third dimension first, second second, and first third.

Uwe Ligges




Because I found I could not imagine how it transposes, anyone could solve my
problem?
And most important I could get the number what I expected, I think if I
could not figure it out, I will have a confused concept which will affect my
future learning of 3D models in [R].

Highly appreciated and thanks.

VD







--
View this message in context: 
http://r.789695.n4.nabble.com/about-the-array-transpose-tp3866241p3866241.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] rolling regression

2011-10-03 Thread R. Michael Weylandt
It seems you don't really know how predict works. If you don't supply
new data, it will only return the least squares fit to the old data,
which is the large data block you saw. Check the first example given
in ?predict to see how this works for new (out of sample) data.

More importantly, use of lm() gives a model for contemporaneous
fitting of your data to cash_ret. You probably need to use a time
series model that has forecasting built into it (unless you can
somehow your independent variables before your dependent variables)

Michael Weylandt

On Sun, Oct 2, 2011 at 11:41 PM, Darius H  wrote:
>
> Dear all,
>
> I have spent the last few days on a seemingly simple and previously 
> documented rolling regression.
>
> I have a 60 year data set organized in a ts matrix.
> The matrix has 5 columns; cash_ret, epy1, ism1, spread1, unemp1
>
> I have been able to come up with the following based on previous help 
> threads. It seems to work fine.
> The trouble is I get regression coefficients but need the immediate next 
> period forecast.
>
> cash_fit= rollapply(cash_data, width=60,
>
> function(x) coef(lm(cash_ret~epy1+ism1+spread1+unemp1, data = 
> as.data.frame(x))),
>
> by.column=FALSE, align="right"); cash_fit
>
>
> I tried to replace "coef" above to "predict" but I get a whole bunch of 
> results too big to be displayed. I would be grateful
> if someone could guide me on how to get the next period forecast after each 
> regression.
>
> If there is a possibility of getting the significance of each regressor and 
> the standard error in addition to R-sq
> without having to spend the next week, that would be helpful as well.
>
> Many thanks,
> Darius
>
>
>
>
>
>        [[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] about the array transpose

2011-10-03 Thread R. Michael Weylandt
Mr. Disease,

As Uwe points out, the syntax is pretty clear, but it is perhaps worth
mulling over why:

R> identical(A[,,1], t(B[1,,]))
TRUE

to confirm that you understand the function.

Michael Weylandt

PS -- Might I suggest, if you insist on anonymity, a different handle?
I'm answering on my lunch break and I'm finding that you are providing
me with all sorts of icky mental images...

2011/10/3 Uwe Ligges :
>
>
> On 03.10.2011 03:29, venerealdisease wrote:
>>
>> Hi, all,
>>
>> I am a newbie for [R]
>> Would anyone help me how to transpose a 3x3x3 array for 1:27
>>
>> Eg.
>> A<-array(1:27, c(3,3,3)
>>
>> What is the logic to transpose it to B<-aperm(A, c(3,2,1))
>
> It simply says third dimension first, second second, and first third.
>
> Uwe Ligges
>
>
>>
>> Because I found I could not imagine how it transposes, anyone could solve
>> my
>> problem?
>> And most important I could get the number what I expected, I think if I
>> could not figure it out, I will have a confused concept which will affect
>> my
>> future learning of 3D models in [R].
>>
>> Highly appreciated and thanks.
>>
>> VD
>>
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/about-the-array-transpose-tp3866241p3866241.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


[R] Question about ggplot2 and stat_smooth

2011-10-03 Thread Thomas Adams

 I'm interested in creating a graphic -like- this:

c <- ggplot(mtcars, aes(qsec, wt))
c + geom_point() + stat_smooth(fill="blue", colour="darkblue", size=2, 
alpha = 0.2)


but I need to show 2 sets of bands (with different shading) using 5%, 
25%, 75%, 95% limits that I specify and where the heavy blue line is the 
median. I don't understand how to do this with ggplot2. What I am doing 
currently is to generate 'boxplots' (with 5%, 25%, 75%, 95% limits) at 
6-hourly time steps (so I have a series of boxplots, which you can see 
by clicking on a map point: 
http://www.erh.noaa.gov/mmefs/index_test.php?Lat=38.2&Lon=-80.1&Zoom=5&Refresh=0&RFCOverlay=0&Model=NAEFS). 
Some who use our graphics would like to see something more like the 
ggplot2 with stat_smooth graphic.


Help is much appreciated.

Regards,
Tom

--
Thomas E Adams
National Weather Service
Ohio River Forecast Center
1901 South State Route 134
Wilmington, OH 45177

EMAIL:  thomas.ad...@noaa.gov

VOICE:  937-383-0528
FAX:937-383-0033

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


Re: [R] generating Venn diagram with 6 sets

2011-10-03 Thread peter dalgaard

On Oct 2, 2011, at 18:25 , Mao Jianfeng wrote:

> But, vennerable can not be installed on my Mac book.

Works for me. What are the symptoms?

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

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


Re: [R] How to run Bibtex with pdfLatex in StatEt/MikTex on Windows ?

2011-10-03 Thread syrvn
Hi,

I know now why it did not work. See here:

http://www.mail-archive.com/r-help@r-project.org/msg19682.html

I started R via the terminal with open -a R and then called the script again
as well as the texi2dvi function.
Both worked. The problem now is I use R within Eclipse and I don't know how
to start R in that way so that
the paths are set correct.


--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-run-Bibtex-with-pdfLatex-in-StatEt-MikTex-on-Windows-tp2271396p3868226.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 about ggplot2 and stat_smooth

2011-10-03 Thread Dennis Murphy
Hi:

I would think that, at least in principle, this should work:

a <- ggplot(mtcars, aes(qsec, wt))
a + geom_point() + stat_smooth(fill="blue", colour="darkblue", size=2,
level = 0.9, alpha = 0.2) +
   stat_smooth(fill = 'blue', colour = 'darkblue', size = 2,
   level = 0.5, alpha = 0.4)

but geom_smooth() doesn't seem to react to different values of level.
I get the same bands on geom_smooth() if I use level = 0.95, 0.75 or
0.5. Since I make it a policy not to invoke the B word, I'll let
others who know more about the code comment on it.

BTW, ggplot2 related questions tend to get faster responses on its
list: ggpl...@googlegroups.com. I've taken the liberty of forwarding
there since most of the developers read that list more regularly than
R-help.

Dennis

On Mon, Oct 3, 2011 at 10:24 AM, Thomas Adams  wrote:
>  I'm interested in creating a graphic -like- this:
>
> c <- ggplot(mtcars, aes(qsec, wt))
> c + geom_point() + stat_smooth(fill="blue", colour="darkblue", size=2, alpha
> = 0.2)
>
> but I need to show 2 sets of bands (with different shading) using 5%, 25%,
> 75%, 95% limits that I specify and where the heavy blue line is the median.
> I don't understand how to do this with ggplot2. What I am doing currently is
> to generate 'boxplots' (with 5%, 25%, 75%, 95% limits) at 6-hourly time
> steps (so I have a series of boxplots, which you can see by clicking on a
> map point:
> http://www.erh.noaa.gov/mmefs/index_test.php?Lat=38.2&Lon=-80.1&Zoom=5&Refresh=0&RFCOverlay=0&Model=NAEFS).
> Some who use our graphics would like to see something more like the ggplot2
> with stat_smooth graphic.
>
> Help is much appreciated.
>
> Regards,
> Tom
>
> --
> Thomas E Adams
> National Weather Service
> Ohio River Forecast Center
> 1901 South State Route 134
> Wilmington, OH 45177
>
> EMAIL:  thomas.ad...@noaa.gov
>
> VOICE:  937-383-0528
> FAX:    937-383-0033
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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 run Bibtex with pdfLatex in StatEt/MikTex on Windows ?

2011-10-03 Thread Duncan Murdoch
Your subject line says Windows, but your error message suggests MacOS.  
I think you need to post questions that are answerable if you want an 
answer.


Duncan Murdoch

On 03/10/2011 12:48 PM, syrvn wrote:

Hi Duncan,

you were right. texi2dvi does latex + bibtex. Unfortunately I cannot get it
running.

When I run texi2dvi(file = "path/to/tex/file", pdf=TRUE, quiet=FALSE) then I
get the following error message:

___
Error in texi2dvi(file = "/Users/XXX/Desktop/test/body.tex", texinputs =
"/Library/Frameworks/R.framework/Resources/share/texmf/tex/latex/tex",  :
   Running 'texi2dvi' on '/Users/XXX/Desktop/test/body.tex' failed.
Output:
You don't have a working TeX binary (tex) installed anywhere in
your PATH, and texi2dvi cannot proceed without one.  If you want to use
this script, you'll need to install TeX (if you don't have it) or change
your PATH or TEX environment variable (if you do).  See the --help
output for more details.

For information about obtaining TeX, please see http://www.tug.org.  If
you happen to be using Debian, you can get it with this command:
   apt-get install tetex-bin
__


So the output tells us it cannot find a a tex binary file. If I open my
terminal and type in:

/Library/Frameworks/R.framework/Resources/share/texmf/tex/latex/tex

I get the following output:

This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011)
**

which means the tex binary is there.


--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-run-Bibtex-with-pdfLatex-in-StatEt-MikTex-on-Windows-tp2271396p3868063.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] distance coefficient for amatrix with ngative valus

2011-10-03 Thread dilshan benaragama
Hi,
I need to run a PCoA (PCO) for a data set wich has both positive and negative 
values for variables. I  could not find any distancecoefficient other than 
euclidean distace running for the data set. Are there any other coefficient 
works with negtive values.Also I cannot get summary out put (the eigen values) 
for PCO as for PCA.
 
Thanks.
Dilshan
[[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] xts/time-series and plot questions...

2011-10-03 Thread Douglas Philips
Hello,
  I'm a complete newbie to R. Spent this past weekend reading The Art of R 
Programming, The R Cookbook, the language spec, Wikis and FAQs. I sort-of have 
my head around R; the dizzying selection of libraries, packages, etc? Not 
really. I've probably missed or failed to understand something... 

  I have very a simple data set. Two years (ish) of temperature data, collected 
and time-stamped every 10 minutes. Sample of the data from read.csv(...):

> head(temp.data)
DateTime Temperature
1 2009-11-23 23:20:0062.9
2 2009-11-23 23:30:0063.4
3 2009-11-23 23:40:0063.6
4 2009-11-23 23:50:0064.2
5 2009-11-24 00:00:0064.5
6 2009-11-24 00:10:0064.7

Converted to an xts object:
> str(temp_data)
xts [1:83089, 1] 62.9 63.4 63.6 64.2 64.5 64.7 65.2 65.3 65.8 65.6 ...
- attr(*, "index")= atomic [1:83089] 1.26e+09 1.26e+09 1.26e+09 1.26e+09 
1.26e+09 ...
 ..- attr(*, "tzone")= chr ""
 ..- attr(*, "tclass")= chr [1:2] "POSIXct" "POSIXt"
- attr(*, "class")= chr [1:2] "xts" "zoo"
- attr(*, ".indexCLASS")= chr [1:2] "POSIXct" "POSIXt"
- attr(*, ".indexTZ")= chr ""


So far so good! I can do all kinds of cool things like plot individual months: 
plot(temp_data["2009-12"]) and plot monthly, weekly, daily mean, sd, etc. (I 
have to say, xts has been a dream to work with!)

What I would like to do is plot several sections of this data on the same graph.
Specifically, I would like to plot all the data from one calendar month, 
regardless of year, on one plot.
i.e. one line for  Jan 2009, another line for Jan 2010, anothe line for Jan 
2011, etc.

I can use xts functions to slice the data into months (or weeks, or days), but 
I am not sure how to arrange to get the X-axis to work right. If I do:
   plot(temp_data["2010-01"]); lines(temp_data("2011-01"))
lines aren't overlayed; the output from lines() is lost because it is far off 
of the right of the plot as the plot autoranged() the x and y axes. But I don't 
think xlim is my problem so much as I need a way to 'slide' 
temp_data["2011-01"] so that it will appear in the same part of the graph/plot 
as the 2010-01 data does.

What I think I want to do is write a "normalizing" function that takes data for 
any given month and makes it "year-free"??? This way I could plot corresponding 
months on the same graph. One month, or a quarter, or even a full year. I don't 
know, however, how to convince xts to ignore the year, or if there is an xts 
compatible object that is year-free (or month-free for looking at week/day 
segements)...

Pointers to online answers, google search terms, etc. greatly appreciated!

Thanks,
  -=Doug

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Compact letter display for interaction effects

2011-10-03 Thread Josh Caplan

Hello,

I am interested in generating a compact letter display for the results 
of Tukey HSD tests that contain interaction effects. The 'cld' method in 
the 'multcomp' package seems only to work for main effects. Does such a 
thing exist already? Thank you for any thoughts,


Josh

--
Joshua Caplan, PhD
Postdoctoral Associate
Department of Ecology, Evolution, and Natural Resources
Rutgers University
14 College Farm Rd, New Brunswick, NJ 08901
p 732-932-9383   f 732-932-8746
jcap...@aesop.rutgers.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] minimisation problem, two setups (nonlinear with equality constraints/linear programming with mixed constraints)

2011-10-03 Thread Liu Evans, Gareth
Dear All,

Thank you for the replies to my first thread here: 
http://r.789695.n4.nabble.com/global-optimisation-with-inequality-constraints-td3799258.html.
  So far the best result is achieved via a penalised objective function.  This 
was suggested by someone on this list privately.  I am still looking into some 
of the options mentioned in the original thread, but I have been advised that 
there may be better ways if I present the actual problem with a reproducible 
example.

In principle the problem can be solved by linear programming, so I include code 
for my attempt at this via RGLPK.  It says that there is no feasible solution, 
but the solution is known analytically in the case below.

Here is the precise problem:

Minimise, over 100×1 real vectors v,
Max_i(|v_i|) such that X'v=e_2,
where X is a given 100×2 matrix and e_2 =(0,1)'.  The v_i are the elements of v.

I have put the actual X matrix at the end of this post, along with a feasible 
starting value for v.  

The correct minimum is 0.01287957, obtained with v_i=0.01287957 for i<=50 and 
v_i = 0.01287957 for i>=51.  

Here is the code for the penalised objective function approach, adapted very 
slightly from what someone on this list sent me:

..
X <- #  See end of this message for the X data

   x1 <- X[, 1]
   x2 <- X[, 2]
   
  fun <- function(q) {
   mu <- 0.1
   max(abs(v)) + (sum(v*x1)^2 + (1-sum(x2*v))^2)/(2*mu)
   }

vstart <- # feasible starting value.  See end of this post.
sol <- optim(vstart, fun, method="L-BFGS-B", lower=rep(-1, 100), 
upper=rep(1,100))
   
   max(abs(sol$par))
.

This gets quite near, around 0.015-0.016 for me by varying mu.

Alternatively the problem can be set up as a linear programming task as follows:

Minimise, over 100×1 real vectors v, and over scalars q >= 0,

q

such that, for i=1,...,100
v_i<=q
v_i>=-q
X'v=e_2

Here is my RGLPK code:

.
X <- #  See end of this message for the X data
XROWS <- 100
XCOLS <- 2
e_2=rep(0,times=XCOLS)
e2[2]<- 1

obj <- c(rep(0,XROWS),1)  # coefficients on v_1, . . . , v_100, q.
mat <- matrix(rbind(cbind(diag(XROWS), rep(-1,XROWS)), cbind(diag(XROWS), 
rep(1,XROWS)), cbind(t(X), rep(0,XCOLS)), cbind(t(rep(0,XROWS)), 1)), 
nrow=2*XROWS+XCOLS+1) 

dir <- c(rep("<=", XROWS), rep(">=", XROWS), rep("==", XCOLS), ">=")
rhs <- c(rep(0, 2*XROWS), e_2, 0)

sol <- Rglpk_solve_LP(obj, mat, dir, rhs, types = NULL, max = FALSE,
bounds = c(-5,5), verbose = TRUE)
...

The output is 

"
GLPK Simplex Optimizer, v4.42
203 rows, 101 columns, 601 non-zeros
  0: obj =  0.0e+000  infeas = 1.000e+000 (2)
  4: obj =  0.0e+000  infeas = 1.000e+000 (1)
PROBLEM HAS NO FEASIBLE SOLUTION
"

I have also tried setting the problem up with a small interval around the 
equality constraints rather than having strict equalities, but could not get 
the correct solution this way either.  

Maybe I am making an error with RGLPK - I have been told it should work for a 
problem of this size and much larger.  I have also tried DEoptim, IpSolve and 
ConstrOptim.

Regards,
Gareth

...
Values of X and vstart below
...
vstart=

-0.025251183
-0.022301089
-0.020429759
-0.01902228
-0.017877586
-0.016903415
-0.016049376
-0.015284788
-0.014589517
-0.0139496
-0.01335494
-0.012797983
-0.012272922
-0.011775194
-0.011301139
-0.010847778
-0.010412649
-0.009993692
-0.009589163
-0.009197573
-0.00881764
-0.008448248
-0.008088421
-0.007737298
-0.007394116
-0.007058194
-0.006728922
-0.006405748
-0.006088173
-0.005775744
-0.005468043
-0.005164689
-0.00486533
-0.004569638
-0.00427731
-0.003988063
-0.003701629
-0.003417759
-0.003136215
-0.002856772
-0.002579217
-0.002303343
-0.002028954
-0.00175586
-0.001483876
-0.001212825
-0.00094253
-0.00067282
-0.000403526
-0.000134481
0.000134481
0.000403526
0.00067282
0.00094253
0.001212825
0.001483876
0.00175586
0.002028954
0.002303343
0.002579217
0.002856772
0.003136215
0.003417759
0.003701629
0.003988063
0.00427731
0.004569638
0.00486533
0.005164689
0.005468043
0.005775744
0.006088173
0.006405748
0.006728922
0.007058194
0.007394116
0.007737298
0.008088421
0.008448248
0.00881764
0.009197573
0.009589163
0.009993692
0.010412649
0.010847778
0.011301139
0.011775194
0.012272922
0.012797983
0.01335494
0.0139496
0.014589517
0.015284788
0.016049376
0.016903415
0.017877586
0.01902228
0.020429759
0.022301089
0.025251183

.
X=

1   -2.330078923
1   -2.057855981
1   -1.885177032
1   -1.755

[R] Import in R with White Spaces

2011-10-03 Thread francy
Hi,

I have a simple question about importing data, I would be very grateful if
you could help me out.

I have used read.csv(file name, header=T, sep=",") to bring in a csv file I
saved in MS Excel.The problem is I have white spaces in the middle of values
(not in the column names), and this messes up the column entries. Since I
have many many files that I am importing and I have spaces in all of them, I
was looking for a way to avoid going into all of them and changing the white
spaec to, for example, an underscore.
Can you suggest whether there is a way to tell R that each element delimited
by "," is actually a different entry, regardless of whether there are white
spaces in between?

Thank you so much for the help!
-f


--
View this message in context: 
http://r.789695.n4.nabble.com/Import-in-R-with-White-Spaces-tp3867799p3867799.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

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


[R] Meta-analysis of test statistics in "metafor" package?

2011-10-03 Thread davidyeager
Hi -

I am conducting a meta-analysis and I have a matrix of f-statistics, Ns and
dfs from a series of studies that tested for an interaction in a 2x2 anova. 
I'd like to test whether the 2x2 interaction is significant in the
aggregate.  

Similarly, I have a matrix of chi-square statistics that I'd like to
meta-analyze.

How can I input these test statistics into the "metafor" package and conduct
these meta-analyses?  I see how to input raw data or standardizes effect
sizes (e.g., d) into "metafor", but not test statistics.

Best,

David

--
View this message in context: 
http://r.789695.n4.nabble.com/Meta-analysis-of-test-statistics-in-metafor-package-tp3868126p3868126.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] Online Course PLS and R and free, public videos

2011-10-03 Thread Geoffrey Hubona
The Georgia R School (http://georgia-r-school.org) is a non-profit
educational organization.  With faculty from Virginia Commonwealth
University, we are conducting live, interactive, synchronous month-long
online courses on PLS path modeling and R statistical software during
October and November. All  live courses are recorded (all audio and video)
and the permanent recordings are also provided to participants. Registration
fees for a course are $225 student; $295 faculty; $325 practitioner; (less
if still early registration); or $345 student (any two courses, including
future courses); $445 faculty (any two); and $495 practitioner (any two).
Courses open for registration are (all times are Eastern Time):



Fundamentals of Using R: Tues 11AM-2PM Oct 18-Nov 15

Using R for Statistical Research Analysis II: Wed 6PM-9PM Nov 9-Dec 14

Using R for Statistical Research Analysis II: Thurs 11AM-2PM Nov 10-Dec 15

PLS Path Modeling with R: Fridays 11AM-2PM Nov 11-Dec 16



For more info on courses, see http://georgia-r-school.org.

Also, there are dozens of short, open, public videos on PLS and R available
to view (and many more will be added in the weeks ahead) at:

http://georgia-r-school.org/PLS_Videos.html  and

http://georgia-r-school.org/R_Videos.html



Email Geoff Hubona at ghub...@vcu.edu or ge...@georgia-r-school.org for more
info or questions.



Geoff Hubona, Ph.D.

Affiliate Faculty, Information Systems

Virginia Commonwealth 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] file input with readLines

2011-10-03 Thread Cable, Sam B Civ USAF AFMC AFRL/RVBXI
I am using readLines to read a fairly large ASCII file.  readLines reads
a fixed number of lines, then other R code processes the data, then
readLines reads the same number of lines again, then other R code
processes the data, then 

 

Sort of like:

 

conn<-file('filename','r')

for (chunk in 1:10) {

   Lines<-readLines(conn,n=25)

  # process "Lines"

}

 

The code is working, but I notice that it slows down greatly as time
progresses.  It took 2 seconds to read my first chunk of data, 4 seconds
to read the next chunk, 10 after that.  The quasi-exponential trend has
slowed, thank goodness, but after about a hundred reads, the read time
for the next chunk is over a minute.  Let me stress that the number of
lines read in each chunk of data is absolutely fixed.

 

The only processing I am doing at the point is to parse the new data,
and rbind the results to an existing data frame.  Processing of new data
in no way depends on earlier data.

 

So, my question is why is the reading taking longer as time goes on?  Is
there a way to fix this?  Is there a better method than readLines?

 

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.


Re: [R] intensity map / plot

2011-10-03 Thread Martin Batholdy

thanks!


On 03.10.2011, at 19:11, Uwe Ligges wrote:

> See ?image
> 
> Uwe Ligges
> 
> 
> On 03.10.2011 19:05, Martin Batholdy wrote:
>> Dear R-list,
>> 
>> 
>> I would like to generate an intensity map based on a x * y matrix.
>> 
>> Each point in the matrix should get plotted at the coordinate: x = column / 
>> y = row with
>> a color-intensity (for example gray-value) based on the actual value of this 
>> point.
>> 
>> Is there a convenient package / function for this kind of plot?
>> 
>> 
>> 
>> example data:
>> x<- matrix(rnorm(100*100, 0, 2), 100, 100)
>> 
>> 
>> thanks!
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Parsing variable-length delimited strings into a matrix

2011-10-03 Thread Benjamin Wright

I'm struggling to find a way of parsing a vector of data in this sort of form:

A,B,C
B,B
A,AA,C
A,B,BB,BBB,B,B

into a matrix (or data frame). The catch is that I don't know a priori how many 
entries there will be in each element, nor how many characters there will be. 
strsplit(vec,",") gets me a list, but I can't find a way of turning the list 
into a matrix. unlistlst) destroys the length data and do.call("rbind", lst) 
fails because of the uneven lengths. It is possible to go through the vector 
element by element, but that has proved too slow for my purposes.

Is there a reasonably quick method of achieving this in a vector-oriented way?

Cheers,

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] Installation from local Compiled directory

2011-10-03 Thread Sandeep Patil
Hello everyone

I have manually compiled directory of gstat in a particular folder of my
Unix system.
I want to install this and am unable to use either of the following two
commands

1. R CMD INSTALL
2. Install.packages

I do not understand how to coax above commands to locate the directory that
i have
compiled.

Please understand that i have solved a number of related issues concerning
this
installation and it is a special case where

1. I cannot use CRAN mirror to download and install
2. Install from TAR file

Essentially this is the only option i have.

Thank you

Sandeep

[[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] read .csv from web from password protected site

2011-10-03 Thread Mike Pfeiff
I am very new to R and have been struggling trying to read a basic ".csv" file 
from a password protected site with the following code:

myURL  
="http://www.frontierweather.com/degreedays/L15N15PowerRegionAverages_10weeks.txt";
test2=read.table(url(myURL),header=TRUE,sep=",")

A 'data.frame' is returned into the workspace, however it is not the data 
contained in the ".csv" file.   I think this occurs because the website where I 
am trying to retrieve the data is password protected.

Is there a way to specify the username and password?

Any guidance would be greatly appreciated.

Sincerely,

Mike

[[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] Merge two data frames and find common values and non-matching values

2011-10-03 Thread francy
Hi,

I am trying to find a function to match two data frames of different lengths
for one field only.
So, for example,
df1 is:

Name Position location
francesca A 75
cristina B 36

And df2 is:

location Country
75 UK
56 Austria

And I would like to match on "Location" and the output to be something like:

Name Position Location Match
francesca A 75 1
cristina B 36 0

I have tried with the function 'match' or with:
subset(df1, location %in% df2)
But it does not work.

Could you please help me figure out how to do this?

Thank you!
-f


--
View this message in context: 
http://r.789695.n4.nabble.com/Merge-two-data-frames-and-find-common-values-and-non-matching-values-tp3868299p3868299.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

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


Re: [R] file input with readLines

2011-10-03 Thread Cable, Sam B Civ USAF AFMC AFRL/RVBXI
More on my previous question ...

I have put in timing statements to try to get a better idea of where the
problem is, like so:

conn<-file('filename','r')

for (chunk in 1:10) {
   print(paste('begin read at',date()))
   Lines<-readLines(conn,n=25)
   print(paste('begin processing at',date()))
  # process "Lines"
   print(paste('end loop at',date()))
}

Every time I go through the loop, all the date() functions return
*exactly* the same time!  It *looks like* it runs through each iteration
very quickly and then takes longer and longer to simply start the next
iteration.  I don't believe this.  I think R must be doing some kind of
latency trick or something.  But, anyway, the point is that I was
assuming the problem was in the I/O, and now I don't know if it's I/O or
processing.  Either way, I don't understand it and would really
appreciate some wisdom from you guys.

Thanks.

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


Re: [R] Meta-analysis of test statistics in "metafor" package?

2011-10-03 Thread Kevin E. Thorpe

On 10/03/2011 01:07 PM, davidyeager wrote:

Hi -

I am conducting a meta-analysis and I have a matrix of f-statistics, Ns and
dfs from a series of studies that tested for an interaction in a 2x2 anova.
I'd like to test whether the 2x2 interaction is significant in the
aggregate.

Similarly, I have a matrix of chi-square statistics that I'd like to
meta-analyze.

How can I input these test statistics into the "metafor" package and conduct
these meta-analyses?  I see how to input raw data or standardizes effect
sizes (e.g., d) into "metafor", but not test statistics.

Best,

David



I believe the MAd package may have what you are looking for.  It can 
call metafor for you.


Kevin

--
Kevin E. Thorpe
Biostatistician/Trialist,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016

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


Re: [R] generating Venn diagram with 6 sets

2011-10-03 Thread Mao Jianfeng
Dear Peter,

I am glad to hearing your reply. That is really nice. Thanks a lot.


###
# (1) the problem of the plot venneuler generated me is sets (A,B,C,D,E,F)
should shared 69604 elements.
#  But, it illustrated nothing for me for this 6 sets sharing.


> But, vennerable can not be installed on my Mac book.
>
> Works for me. What are the symptoms?
>


##
# (2) I compiled vennerable package, and then installed in my R-2.13.0. But
the plot can only generated 5 sets, and looks not good.

I have not saved the codes I tested. Could you please show me your codes? or
just show me the plot you generated.

Best wishes,

Jian-Feng,




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


-- 
Jian-Feng, Mao

Post doc
Max Planck Institute for Developmental Biology
Dept. of Molecular Biology
Spemannstrasse 37-39
72076 Tuebingen
Germany
Blog: http://maojf.blogspot.com/

[[alternative HTML version deleted]]

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


Re: [R] Merge two data frames and find common values and non-matching values

2011-10-03 Thread William Dunlap
Start out with merge():
  > df <- merge(df1, df2, all.x=TRUE) # could add by="location" for emphasis
  > df
location  Name Position Country
  1   36  cristinaB
  2   75 francescaA  UK
You could make make your 'Match' column from is.na(df$Country) if you 
knew that df2$Country were never NA.  Otherwise you can add a fake
variable to the merge to tell which output rows come from unmatched
rows in the first data.frame:

  > df12 <- merge(df1, cbind(df2, fromDF2=TRUE), all.x=TRUE, by="location")
  > df12$Match <- !is.na(df12$fromDF2)
  > df12
location  Name Position Country fromDF2 Match
  1   36  cristinaB  NA FALSE
  2   75 francescaA  UKTRUE  TRUE

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of francy
> Sent: Monday, October 03, 2011 10:55 AM
> To: r-help@r-project.org
> Subject: [R] Merge two data frames and find common values and non-matching 
> values
> 
> Hi,
> 
> I am trying to find a function to match two data frames of different lengths
> for one field only.
> So, for example,
> df1 is:
> 
> Name Position location
> francesca A 75
> cristina B 36
> 
> And df2 is:
> 
> location Country
> 75 UK
> 56 Austria
> 
> And I would like to match on "Location" and the output to be something like:
> 
> Name Position Location Match
> francesca A 75 1
> cristina B 36 0
> 
> I have tried with the function 'match' or with:
> subset(df1, location %in% df2)
> But it does not work.
> 
> Could you please help me figure out how to do this?
> 
> Thank you!
> -f
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Merge-two-data-frames-and-find-common-
> values-and-non-matching-values-tp3868299p3868299.html
> Sent from the R help mailing list archive at Nabble.com.
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Merge two data frames and find common values and non-matching values

2011-10-03 Thread Sarah Goslee
Hi,


On Mon, Oct 3, 2011 at 1:54 PM, francy  wrote:
> Hi,
>
> I am trying to find a function to match two data frames of different lengths
> for one field only.
> So, for example,
> df1 is:
>
> Name Position location
> francesca A 75
> cristina B 36
>
> And df2 is:
>
> location Country
> 75 UK
> 56 Austria
>
> And I would like to match on "Location" and the output to be something like:


Sounds like you need merge() (just as in your subject line!).

> Name Position Location Match
> francesca A 75 1
> cristina B 36 0
>
> I have tried with the function 'match' or with:
> subset(df1, location %in% df2)
> But it does not work.
>
> Could you please help me figure out how to do this?
>

Sarah

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

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


Re: [R] read .csv from web from password protected site

2011-10-03 Thread Sarah Goslee
Hi Mike,

On Mon, Oct 3, 2011 at 12:31 PM, Mike Pfeiff  wrote:
> I am very new to R and have been struggling trying to read a basic ".csv" 
> file from a password protected site with the following code:
>
> myURL  
> ="http://www.frontierweather.com/degreedays/L15N15PowerRegionAverages_10weeks.txt";
> test2=read.table(url(myURL),header=TRUE,sep=",")


> A 'data.frame' is returned into the workspace, however it is not the data 
> contained in the ".csv" file.   I think this occurs because the website where 
> I am trying to retrieve the data is password protected.
>
> Is there a way to specify the username and password?


I'd try first
read.table("http://userid:passw...@my.url/file.csv";), which is the
standard way to do it (hint: try that form in your web browser and see
whether you can access the data), and if that doesn't work look into
the RCurl package. The list archives have a fair bit of information on
this topic.

Sarah


> Any guidance would be greatly appreciated.
>
> Sincerely,
>
> Mike
>


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

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


Re: [R] Import in R with White Spaces

2011-10-03 Thread Sarah Goslee
Hi,

On Mon, Oct 3, 2011 at 11:14 AM, francy  wrote:
> Hi,
>
> I have a simple question about importing data, I would be very grateful if
> you could help me out.
>
> I have used read.csv(file name, header=T, sep=",") to bring in a csv file I
> saved in MS Excel.The problem is I have white spaces in the middle of values
> (not in the column names), and this messes up the column entries. Since I
> have many many files that I am importing and I have spaces in all of them, I
> was looking for a way to avoid going into all of them and changing the white
> spaec to, for example, an underscore.
> Can you suggest whether there is a way to tell R that each element delimited
> by "," is actually a different entry, regardless of whether there are white
> spaces in between?

Since you're exporting from Excel, make sure that quoting is turned on in
the export options. That way an entire value, including white space, will
be in quotes and thus read as an entire value. That should have been
done by default, and specifying sep as you did should have worked.

So actually, we may need more information beyond what you've provided.

Sarah

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

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


Re: [R] Question about ggplot2 and stat_smooth

2011-10-03 Thread Thomas Adams



Andrés,

Thank you for your help, but that does not capture what I'm looking for. I need 
to be able to control the
shaded bound limits and they need to be coincident.

Tom

On 10/3/11 3:37 PM, Andrés Aragón wrote:

Hi,
Try some like this:

c<- ggplot(mtcars, aes(qsec, mpg, colour=factor(cyl)))
c + stat_smooth(aes(group=cyl))+stat_smooth(aes(fill=factor(cyl)))+geom_point()


Andrés AM



2011/10/3, Thomas Adams:

   I'm interested in creating a graphic -like- this:

c<- ggplot(mtcars, aes(qsec, wt))
c + geom_point() + stat_smooth(fill="blue", colour="darkblue", size=2,
alpha = 0.2)

but I need to show 2 sets of bands (with different shading) using 5%,
25%, 75%, 95% limits that I specify and where the heavy blue line is the
median. I don't understand how to do this with ggplot2. What I am doing
currently is to generate 'boxplots' (with 5%, 25%, 75%, 95% limits) at
6-hourly time steps (so I have a series of boxplots, which you can see
by clicking on a map point:
http://www.erh.noaa.gov/mmefs/index_test.php?Lat=38.2&Lon=-80.1&Zoom=5&Refresh=0&RFCOverlay=0&Model=NAEFS).
Some who use our graphics would like to see something more like the
ggplot2 with stat_smooth graphic.

Help is much appreciated.

Regards,
Tom

--
Thomas E Adams
National Weather Service
Ohio River Forecast Center
1901 South State Route 134
Wilmington, OH 45177

EMAIL:  thomas.ad...@noaa.gov

VOICE:  937-383-0528
FAX:937-383-0033

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




--
Thomas E Adams
National Weather Service
Ohio River Forecast Center
1901 South State Route 134
Wilmington, OH 45177

EMAIL:  thomas.ad...@noaa.gov

VOICE:  937-383-0528
FAX:937-383-0033

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


Re: [R] Compact letter display for interaction effects

2011-10-03 Thread Spencer Graves




library(sos)
cl <- ???'compact letter display'
cl



  This opened a table for me in a web browser identifying 3 help 
pages in 'multcomp' and 1 in 'multcompView' that mention 'compact letter 
display'.  Functions in multcompView will work anything that looks like 
a distance or similarity matrix.  You need to decide what to use so the 
results make sense.



  Hope this helps.
  Spencer


On 10/3/2011 8:09 AM, Josh Caplan wrote:

Hello,

I am interested in generating a compact letter display for the results
of Tukey HSD tests that contain interaction effects. The 'cld' method
in the 'multcomp' package seems only to work for main effects. Does
such a thing exist already? Thank you for any thoughts,

Josh




--
Spencer Graves, PE, PhD
President and Chief Technology Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567
web:  www.structuremonitoring.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] suggestions argument in rbga function in genalg package

2011-10-03 Thread Joseph Boyer
Enrico,

The idea of looking at the code never occurred to me. That's a great idea which 
will come in useful
I'm sure.

In this particular case the using list() or as.matrix() does not solve the 
problem, but
those are both good ideas.

Thanks for the reply.

-Original Message-
From: Enrico Schumann [mailto:enricoschum...@yahoo.de] 
Sent: Friday, September 23, 2011 12:53 AM
To: Joseph Boyer
Cc: r-help@r-project.org
Subject: Re: [R] suggestions argument in rbga function in genalg package


I do not use this package, but a quick look at the code shows this.

if (!is.null(suggestions)) {
# [deleted]
suggestionCount = dim(suggestions)[1]

So 'suggestions' needs to have a dim argument (while the documentation 
speaks of an 'optional list of suggested chromosomes'). You could try

as.matrix(c(1,0.1,10, 100,1,100,1))

But I cannot tell if that solves your problem since you have not 
provided your objective function (ie, you have not provided the 
"commented, minimal, self-contained, reproducible code" that the footer 
of this message speaks about).


Regards,
Enrico

Am 22.09.2011 20:46, schrieb Joseph Boyer:
> Would someone be so kind as to provide example code where they use the 
> suggestions argument in  the rgba function
> In genalg? I can't get it to work.
>
> The following code works just fine:
>
> GenFit<-rbga(Lower, Upper, evalFunc = evaluate)
>
> Lower and Upper are each numeric vectors with 7 elements. Evaluate is an 
> objective function.
> However, when I want to use a suggested chromosome, I get an error message. 
> My code is
>
> start<- c(1,0.1,10, 100,1,100,1)
>
> suggestions<- list(start)
>
> GenFit<-rbga(Lower, Upper, suggestions = suggestions, evalFunc = evaluate)
>
> The error message is:
>
> Error in 1:suggestionCount : argument of length 0
>
> 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.
>

-- 
Enrico Schumann
Lucerne, Switzerland
http://nmof.net/

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


Re: [R] read .csv from web from password protected site

2011-10-03 Thread Sarah Goslee
Hi,

I've assumed that you meant to send this to the R-help list, and not just me.

On Mon, Oct 3, 2011 at 3:54 PM, Mike Pfeiff  wrote:
> Sarah,  Thanks for the suggestion.  Although, 
> read.table("http://userid:passw...@my.url/file.csv";) did not work as it 
> returned the following:
>
>        Error in file(file, "rt") : cannot open the connection
>        In addition: Warning message:
>        In file(file, "rt") : unable to resolve 'userid'
>
> (where 'usesid is my actual userid)
>
> I've tried the following RCurl commands...
>
>        myURL   
> ="http://www.frontierweather.com/degreedays/L15N15PowerRegionAverages_10weeks.txt";
>        h=getURL(myURL, userpw = "userid:passwod", followlocation=TRUE)
>        test=read.table(h,header=TRUE,sep=",")
>
> ..and I can't get the data to read and get the following errors:
>
>        Error in file(file, "rt") : cannot open the connection
>        In addition: Warning message:
>        In file(file, "rt") : unable to resolve 'userid'
>
> I'm at a total loss.  Any assistance anyone could provide would be greatly 
> appreciated.

You can get to the file using your web browser and that
userid/password combo, right?

Do you have to go through a dialog box? Press a button to login? Any
of those have the potential to
complicate the task.

If so, you'll need to work through the Forms section at
http://www.omegahat.org/RCurl/philosophy.html

Sarah

>
>
> -Original Message-
> From: Sarah Goslee [mailto:sarah.gos...@gmail.com]
> Sent: Monday, October 03, 2011 2:26 PM
> To: Mike Pfeiff
> Cc: r-help@r-project.org
> Subject: Re: [R] read .csv from web from password protected site
>
> Hi Mike,
>
> On Mon, Oct 3, 2011 at 12:31 PM, Mike Pfeiff  wrote:
>> I am very new to R and have been struggling trying to read a basic ".csv" 
>> file from a password protected site with the following code:
>>
>> myURL  
>> ="http://www.frontierweather.com/degreedays/L15N15PowerRegionAverages_10weeks.txt";
>> test2=read.table(url(myURL),header=TRUE,sep=",")
>
>
>> A 'data.frame' is returned into the workspace, however it is not the data 
>> contained in the ".csv" file.   I think this occurs because the website 
>> where I am trying to retrieve the data is password protected.
>>
>> Is there a way to specify the username and password?
>
>
> I'd try first
> read.table("http://userid:passw...@my.url/file.csv";), which is the standard 
> way to do it (hint: try that form in your web browser and see whether you can 
> access the data), and if that doesn't work look into the RCurl package. The 
> list archives have a fair bit of information on this topic.
>
> Sarah
>
>
>> Any guidance would be greatly appreciated.
>>
>> Sincerely,
>>
>> Mike
>>
>

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

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


Re: [R] Returning vector of values shared across 3 vectors?

2011-10-03 Thread Brian Diggs

On 10/1/2011 3:03 AM, jim holtman wrote:

try this:


vec1<- 
c(4,5,6,7,8,9,10,11,12,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81)
vec2<- c 
(1,2,3,4,5,6,7,8,9,10,11,12,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66)
vec3<- c (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,52)
  intersect(vec1,intersect(vec2, vec3))

  [1]  4  5  6  7  8  9 10 11 12 52




Or if your real problem may go to more vec's and you don't want to keep 
nesting the calls:


Reduce(intersect, list(vec1, vec2, vec3))
# [1]  4  5  6  7  8  9 10 11 12 52




On Sat, Oct 1, 2011 at 2:00 AM, Chris Conner  wrote:

Help-Rs,

I've got three vectors representing participants:

vec1<- 
c(4,5,6,7,8,9,10,11,12,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81)
vec2<- c 
(1,2,3,4,5,6,7,8,9,10,11,12,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66)
vec3<- c (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,52)

I'd like to return a vector that contains only the values that are shared 
across ALL THREE vectors. So the statement would return a vector that looked 
like this:
4,5,6,7,8,9,10,11,12,52

For some reason I initially thought that a cbind and a unique() would handle 
it, but then common sense sunk in.  I think the sleep deprivation is starting 
to take it's toll.  I've got to believe that there is a simple solution to this 
dilema.

Thanks in adance for any help!
C
[[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.









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

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


Re: [R] file input with readLines

2011-10-03 Thread R. Michael Weylandt
If you are using rbind() at each iteration, that can slow things down
greatly. Look up a document called the R Inferno which discusses this
in great detail in circle 2.

Michael Weylandt

On Mon, Oct 3, 2011 at 2:26 PM, Cable, Sam B Civ USAF AFMC AFRL/RVBXI
 wrote:
> More on my previous question ...
>
> I have put in timing statements to try to get a better idea of where the
> problem is, like so:
>
> conn<-file('filename','r')
>
> for (chunk in 1:10) {
>   print(paste('begin read at',date()))
>   Lines<-readLines(conn,n=25)
>   print(paste('begin processing at',date()))
>  # process "Lines"
>   print(paste('end loop at',date()))
> }
>
> Every time I go through the loop, all the date() functions return
> *exactly* the same time!  It *looks like* it runs through each iteration
> very quickly and then takes longer and longer to simply start the next
> iteration.  I don't believe this.  I think R must be doing some kind of
> latency trick or something.  But, anyway, the point is that I was
> assuming the problem was in the I/O, and now I don't know if it's I/O or
> processing.  Either way, I don't understand it and would really
> appreciate some wisdom from you guys.
>
> Thanks.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Parsing variable-length delimited strings into a matrix

2011-10-03 Thread R. Michael Weylandt
Well how do you want it be made into a matrix if the rows are all
different lengths? Methinks you are finding this tricky for a
reason...

Michael

On Mon, Oct 3, 2011 at 11:40 AM, Benjamin Wright  wrote:
>
> I'm struggling to find a way of parsing a vector of data in this sort of form:
>
> A,B,C
> B,B
> A,AA,C
> A,B,BB,BBB,B,B
>
> into a matrix (or data frame). The catch is that I don't know a priori how 
> many entries there will be in each element, nor how many characters there 
> will be. strsplit(vec,",") gets me a list, but I can't find a way of turning 
> the list into a matrix. unlistlst) destroys the length data and 
> do.call("rbind", lst) fails because of the uneven lengths. It is possible to 
> go through the vector element by element, but that has proved too slow for my 
> purposes.
>
> Is there a reasonably quick method of achieving this in a vector-oriented way?
>
> Cheers,
>
> 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] distance coefficient for amatrix with ngative valus

2011-10-03 Thread R. Michael Weylandt
One order of the usual coming right up!

1 course of "Why does XXX not work for you?" a la francaise, where XXX
is, in your case, the Euclidean distance.  Specifically, any metric
worth its salt (in a normed space) satisfies dist(a,b) = dist(a+c,b+c)
so why are negative values a problem?...

2 sides: a "Minimal Working Example" with a light buttery sauce and a
fried "what package/code are you using"

and, for desert, a Winsemian special of: "read the posting guide!"

Michael Weylandt, who is putting together a menu for a fancy dinner
even as he types

On Mon, Oct 3, 2011 at 12:55 PM, dilshan benaragama
 wrote:
> Hi,
> I need to run a PCoA (PCO) for a data set wich has both positive and negative 
> values for variables. I  could not find any distancecoefficient other than 
> euclidean distace running for the data set. Are there any other coefficient 
> works with negtive values.Also I cannot get summary out put (the eigen 
> values) for PCO as for PCA.
>
> Thanks.
> Dilshan
>        [[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] xts/time-series and plot questions...

2011-10-03 Thread Joshua Ulrich
Hi Doug,

Thanks for taking the time to write a great question.

On Mon, Oct 3, 2011 at 12:23 PM, Douglas Philips  wrote:
> Hello,
>  I'm a complete newbie to R. Spent this past weekend reading The Art of R 
> Programming, The R Cookbook, the language spec, Wikis and FAQs. I sort-of 
> have my head around R; the dizzying selection of libraries, packages, etc? 
> Not really. I've probably missed or failed to understand something...
>
>  I have very a simple data set. Two years (ish) of temperature data, 
> collected and time-stamped every 10 minutes. Sample of the data from 
> read.csv(...):
>
>> head(temp.data)
>            DateTime Temperature
> 1 2009-11-23 23:20:00        62.9
> 2 2009-11-23 23:30:00        63.4
> 3 2009-11-23 23:40:00        63.6
> 4 2009-11-23 23:50:00        64.2
> 5 2009-11-24 00:00:00        64.5
> 6 2009-11-24 00:10:00        64.7
>
> Converted to an xts object:
>> str(temp_data)
> xts [1:83089, 1] 62.9 63.4 63.6 64.2 64.5 64.7 65.2 65.3 65.8 65.6 ...
> - attr(*, "index")= atomic [1:83089] 1.26e+09 1.26e+09 1.26e+09 1.26e+09 
> 1.26e+09 ...
>  ..- attr(*, "tzone")= chr ""
>  ..- attr(*, "tclass")= chr [1:2] "POSIXct" "POSIXt"
> - attr(*, "class")= chr [1:2] "xts" "zoo"
> - attr(*, ".indexCLASS")= chr [1:2] "POSIXct" "POSIXt"
> - attr(*, ".indexTZ")= chr ""
>
>
> So far so good! I can do all kinds of cool things like plot individual 
> months: plot(temp_data["2009-12"]) and plot monthly, weekly, daily mean, sd, 
> etc. (I have to say, xts has been a dream to work with!)
>
> What I would like to do is plot several sections of this data on the same 
> graph.
> Specifically, I would like to plot all the data from one calendar month, 
> regardless of year, on one plot.
> i.e. one line for  Jan 2009, another line for Jan 2010, anothe line for Jan 
> 2011, etc.
>
> I can use xts functions to slice the data into months (or weeks, or days), 
> but I am not sure how to arrange to get the X-axis to work right. If I do:
>   plot(temp_data["2010-01"]); lines(temp_data("2011-01"))
> lines aren't overlayed; the output from lines() is lost because it is far off 
> of the right of the plot as the plot autoranged() the x and y axes. But I 
> don't think xlim is my problem so much as I need a way to 'slide' 
> temp_data["2011-01"] so that it will appear in the same part of the 
> graph/plot as the 2010-01 data does.
>
> What I think I want to do is write a "normalizing" function that takes data 
> for any given month and makes it "year-free"??? This way I could plot 
> corresponding months on the same graph. One month, or a quarter, or even a 
> full year. I don't know, however, how to convince xts to ignore the year, or 
> if there is an xts compatible object that is year-free (or month-free for 
> looking at week/day segements)...
>
xts requires a time-based index, so there's no way to make an index
"year-free".  What you can do, is split the xts object into years,
convert all the index values to have the same year, and merge them
together.

The "toyear" function I've provided below converts the index values to
a specific year.  A "month-free" solution would be similar.  I'd also
recommend using plot.zoo for more complex graphs.

toyear <- function(x, year) {
  # get year of last obs
  xyear <- .indexyear(last(x))+1900
  # get index and convert to POSIXlt
  ind <- as.POSIXlt(index(x))
  # set index year to desired value
  ind$year <- year-1900
  index(x) <- ind
  # label column with year of last obs
  colnames(x) <- paste(colnames(x),xyear,sep=".")
  x
}

# split data into a list of xts objects by year
tmp_dat_yr_list <- split(temp_data, "years")
# convert each list element to be "2011"
tmp_dat_yr_list <- lapply(tmp_dat_yr_list, toyear, 2011)
# merge all list elements into one object
temp_data_by_year <- do.call(merge, tmp_dat_yr_list)
# plot.zoo has more features than plot.xts at the moment
plot.zoo(temp_data_by_year, screens=1,
  col=rainbow(ncol(temp_data_by_year)))

> Pointers to online answers, google search terms, etc. greatly appreciated!
>
> Thanks,
>  -=Doug
>

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.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] new standardised variable based on group membership

2011-10-03 Thread John.Morrongiello
That works a treat Thierry, thanks! I wasn't aware of the plyr package but I 
like what it does- I'll put it to use work in the future.

Regards

John 

-Original Message-
From: ONKELINX, Thierry [mailto:thierry.onkel...@inbo.be] 
Sent: Monday, 3 October 2011 6:36 PM
To: Morrongiello, John (CMAR, Hobart); r-help@r-project.org
Subject: RE: [R] new standardised variable based on group membership

Dear John,

You need to combine scale with a grouping function.

data(Orange)
library(plyr)
Orange <- ddply(Orange, .(Tree), function(x){
x$ddplyAge <- scale(x$age)[, 1]
x
})

Orange$aveAge <- ave(Orange$age, by = Orange$Tree, FUN = scale)

all.equal(Orange$ddplyAge, Orange$aveAge)

Best regards,

Thierry


> -Oorspronkelijk bericht-
> Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> Namens john.morrongie...@csiro.au
> Verzonden: maandag 3 oktober 2011 7:34
> Aan: r-help@r-project.org
> Onderwerp: [R] new standardised variable based on group membership
> 
> Hi
> I have a data comprised of repeated measures of growth (5-15 records per
> individual) for 580 fish (similar to Orange dataset from nlme library). I 
> would like
> to standardise these growth measures (yi – ŷ/sd) using mean and standard
> deviation unique to each fish. Can someone suggest a function that would help
> me do this? I’ve had a look at scale and sweep but can’t find a worked example
> that does what I’m after
> 
> Cheers
> 
> John
> 
> 
>   [[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] new standardised variable based on group membership

2011-10-03 Thread baptiste auguie
More concisely,

ddply(Orange, .(Tree), transform, scaled = scale(age))

HTH,

baptiste

On 4 October 2011 11:24,   wrote:
> That works a treat Thierry, thanks! I wasn't aware of the plyr package but I 
> like what it does- I'll put it to use work in the future.
>
> Regards
>
> John
>
> -Original Message-
> From: ONKELINX, Thierry [mailto:thierry.onkel...@inbo.be]
> Sent: Monday, 3 October 2011 6:36 PM
> To: Morrongiello, John (CMAR, Hobart); r-help@r-project.org
> Subject: RE: [R] new standardised variable based on group membership
>
> Dear John,
>
> You need to combine scale with a grouping function.
>
> data(Orange)
> library(plyr)
> Orange <- ddply(Orange, .(Tree), function(x){
>        x$ddplyAge <- scale(x$age)[, 1]
>        x
> })
>
> Orange$aveAge <- ave(Orange$age, by = Orange$Tree, FUN = scale)
>
> all.equal(Orange$ddplyAge, Orange$aveAge)
>
> Best regards,
>
> Thierry
>
>
>> -Oorspronkelijk bericht-
>> Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
>> Namens john.morrongie...@csiro.au
>> Verzonden: maandag 3 oktober 2011 7:34
>> Aan: r-help@r-project.org
>> Onderwerp: [R] new standardised variable based on group membership
>>
>> Hi
>> I have a data comprised of repeated measures of growth (5-15 records per
>> individual) for 580 fish (similar to Orange dataset from nlme library). I 
>> would like
>> to standardise these growth measures (yi – ŷ/sd) using mean and standard
>> deviation unique to each fish. Can someone suggest a function that would help
>> me do this? I’ve had a look at scale and sweep but can’t find a worked 
>> example
>> that does what I’m after
>>
>> Cheers
>>
>> John
>>
>>
>>       [[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] new standardised variable based on group membership

2011-10-03 Thread John.Morrongiello
I like that one too Baptiste, thanks

-Original Message-
From: baptiste auguie [mailto:baptiste.aug...@googlemail.com] 
Sent: Tuesday, 4 October 2011 9:56 AM
To: Morrongiello, John (CMAR, Hobart)
Cc: thierry.onkel...@inbo.be; r-help@r-project.org
Subject: Re: [R] new standardised variable based on group membership

More concisely,

ddply(Orange, .(Tree), transform, scaled = scale(age))

HTH,

baptiste

On 4 October 2011 11:24,   wrote:
> That works a treat Thierry, thanks! I wasn't aware of the plyr package but I 
> like what it does- I'll put it to use work in the future.
>
> Regards
>
> John
>
> -Original Message-
> From: ONKELINX, Thierry [mailto:thierry.onkel...@inbo.be]
> Sent: Monday, 3 October 2011 6:36 PM
> To: Morrongiello, John (CMAR, Hobart); r-help@r-project.org
> Subject: RE: [R] new standardised variable based on group membership
>
> Dear John,
>
> You need to combine scale with a grouping function.
>
> data(Orange)
> library(plyr)
> Orange <- ddply(Orange, .(Tree), function(x){
>        x$ddplyAge <- scale(x$age)[, 1]
>        x
> })
>
> Orange$aveAge <- ave(Orange$age, by = Orange$Tree, FUN = scale)
>
> all.equal(Orange$ddplyAge, Orange$aveAge)
>
> Best regards,
>
> Thierry
>
>
>> -Oorspronkelijk bericht-
>> Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
>> Namens john.morrongie...@csiro.au
>> Verzonden: maandag 3 oktober 2011 7:34
>> Aan: r-help@r-project.org
>> Onderwerp: [R] new standardised variable based on group membership
>>
>> Hi
>> I have a data comprised of repeated measures of growth (5-15 records per
>> individual) for 580 fish (similar to Orange dataset from nlme library). I 
>> would like
>> to standardise these growth measures (yi – ŷ/sd) using mean and standard
>> deviation unique to each fish. Can someone suggest a function that would help
>> me do this? I’ve had a look at scale and sweep but can’t find a worked 
>> example
>> that does what I’m after
>>
>> Cheers
>>
>> John
>>
>>
>>       [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] a question about sort and BH

2011-10-03 Thread chunjiang he
Hi,

I have two questions want to ask.

1. If I have a matrix like this, and I want to figure out the rows whose
value in the 3rd column are less than 0.05. How can I do it with R.
hsa-let-7a--MBTD10.5282391972.41E-05
hsa-let-7a--APOBEC10.5078694095.51E-05
hsa-let-7a--PAPOLA0.4704518840.000221774
hsa-let-7a--NF20.4692801860.000231065
hsa-let-7a--SLC17A50.4545979780.000381713
hsa-let-7a--THOC20.4477140540.000479322
hsa-let-7a--SMG70.4449722820.000524129

2. I got the p.adjust.R from R source. In the method "BH", I am not clear
with the code:
   i <- lp:1L
   o <- order(p, decreasing = TRUE)
   ro <- order(o)
   pmin(1, cummin( n / i * p[o] ))[ro]

How to explain the first and the fourth row.
p.adjust.R===
p.adjust.methods <-
c("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none")
p.adjust <- function(p, method = p.adjust.methods, n = length(p))
{
## Methods 'Hommel', 'BH', 'BY' and speed improvements contributed by
## Gordon Smyth .
method <- match.arg(method)
if(method == "fdr") method <- "BH" # back compatibility
nm <- names(p)
p <- as.numeric(p); names(p) <- nm
p0 <- p
if(all(nna <- !is.na(p))) nna <- TRUE
p <- p[nna]
lp <- length(p)
stopifnot(n >= lp)
if (n <= 1) return(p0)
if (n == 2 && method == "hommel") method <- "hochberg"
p0[nna] <-
 switch(method,
bonferroni = pmin(1, n * p),
holm = {
 i <- seq_len(lp)
 o <- order(p)
 ro <- order(o)
 pmin(1, cummax( (n - i + 1L) * p[o] ))[ro]
},
hommel = { ## needs n-1 >= 2 in for() below
 if(n > lp) p <- c(p, rep.int(1, n-lp))
 i <- seq_len(n)
 o <- order(p)
 p <- p[o]
 ro <- order(o)
 q <- pa <- rep.int( min(n*p/i), n)
 for (j in (n-1):2) {
 ij <- seq_len(n-j+1)
 i2 <- (n-j+2):n
 q1 <- min(j*p[i2]/(2:j))
 q[ij] <- pmin(j*p[ij], q1)
 q[i2] <- q[n-j+1]
 pa <- pmax(pa,q)
 }
 pmax(pa,p)[if(lp < n) ro[1:lp] else ro]
},
hochberg = {
 i <- lp:1L
 o <- order(p, decreasing = TRUE)
 ro <- order(o)
 pmin(1, cummin( (n - i + 1L) * p[o] ))[ro]
},
BH = {
 i <- lp:1L
 o <- order(p, decreasing = TRUE)
 ro <- order(o)
 pmin(1, cummin( n / i * p[o] ))[ro]
},
BY = {
 i <- lp:1L
 o <- order(p, decreasing = TRUE)
 ro <- order(o)
 q <- sum(1L/(1L:n))
 pmin(1, cummin(q * n / i * p[o]))[ro]
},
none = p)
p0
}



I wrote a code to do my work in BH correction like the following:

rm(list=ls())
a<-read.csv("test.txt",sep="\t",header=F,quote="")
b<-a[order(a[,3],decreasing=TRUE),]
c<-p.adjust(b[,3],method="BH")
b[,4]<-c
write.table(b,"zz.txt",sep="\t")

Is that right? Thanks for all.

Jiang

[[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] Hi

2011-10-03 Thread chunjiang he
thanks

On Fri, Sep 30, 2011 at 5:25 PM, Francois Pepin <
francois.pe...@sequentainc.com> wrote:

> Hi Jiang,
>
> where did you get that definition of the Benjamini-Hochberg correction?
> That is simply not how it works. You can take a look at the original paper,
> it is available online (
> http://www.math.tau.ac.il/~ybenja/MyPapers/benjamini_hochberg1995.pdf).
> You can also look at the p.adjust function to see how it is implemented in
> R.
>
> Also, please keep the replies on the list. They're archived so that other
> people can refer to it later it also gives other people the opportunity to
> reply if they have more to add.
>
> Francois
>
> On Sep 30, 2011, at 15:07 , chunjiang he wrote:
>
> > Hi Francois,
> >
> > Thansk for your reply. I did BH correction manually. Just use corrected
> pvalue=pvalue*(n/n-1). And I got the result like this: The pvalue in manual
> and by R package are different.
> >
> > title r   raw R package   manual
> > hsa-miR-205--GATA30.7978831.08E-131.08E-12
>  1.08E-12
> > hsa-miR-205--ITGB40.7502181.85E-118.20E-11
>  9.25E-11
> > hsa-miR-187--PGF  0.7976043.24E-118.20E-11
>  1.08E-10
> > hsa-miR-205--SERPINB5 0.7441253.28E-118.20E-11
>  8.20E-11
> > hsa-miR-205--PBX1 0.7344877.89E-111.58E-10
>  1.58E-10
> > hsa-miR-205--MCC  0.7249991.80E-103.00E-10
>  3.00E-10
> > hsa-miR-205--WNT5B0.7177053.33E-103.78E-10
>  4.76E-10
> > hsa-miR-200c--PKN20.7217473.46E-103.78E-10
>  4.33E-10
> > hsa-miR-200c--PCYOX1  0.7216983.48E-103.78E-10
>  3.87E-10
> > hsa-miR-200c--WDR68   0.72068 3.78E-103.78E-103.78E-10
> >
> > So I am confused about that.
> >
> > Best,
> > Jiang
> > On Fri, Sep 30, 2011 at 4:53 PM, Francois Pepin <
> francois.pe...@sequentainc.com> wrote:
> > Hi Jiang,
> >
> > you'll have to give us some more information than this: a reproducible
> example and why you expect things to be different.
> >
> > This method has been tested extensively so we'd need something more
> specific if we are to help you.
> >
> > Francois
> >
> > On Sep 30, 2011, at 14:40 , chunjiang he wrote:
> >
> > > Hi,
> > >
> > > There is a question that I am confused.
> > > I have a set of data like this:
> > >
> > > hsa-miR-205--GATA30.797882767 1.08E-13
> > > hsa-miR-205--ITGB4 0.750217593 1.85E-11
> > > hsa-miR-187--PGF0.797604155 3.24E-11
> > > hsa-miR-205--SERPINB5 0.744124886 3.28E-11
> > > hsa-miR-205--PBX1 0.734487224 7.89E-11
> > > hsa-miR-205--MCC 0.72499934 1.80E-10
> > > hsa-miR-205--WNT5B 0.717705259 3.33E-10
> > > hsa-miR-200c--PKN2 0.721746815 3.46E-10
> > > hsa-miR-200c--PCYOX1 0.721698034 3.48E-10
> > > hsa-miR-200c--WDR68 0.72068017 3.78E-10
> > >
> > > And I want to do the Benjamini & Hochberg correction.
> > >
> > > So I run :
> > >
> > > rm(list=ls())
> > > a<-read.csv("1-correlation.txt",sep="\t",header=F,quote="")
> > > c<-p.adjust(a$V3,"BH")
> > > a[,4]<-c
> > > write.table(a,"zz.txt",sep="\t")
> > >
> > > And I got the result:
> > >
> > > hsa-miR-205--GATA3 0.797882767 1.08E-13 1.08E-12
> > > hsa-miR-205--ITGB4 0.750217593 1.85E-11 8.20E-11
> > > hsa-miR-187--PGF 0.797604155 3.24E-11 8.20E-11
> > > hsa-miR-205--SERPINB5 0.744124886 3.28E-11 8.20E-11
> > > hsa-miR-205--PBX1 0.734487224 7.89E-11 1.58E-10
> > > hsa-miR-205--MCC 0.72499934 1.80E-10 3.00E-10
> > > hsa-miR-205--WNT5B 0.717705259 3.33E-10 3.78E-10
> > > hsa-miR-200c--PKN2 0.721746815 3.46E-10 3.78E-10
> > > hsa-miR-200c--PCYOX1 0.721698034 3.48E-10 3.78E-10
> > > hsa-miR-200c--WDR68 0.72068017 3.78E-10 3.78E-10
> > >
> > > When I check it, I found some adjust pvalue are not same to result that
> I
> > > did manually.
> > >
> > > Can anyone help for this. Thanks,
> > >
> > > Jiang
> > >
> > >   [[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] distance coefficient for amatrix with ngative valus

2011-10-03 Thread R. Michael Weylandt
You still haven't explained what's wrong with *almost every metric
there is*, but if you want other distance metrics have you considered
those in the package you are using, via the function dsvdis().
Consider, for example:

library(labdsv)

X <- get(data(bryceveg));

X[, sample(NROW(X))] <- (-1)*X[, sample(NROW(X))] # Put some negative
values in all willy nilly like
Y <- pco( dsvdis(X, index="bray/curtis") )
print(any(X < 0))

If you want more explanation, please provide actual details of what
you are asking, as requested in my first email.

Michael Weylandt

On Mon, Oct 3, 2011 at 9:23 PM, dilshan benaragama
 wrote:
> I am using (labdsv). If I can use euclidean distance I can do it with PCA
> instead of PCO, so I am trying an alternative to PCA, but I cannot find a
> disimilarity coefficient for that.
>
> From: R. Michael Weylandt 
> To: dilshan benaragama ; r-help
> 
> Sent: Monday, October 3, 2011 3:27:53 PM
> Subject: Re: [R] distance coefficient for amatrix with ngative valus
>
> One order of the usual coming right up!
>
> 1 course of "Why does XXX not work for you?" a la francaise, where XXX
> is, in your case, the Euclidean distance.  Specifically, any metric
> worth its salt (in a normed space) satisfies dist(a,b) = dist(a+c,b+c)
> so why are negative values a problem?...
>
> 2 sides: a "Minimal Working Example" with a light buttery sauce and a
> fried "what package/code are you using"
>
> and, for desert, a Winsemian special of: "read the posting guide!"
>
> Michael Weylandt, who is putting together a menu for a fancy dinner
> even as he types
>
> On Mon, Oct 3, 2011 at 12:55 PM, dilshan benaragama
>  wrote:
>> Hi,
>> I need to run a PCoA (PCO) for a data set wich has both positive and
>> negative values for variables. I  could not find any distancecoefficient
>> other than euclidean distace running for the data set. Are there any other
>> coefficient works with negtive values.Also I cannot get summary out put (the
>> eigen values) for PCO as for PCA.
>>
>> Thanks.
>> Dilshan
>>        [[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] distance coefficient for amatrix with ngative valus

2011-10-03 Thread R. Michael Weylandt
Comments inline:

On Mon, Oct 3, 2011 at 11:27 PM, dilshan benaragama
 wrote:
> Yes I think you did not get my problem.

No, you did not state your problem. I have replied to everything you
have actually included to this point. Admittedly, I have failed to
reply to things you did not say...

>  Actualy I want run PCO with
> (labdsv). To do that I I am trying to get the distance metrix using
> following fuctions with library (vegan).

This is now the 7th email in this chain. You should mention the
packages and functions you are using in the FIRST email of the chain.
This is mentioned in the posting guide which you apparently have still
not yet read.

>
> pca.gower<- vegdist(envt[,2:9],method="gower")
> pca.eucl<-vegdist(envt[,2:9],method="euclidean")
> pca.chi<-vegdist(envt[,2:9],method="chi.square")
> pca.mahal<-vegdist(envt[,2:9],method="mahal")
> pca.bray<-vegdist(envt,method="bray")
>
> However none of the functions work

They all work for any data I put in. This is perhaps when that minimal
working example, which you also should have included, is necessary.
The append at the end of each of the 7 emails in this chain that tells
you to read the posting guide also asks for this, as did I explicitly.

> (gives an error saying that is not
> working due to negatve values)

No, they each give warnings. Warnings are not errors. They are
warnings and they say "warning". Perhaps unsurprisingly, errors say
"error". If you are using an old version of vegan that throws an
error, you should always update before seeking help.Not surprisingly,
a certain document suggests this.

> except euclidean distance for the raw data
> set as the raw data has negative values for some variables. It is no point
> of using euclidean metrix with PCO as we can do the same thing from PCA. So
> I need to find a way I can run PCO with a different dissimilarity metrix
> for this data. It will be a great help if you can help me on this

Actually read the warning message: it warns you that you have given
negative data to an ecological function and suggests this might be a
point you look into as this usually suggests a user-end problem. It
does not fail to work in any sense of the word as evidence by the
output of distances. If  negative data is nonsense, you should heed
this warning; if you know its not, disregard it.

More importantly, as I said in my initial response, any distance
metric worth its salt is translation invariant. To wit,

x <- matrix(rnorm(50),5)

d1 = vegdist(x, method="gower")
d2 = vegdist(x + abs(min(x))*3, method="gower")

all.equal(as.numeric(d1), as.numeric(d2))
TRUE

In fairness, I'll admit this does not seem to work for the bray
distance. I am not an ecologist and I do not know why this would be --
it does leave me somewhat confused as to what sort of space motivates
the bray metric, but that's a discussion for another time and place --
but the function still returns a valid dist object for both d1 and d2.

>
> Thanks,
> From: R. Michael Weylandt 
> To: dilshan benaragama ; r-help
> 

You will note that I include the r-help list on each email on this
chain while you have not; this is mentioned in the posting guide.

> Sent: Monday, October 3, 2011 10:00:53 PM
> Subject: Re: [R] distance coefficient for amatrix with ngative valus
>
> You still haven't explained what's wrong with *almost every metric
> there is*, but if you want other distance metrics have you considered
> those in the package you are using, via the function dsvdis().
> Consider, for example:
>
> library(labdsv)
>
> X <- get(data(bryceveg));
>
> X[, sample(NROW(X))] <- (-1)*X[, sample(NROW(X))] # Put some negative
> values in all willy nilly like
> Y <- pco( dsvdis(X, index="bray/curtis") )
> print(any(X < 0))
>
> If you want more explanation, please provide actual details of what
> you are asking, as requested in my first email.
>
> Michael Weylandt
>
> On Mon, Oct 3, 2011 at 9:23 PM, dilshan benaragama
>  wrote:
>> I am using (labdsv). If I can use euclidean distance I can do it with PCA
>> instead of PCO, so I am trying an alternative to PCA, but I cannot find a
>> disimilarity coefficient for that.
>>
>> From: R. Michael Weylandt 
>> To: dilshan benaragama ; r-help
>> 
>> Sent: Monday, October 3, 2011 3:27:53 PM
>> Subject: Re: [R] distance coefficient for amatrix with ngative valus
>>
>> One order of the usual coming right up!
>>
>> 1 course of "Why does XXX not work for you?" a la francaise, where XXX
>> is, in your case, the Euclidean distance.  Specifically, any metric
>> worth its salt (in a normed space) satisfies dist(a,b) = dist(a+c,b+c)
>> so why are negative values a problem?...
>>
>> 2 sides: a "Minimal Working Example" with a light buttery sauce and a
>> fried "what package/code are you using"
>>
>> and, for desert, a Winsemian special of: "read the posting guide!"
>>
>> Michael Weylandt, who is putting together a menu for a fancy dinner
>> even as he types
>>
>> On Mon, Oct 3, 2011 at 12:55 PM, dilshan benaragama
>>  wrote:
>>> Hi

Re: [R] ROC plot for KNN

2011-10-03 Thread AHmed

Qian Liu  gmail.com> writes:

> 
> Hi I need some help with ploting the ROC for K-nearest neighbors. Since KNN
> is a non-parametric classification methods, the predicted value will be
> either 0 or 1.
> It will not be able to test for different cutoff to plot ROC. What is the
> package or functions I should use to plot ROC for KNN?
> 
> Thanks.
> Qian
> 
>   [[alternative HTML version deleted]]
> 
> 


I m wondering if you found any help or any codes to plot roc curve 

Thanks.
Salmi

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


Re: [R] Import in R with White Spaces

2011-10-03 Thread Tyler Rinker

I use the following function I stole somewhere.  There's probably better ways.
 
white <- function(x){
x <- as.data.frame(x)
W <- function(x) gsub(" +", "", x)
sapply(x,W)
}

#EXAPLE
dat <- paste(letters," ", " ", LETTERS)
(DAT <- data.frame(dat, dat))   #nasty white spaces
white(DAT)   #white spaces gone
 
 
Tyler
 

> Date: Mon, 3 Oct 2011 08:14:27 -0700
> From: francy.casal...@gmail.com
> To: r-help@r-project.org
> Subject: [R] Import in R with White Spaces
> 
> Hi,
> 
> I have a simple question about importing data, I would be very grateful if
> you could help me out.
> 
> I have used read.csv(file name, header=T, sep=",") to bring in a csv file I
> saved in MS Excel.The problem is I have white spaces in the middle of values
> (not in the column names), and this messes up the column entries. Since I
> have many many files that I am importing and I have spaces in all of them, I
> was looking for a way to avoid going into all of them and changing the white
> spaec to, for example, an underscore.
> Can you suggest whether there is a way to tell R that each element delimited
> by "," is actually a different entry, regardless of whether there are white
> spaces in between?
> 
> Thank you so much for the help!
> -f
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Import-in-R-with-White-Spaces-tp3867799p3867799.html
> Sent from the R help mailing list archive at Nabble.com.
> [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
  
[[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] Question about ggplot2 and stat_smooth

2011-10-03 Thread Andrés Aragón
Hi,
Try some like this:

c <- ggplot(mtcars, aes(qsec, mpg, colour=factor(cyl)))
c + stat_smooth(aes(group=cyl))+stat_smooth(aes(fill=factor(cyl)))+geom_point()


Andrés AM



2011/10/3, Thomas Adams :
>   I'm interested in creating a graphic -like- this:
>
> c <- ggplot(mtcars, aes(qsec, wt))
> c + geom_point() + stat_smooth(fill="blue", colour="darkblue", size=2,
> alpha = 0.2)
>
> but I need to show 2 sets of bands (with different shading) using 5%,
> 25%, 75%, 95% limits that I specify and where the heavy blue line is the
> median. I don't understand how to do this with ggplot2. What I am doing
> currently is to generate 'boxplots' (with 5%, 25%, 75%, 95% limits) at
> 6-hourly time steps (so I have a series of boxplots, which you can see
> by clicking on a map point:
> http://www.erh.noaa.gov/mmefs/index_test.php?Lat=38.2&Lon=-80.1&Zoom=5&Refresh=0&RFCOverlay=0&Model=NAEFS).
> Some who use our graphics would like to see something more like the
> ggplot2 with stat_smooth graphic.
>
> Help is much appreciated.
>
> Regards,
> Tom
>
> --
> Thomas E Adams
> National Weather Service
> Ohio River Forecast Center
> 1901 South State Route 134
> Wilmington, OH 45177
>
> EMAIL:thomas.ad...@noaa.gov
>
> VOICE:937-383-0528
> FAX:  937-383-0033
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Efficient way to do a merge in R

2011-10-03 Thread Aurélien PHILIPPOT
Dear all,
I am new in R and I have been faced with the following problem, that slows
me down a lot.  I am short of ideas to circumvent it. So, any help would be
highly appreciated:

I have 2 dataframes x and y.  x is very big (70 million observations),
whereas y is smaller (30 observations).
All the observations of y are present in x. But y has one additional
variable that I would like to incorporate to the dataframe x.

For instance, imagine they have the following variable names:
colnames(x)<- c("V1", "V2", "V3", "V4") and colnames(y)<- c("V1", "V2",
"V5")

-Since the observations of y are present in x, my strategy was to merge x
and y so that the dataframe x would get the values of the variable V5 for
the observations that are both in x and y.

-So, I did the following:
dat<- merge(x, y, all=TRUE).

On a small example, it works fine. The only problem is that when I apply it
to my big dataframe x, it really take for ever (several days and not done
yet) and I have a very  fast computer. So, I don't know whether I should
stop now or keep on waiting.

Does anyone have any idea to perform this operation in a more efficient way
(in terms of computation time)?
In addition, does anyone know how to incoporate some sort of counter in a
program to check what how much work has been done at a given point of time?

Any comments are very welcome,
Thanks,

Best,
Aurelien

[[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] read .csv from web from password protected site

2011-10-03 Thread Mike Pfeiff
Yes, I meant to reply to all (sorry still new at asking for help)

1. No, I am not able to open the file when I insert "userID:password@"  between 
"http://"; and "www"


http://userid:passw...@www.frontierweather.com/degreedays/L15N15PowerRegionAverages_10weeks.txt
(replacing userid and password with my actual information that is known 
to work)

2. Yes, the webpage where the data is stored does require me to my userid and 
password and gives me the option to remember password for future use which I 
have selected.  Subsequent visits to the website do not require me to reenter 
info.  



-Original Message-
From: Sarah Goslee [mailto:sarah.gos...@gmail.com] 
Sent: Monday, October 03, 2011 3:07 PM
To: Mike Pfeiff; r-help
Subject: Re: [R] read .csv from web from password protected site

Hi,

I've assumed that you meant to send this to the R-help list, and not just me.

On Mon, Oct 3, 2011 at 3:54 PM, Mike Pfeiff  wrote:
> Sarah,  Thanks for the suggestion.  Although, 
> read.table("http://userid:passw...@my.url/file.csv";) did not work as it 
> returned the following:
>
>        Error in file(file, "rt") : cannot open the connection
>        In addition: Warning message:
>        In file(file, "rt") : unable to resolve 'userid'
>
> (where 'usesid is my actual userid)
>
> I've tried the following RCurl commands...
>
>        myURL   
> ="http://www.frontierweather.com/degreedays/L15N15PowerRegionAverages_10weeks.txt";
>        h=getURL(myURL, userpw = "userid:passwod", followlocation=TRUE)
>        test=read.table(h,header=TRUE,sep=",")
>
> ..and I can't get the data to read and get the following errors:
>
>        Error in file(file, "rt") : cannot open the connection
>        In addition: Warning message:
>        In file(file, "rt") : unable to resolve 'userid'
>
> I'm at a total loss.  Any assistance anyone could provide would be greatly 
> appreciated.

You can get to the file using your web browser and that userid/password combo, 
right?

Do you have to go through a dialog box? Press a button to login? Any of those 
have the potential to complicate the task.

If so, you'll need to work through the Forms section at 
http://www.omegahat.org/RCurl/philosophy.html

Sarah

>
>
> -Original Message-
> From: Sarah Goslee [mailto:sarah.gos...@gmail.com]
> Sent: Monday, October 03, 2011 2:26 PM
> To: Mike Pfeiff
> Cc: r-help@r-project.org
> Subject: Re: [R] read .csv from web from password protected site
>
> Hi Mike,
>
> On Mon, Oct 3, 2011 at 12:31 PM, Mike Pfeiff  wrote:
>> I am very new to R and have been struggling trying to read a basic ".csv" 
>> file from a password protected site with the following code:
>>
>> myURL  
>> ="http://www.frontierweather.com/degreedays/L15N15PowerRegionAverages_10weeks.txt";
>> test2=read.table(url(myURL),header=TRUE,sep=",")
>
>
>> A 'data.frame' is returned into the workspace, however it is not the data 
>> contained in the ".csv" file.   I think this occurs because the website 
>> where I am trying to retrieve the data is password protected.
>>
>> Is there a way to specify the username and password?
>
>
> I'd try first
> read.table("http://userid:passw...@my.url/file.csv";), which is the standard 
> way to do it (hint: try that form in your web browser and see whether you can 
> access the data), and if that doesn't work look into the RCurl package. The 
> list archives have a fair bit of information on this topic.
>
> Sarah
>
>
>> Any guidance would be greatly appreciated.
>>
>> Sincerely,
>>
>> Mike
>>
>

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

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


Re: [R] rolling regression

2011-10-03 Thread Darius H

Hi Michael, 

Many thanks for your reply. 

I am handicapped in 2 different areas; firstly R and most importantly 
statistical concepts! 

May
 I ask you to expand on the 2nd paragraph of your reply below. I was 
originally using dynlm but then changed back to lm to avoid 
complication.

Also, what do you mean by: "You probably need to use a time series model that 
has forecasting built into it..."

Many thanks,
Darius

> From: michael.weyla...@gmail.com
> Date: Mon, 3 Oct 2011 13:16:47 -0400
> Subject: Re: [R] rolling regression
> To: xeno...@hotmail.com
> CC: r-help@r-project.org
> 
> It seems you don't really know how predict works. If you don't supply
> new data, it will only return the least squares fit to the old data,
> which is the large data block you saw. Check the first example given
> in ?predict to see how this works for new (out of sample) data.
> 
> More importantly, use of lm() gives a model for contemporaneous
> fitting of your data to cash_ret. You probably need to use a time
> series model that has forecasting built into it (unless you can
> somehow your independent variables before your dependent variables)
> 
> Michael Weylandt
> 
> On Sun, Oct 2, 2011 at 11:41 PM, Darius H  wrote:
> >
> > Dear all,
> >
> > I have spent the last few days on a seemingly simple and previously 
> > documented rolling regression.
> >
> > I have a 60 year data set organized in a ts matrix.
> > The matrix has 5 columns; cash_ret, epy1, ism1, spread1, unemp1
> >
> > I have been able to come up with the following based on previous help 
> > threads. It seems to work fine.
> > The trouble is I get regression coefficients but need the immediate next 
> > period forecast.
> >
> > cash_fit= rollapply(cash_data, width=60,
> >
> > function(x) coef(lm(cash_ret~epy1+ism1+spread1+unemp1, data = 
> > as.data.frame(x))),
> >
> > by.column=FALSE, align="right"); cash_fit
> >
> >
> > I tried to replace "coef" above to "predict" but I get a whole bunch of 
> > results too big to be displayed. I would be grateful
> > if someone could guide me on how to get the next period forecast after each 
> > regression.
> >
> > If there is a possibility of getting the significance of each regressor and 
> > the standard error in addition to R-sq
> > without having to spend the next week, that would be helpful as well.
> >
> > Many thanks,
> > Darius
> >
> >
> >
> >
> >
> >[[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] Quasi-Binomial simulation

2011-10-03 Thread saber fallahpour
Hi
I want to do simulation on quasi-binomial distribution with some covariates.
Does anyone have an idea how to do that? 

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


  1   2   >