Re: [R] Linear Regression with Constraints

2009-05-27 Thread Emmanuel Charpentier
Le mardi 26 mai 2009 à 14:11 -0400, Stu @ AGS a écrit :
> Hi!
> I am a bit new to R.
> I am looking for the right function to use for a multiple regression problem
> of the form:
> 
> y = c1 + x1 + (c2 * x2) - (c3 * x3)
> 
> Where c1, c2, and c3 are the desired regression coefficients that are
> subject to the following constraints:
> 
> 0.0 < c2 < 1.0, and
> 0.0 < c3 < 1.0

Sounds rather like an in-the-closet Bayesian problem (with a very
strange prior...). Did you consider to submit it to WinBUGS (or JAGS) ?

If you still want a direct optimization, you could have started :

RSiteSearch("optimization constraint")

Which would have quickly led you to ask :

? constrOptim

> y, x1, x2, and x3 are observed data.  
> I have a total of 6 rows of data in a data set.

??? I that's real-life data, I wonder what kind of situation forces you
to estimate 3+1 parameters (c1, c2, c3 and the residual, which is not
really a parameter) with 6 data points ? Your problem can be written as
a system of 6 linear equations with 3 unknowns (c1, c2, c3), leaving you
room to search in (a small piece of) R^3 (the residual is another way to
express your objective function, not an independent parameter).

Of course, if it's homework, get lost !

Emmanuel Charpentier

> Is "optim" in the stats package the right function to use?
> Also, I can't quite figure out how to specify the constraints.
> Thank you!
> 
> -Stu
> 

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


Re: [R] Linear Regression with Constraints

2009-05-27 Thread Bill.Venables
You can accommodate the constraints by, e.g., putting

c2 = pnorm(theta2)
c3 = pnorm(theta3)

x1 has a known coefficient (unity) so it becomes an offset.  Essentially your 
problem can be written

y1 = y-x1 = c1 + pnorm(theta2)*x2 - pnorm(theta3)*x3 + error

This is then a (pretty simple) non-linear regression which could be fitted 
using, e.g. nls

If you could not rule out the possibility that the solution is on the boundary, 
you could put c2 = (cos(theta2))^2, and the fitting procedure could take you 
there.  The solution is not unique, but the original coefficients, c2,c3, would 
be unique, of course.

With just 6 observations and 4 parameters to estimate, you will need the model 
to be an exceptionally close fitting one for the fit to have any credibility at 
all.

Bill Venables.

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
Emmanuel Charpentier [charp...@bacbuc.dyndns.org]
Sent: 27 May 2009 17:05
To: r-h...@stat.math.ethz.ch
Subject: Re: [R] Linear Regression with Constraints

Le mardi 26 mai 2009 à 14:11 -0400, Stu @ AGS a écrit :
> Hi!
> I am a bit new to R.
> I am looking for the right function to use for a multiple regression problem
> of the form:
>
> y = c1 + x1 + (c2 * x2) - (c3 * x3)
>
> Where c1, c2, and c3 are the desired regression coefficients that are
> subject to the following constraints:
>
> 0.0 < c2 < 1.0, and
> 0.0 < c3 < 1.0

Sounds rather like an in-the-closet Bayesian problem (with a very
strange prior...). Did you consider to submit it to WinBUGS (or JAGS) ?

If you still want a direct optimization, you could have started :

RSiteSearch("optimization constraint")

Which would have quickly led you to ask :

? constrOptim

> y, x1, x2, and x3 are observed data.
> I have a total of 6 rows of data in a data set.

??? I that's real-life data, I wonder what kind of situation forces you
to estimate 3+1 parameters (c1, c2, c3 and the residual, which is not
really a parameter) with 6 data points ? Your problem can be written as
a system of 6 linear equations with 3 unknowns (c1, c2, c3), leaving you
room to search in (a small piece of) R^3 (the residual is another way to
express your objective function, not an independent parameter).

Of course, if it's homework, get lost !

Emmanuel Charpentier

> Is "optim" in the stats package the right function to use?
> Also, I can't quite figure out how to specify the constraints.
> Thank you!
>
> -Stu
>

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

2009-05-27 Thread Dieter Menne
  alice.it> writes:

> 
> I am looking for a package to perform harmonic analysis with the goal of 
> estimating the period of the
> dominant high frequency component in some mono-channel signals.

You should widen your scope by looking a "time series" instead of harmonic
analysis. There is a task view on the subject at

http://cran.at.r-project.org/web/views/TimeSeries.html

Dieter

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


Re: [R] using lsoda() and nls() together

2009-05-27 Thread Dieter Menne



bbouling wrote:
> 
> Thanks to Dieter Menne and Spencer Graves I started to get my way through
> lsoda()
> Now I need to use it in with nls() to assess parameters
> 
> I have a go with a basic example
> 
> dy/dt = K1*conc
> 
> I try to assess the value of K1 from a simulated data set with a K1 close
> to
> 2. Here is (I think) the best code that I've done so far even though it
> crashes
> when I call nls()
> 
> 

Not sure, but I believe you have taken the advice to produce reproducible
code too seriously and got trapped by the bold warning in nls:

Warning
Do not use nls on artificial "zero-residual" data.

The nls function uses a relative-offset convergence criterion that compares
the numerical imprecision at the current parameter estimates to the residual
sum-of-squares. This performs well on data of the form
...

Creating some noise in your data might help

Dieter



-- 
View this message in context: 
http://www.nabble.com/using-lsoda%28%29-and-nls%28%29-together-tp23727813p23737666.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Using package "exams" and xtable

2009-05-27 Thread Dieter Menne



M Berg wrote:
> 
>>str(rx)
> num [1:16] 21 9 8 18 4 12 17 2 9 7 ...
> 
> I want to print out the entire vector as part of the problem.
> When I use \Sexpr(rx) only the first value (in this case 21) is printed
> out.
> 
> 

rx = 1:10
rxs = paste(rx,collapse=", ")

So 

\Sexpr{paste(rx,collapse=", ")} 

should work, but I always prefer

\Sexpr{rxs}

because it is easier to read. And make sure you spell out "collapse" fully,
because it occurs after the  
I got bitten for my laziness a few times

Dieter


-- 
View this message in context: 
http://www.nabble.com/Using-package-%22exams%22-and-xtable-tp23731879p23737771.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] split strings

2009-05-27 Thread Wacek Kusnierczyk
Allan Engelhardt wrote:
> Immaterial, yes, but it is always good to test :) and your solution
> *is* faster and it is even faster if you can assume byte strings:

:)

indeed;  though if the speed is immaterial (and in this case it
supposedly was), it's probably not worth risking fixed=TRUE removing
'.tif' from the middle of the name, however unlikely this might be (cf
murphy's laws).

but if you can assume that each string ends with a '.tif' (or any other
\..{3} substring), then substr is marginally faster than sub, even as a
three-pass approach, while avoiding the risk of removing '.tif' from the
middle:

strings = sprintf('f:/foo/bar//%s.tif', replicate(1000,
paste(sample(letters, 10), collapse='')))
library(rbenchmark)
benchmark(columns=c('test', 'elapsed'), replications=1000, order=NULL,
   substr={basenames=basename(strings); substr(basenames, 1,
nchar(basenames)-4)},
   sub=sub('.tif', '', basename(strings), fixed=TRUE, useBytes=TRUE))
# test elapsed
# 1 substr   3.176
# 2sub   3.296


vQ

>
> > strings = sprintf('f:/foo/bar//%s.tif', replicate(1000,
> paste(sample(letters, 10), collapse='')))
> > library(rbenchmark)
> > benchmark(columns=c('test', 'elapsed'), replications=1000, order=NULL,
>   'one-pass, perl'=sub('.*//(.*)[.]tif$', '\\1', strings, perl=TRUE),
>   'two-pass, perl'=sub('.tif$', '', basename(strings), perl=TRUE),
>   'one-pass, no perl'=sub('.*//(.*)[.]tif$', '\\1', strings, perl=FALSE),
>   'two-pass, no perl'=sub('.tif$', '', basename(strings), perl=FALSE),
>   'fixed'=sub(".tif", "", basename(strings), fixed=TRUE),
>   'fixed, bytes'=sub(".tif", "", basename(strings), fixed=TRUE,
> useBytes=TRUE))
>
>   test elapsed
> 1one-pass, perl   2.946
> 2two-pass, perl   3.858
> 3 one-pass, no perl  15.884
> 4 two-pass, no perl   3.788
> 5 fixed   2.264
> 6  fixed, bytes   1.813
>

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

2009-05-27 Thread Indrajit Sengupta

Hi All,

I am trying to learn Neural Networks. I found that R has packages which can 
help build Neural Nets - the popular one being AMORE package. Is there any book 
/ resource available which guides us in this subject using the AMORE package?

Any help will be much appreciated.

Thanks,
Indrajit

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

2009-05-27 Thread Lazy Tiger

Greetings,

Does anyone know if the C4.5 algorithm is already implemented in R? If yes,
please let me know the package. Thanks.
-- 
View this message in context: 
http://www.nabble.com/C4.5-implementation-in-R-tp23736785p23736785.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Using package "exams" and xtable

2009-05-27 Thread David Hajage
Hello,

\Sexpr only displays one value.

Why don't you print your vector into a verbatim environment ?

<>
print(rx)
@

But if you want to generate a table with xtable, one solution :

<>
print(xtable(as.data.frame(t(rx))), include.rownames = F, include.colnames =
F)
@


David


On Tue, May 26, 2009 at 11:36 PM, M Berg  wrote:

> Hello,
>
> I am trying to use the package "exams" to construct problem sets.
>
> I have constructed an exercise which generates a list of integers and asks
> the student to compute the median.
>
> rx is the vector of n numbers
>
> >str(rx)
> num [1:16] 21 9 8 18 4 12 17 2 9 7 ...
>
> I want to print out the entire vector as part of the problem.
> When I use \Sexpr(rx) only the first value (in this case 21) is printed
> out.
>
> I have been trying to get xtable to work.
>
> > xtable(rx)
> Error in UseMethod("xtable") : no applicable method for "xtable"
>
> > methods(xtable)
>  [1] xtable.anova*   xtable.aov* xtable.aovlist*
>  [4] xtable.coxph*   xtable.data.frame*  xtable.glm*
>  [7] xtable.lm*  xtable.matrix*  xtable.prcomp*
> [10] xtable.summary.aov* xtable.summary.aovlist* xtable.summary.glm*
> [13] xtable.summary.lm*  xtable.summary.prcomp*  xtable.table*
> [16] xtable.ts*  xtable.zoo*
>
>   Non-visible functions are asterisked
>
> I am new to R and would appreciate any suggestions.
>
> What is the best way to get exams/Sweave to print out the entire vector?
>
> Thanks in advance.
>
> DBerg
>
>[[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] C4.5 implementation in R

2009-05-27 Thread Tony Breyal
I think Rweka implements the C4.5 (revision 8) algorithm, but it calls
it J4.8 (because it's written in Java instead of C, and also the
revision number, and is uses an open source licence, i think).

You might want to look at this paper by Schauerhuber, Zeileis & Hornik
called 'Benchmarking Open-Source Tree Learners in R/RWeka':

http://epub.wu-wien.ac.at/dyn/virlib/wp/eng/mediate/epub-wu-01_bd8.pdf?ID=epub-wu-01_bd8

otherwise, try: http://cran.r-project.org/web/views/MachineLearning.html

Hope that helps a little bit, i've been meaning to have a play around
with that package myself actually, just need to find the time :D

Tony



On 27 May, 07:39, Lazy Tiger  wrote:
> Greetings,
>
> Does anyone know if the C4.5 algorithm is already implemented in R? If yes,
> please let me know the package. Thanks.
> --
> View this message in 
> context:http://www.nabble.com/C4.5-implementation-in-R-tp23736785p23736785.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://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] interactive file choosing in Linux?

2009-05-27 Thread Juergen Rose
Am Dienstag, den 26.05.2009, 21:05 +0200 schrieb Romain Francois:
> Hi,
> 
> You might like tk_choose.files from package tcltk. This comes with R but 
> your system needs to be capable enough:
> 
>  > capabilities( )["tcktk"]
>  > require( tcltk )
>  > tk_choose.files

I suppose it should be
> capabilities( )["tcltk"]

> Romain
> 
> Derek Eder wrote:
> > I am used to using the [R] function choose.files() for interactive file 
> > selection in MS-Windows.
> >
> > What is the comparable function in Linux?   I expected the function 
> > file.choose() to display similar behavior, i.e., a graphical interface 
> > diplaying a file listing, but all I seem to get is a "text input prompt".   
> > This does not seem correct.
> >
> > > file.choose()
> > Enter file name: 
> >
> > I have seen gfile() function in the gWidgets library - but isn't there 
> > anything native? 
> >
> > Thank you!
> >
> >
> > Derek Eder
> >
> >
> >
> >
> >
> > Linux:  Ubuntu 9.04,  Gnome, [R] running in terminal or ESS GTK_Emacs 
> > (doesn't make any difference to the above).
> >
> >
> >   
> >> version   _  
> >> 
> > platform   i486-pc-linux-gnu  
> > arch   i486   
> > os linux-gnu  
> > system i486, linux-gnu
> > status
> > major  2  
> > minor  8.1
> > year   2008   
> > month  12 
> > day22 
> > svn rev47281  
> > language   R  
> > version.string R version 2.8.1 (2008-12-22)
> >
> >
> >
> > Derek N. Eder
> > Gothenburg University
> > Vigilance and Neurocognition Laboratory
> > Medicinaregatan 8B
> > Gothenburg Sweden
> > SE 405 30
> >
> > tlf (031) 342-8261
> > mobil 0704 915 714
> >  
> >
> > "All created things are impermanent — Strive diligently."
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
> >   
> 
> 
-- 
Juergen Rose 
Uni Potsdam

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Constrained fits: y~a+b*x-c*x^2, with a,b,c >=0

2009-05-27 Thread Alex van der Spek
I wonder whether R has methods for constrained fitting of linear models.

I am trying fm<-lm(y~x+I(x^2), data=dat) which most of the time gives
indeed the coefficients of an inverted parabola. I know in advance that
it has to be an inverted parabola with the maximum constrained to
positive (or zero) values of x.

The help pages for lm do not contain any info on constrained fitting.

Does anyone know how to?

Regards,
Alex van der Spek

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


Re: [R] Still can't find missing data

2009-05-27 Thread Dieter Menne
Farley, Robert  metro.net> writes:

> 
> What is wrong?  I've looked into the na commands and the ?xtabs entry, but I
haven't found anything that works.
> 

I never understood the logic that exclude=NULL needs na.action in addition.

test <- c(1,2,3,1,2,3,NA,NA,1,2,3) 
xtabs(~test,exclude=NULL,na.action=na.pass)

Dieter

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

2009-05-27 Thread Shreyasee
Hi,

I searched a lot on the internet but was unable to find the function for
calculating the kappa statistics for intra-observer reliabilty.
Can anybody help me in the this regards.

Thanks,
Shreyasee

[[alternative HTML version deleted]]

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


[R] r-plot

2009-05-27 Thread durden10

Dear R-community

I have a grueling problem which appears to be impossible to solve:
I want to make a simple plot, here is my code: http://gist.github.com/118550
Unfortunately, the annotation of both the x- and y-axis are not correct, as
you can see in the following picture: 
http://www.nabble.com/file/p23739356/plot.png 
I am not an expert of R, so maybe someone can point me to the solution of
this problem, i.e. both of the axes should start and end at the min / max
values of the two vectors.

Thanks in advance!!

Best,
Durden
-- 
View this message in context: 
http://www.nabble.com/r-plot-tp23739356p23739356.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] Multivariate Transformations

2009-05-27 Thread Hollix

Hello folks,

many multivariate anayses (e.g., structural equation modeling) require
multivariate normal distributions.
Real data, however, most often significantly depart from the multinormal
distribution. Some researchers (e.g., Yuan et al., 2000) have proposed a
multivariate transformation of the variables.

Can you tell me, if and how such a transformation can be handeled in R?

Thanks in advance.
With best regards
Holger


---
Yuan, K.-H., Chan, W., & Bentler, P. M. (2000). Robust transformation with
applications to structural equation modeling. British Journal of
Mathematical and Statistical Psychology, 53, 31–50. 
-- 
View this message in context: 
http://www.nabble.com/Multivariate-Transformations-tp23739013p23739013.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] Neural Network resource

2009-05-27 Thread Tony Breyal
There's a link on the CRAN page for the AMORE package which apears to
have some cool information:

http://wiki.r-project.org/rwiki/doku.php?id=packages:cran:amore

Seems like an interesting package, I hadn't actually heard of it
before your post.

HTH,
Tony

On 27 May, 09:13, Indrajit Sengupta  wrote:
> Hi All,
>
> I am trying to learn Neural Networks. I found that R has packages which can 
> help build Neural Nets - the popular one being AMORE package. Is there any 
> book / resource available which guides us in this subject using the AMORE 
> package?
>
> Any help will be much appreciated.
>
> Thanks,
> Indrajit
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://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] Constrained fits: y~a+b*x-c*x^2, with a,b,c >=0

2009-05-27 Thread Berwin A Turlach
G'day Alex,

On Wed, 27 May 2009 11:51:39 +0200
Alex van der Spek  wrote:

> I wonder whether R has methods for constrained fitting of linear
> models.
> 
> I am trying fm<-lm(y~x+I(x^2), data=dat) which most of the time gives
> indeed the coefficients of an inverted parabola. I know in advance
> that it has to be an inverted parabola with the maximum constrained to
> positive (or zero) values of x.
> 
> The help pages for lm do not contain any info on constrained fitting.
> 
> Does anyone know how to?

Look at the package nnls on CRAN.

According to your subject line, you are trying to solve what is known
as a quadratic program, and there are at least two quadratic
programming solvers (ipop in kernlab and solve.qp in quadprog)
available for R.

HTH.

Cheers,

Berwin

=== Full address =
Berwin A TurlachTel.: +65 6516 4416 (secr)
Dept of Statistics and Applied Probability+65 6516 6650 (self)
Faculty of Science  FAX : +65 6872 3919   
National University of Singapore 
6 Science Drive 2, Blk S16, Level 7  e-mail: sta...@nus.edu.sg
Singapore 117546http://www.stat.nus.edu.sg/~statba

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


[R] Multiple ANOVA tests

2009-05-27 Thread Imri

Hi all -
I'm trying to do multiple one-way ANOVA tests of different factors on the
same variable. As a result I have a list with all the ANOVA tables, for
exemple:

$X11_20502
Analysis of Variance Table

Response: MPH
   Df  Sum Sq Mean Sq F valuePr(>F)
x   3   369.9   123.3   6.475 0.0002547 ***
Residuals 635 12093.219.0  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

$X11_21067
Analysis of Variance Table

Response: MPH
   Df  Sum Sq Mean Sq F value Pr(>F)
x   126.726.7  1.3662 0.2429
Residuals 637 12436.419.5   

$X11_10419
Analysis of Variance Table

Response: MPH
   Df  Sum Sq Mean Sq F valuePr(>F)
x   3   527.8   175.9   9.361 4.621e-06 ***
Residuals 635 11935.318.8  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

My question is how can I extract from this list, just the Pr(>F) values for
each x ?  
-- 
View this message in context: 
http://www.nabble.com/Multiple-ANOVA-tests-tp23739615p23739615.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] How to write a loop?

2009-05-27 Thread Maithili Shiva
Dear R helpers, 
 
Following is a R script I am using to run the Fast Fourier Transform. The csv 
files has 10 columns with titles m1, m2, m3 .m10.   
 
When I use the following commands, I am getting the required results. The 
probelm is if there are 100 columns, it is not wise to define 100 commands as 
fk <- ONS$mk and so on. Thus, I need some guidance to write the loop for the 
STEP A and STEP B.
 
Thanking in advance
 
Regards
 
Maithili
 
 
 
My R Script
 
---
 
ONS <- read.csv("fast fourier transform.csv", header = TRUE)
 
  # STEP A
 
  f1 <- ONS$m1
 
  f2 <- ONS$m2
 
  f3 <- ONS$m3
 
  f4 <- ONS$m4
 
  f5 <- ONS$m5
   
  f6 <- ONS$m6
 
  f7 <- ONS$m7
 
  f8 <- ONS$m8
  
  f9 <- ONS$m9
   
  f10 <- ONS$m10
 
#
 

  # STEP B
 
  g1 <- fft(f1)
 
  g2 <- fft(f2)
 
  g3 <- fft(f3)
  
  g4 <- fft(f4)
  
  g5 <- fft(f5)
  
  g6 <- fft(f6)
  
  g7 <- fft(f7)
  
  g8 <- fft(f8)
  
  g9 <- fft(f9)
  
  g10 <- fft(f10)
  
 
#
 
  h <- g1*g2*g3*g4*g5*g6*g7*g8*g9*g10
  
  j <- fft((h), inverse = TRUE)/length(h)
  
 
#
 
 


  Cricket on your mind? Visit the ultimate cricket website. Enter 
http://beta.cricket.yahoo.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] How to exclude a column by name?

2009-05-27 Thread Zeljko Vrba
Given an arbitrary data frame, it is easy to exclude a column given its index:
df[,-2].  How to do the same thing given the column name?  A naive attempt
df[,-"name"] did not work :)

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

2009-05-27 Thread Linlin Yan
Why did you use different variable names rather than index of list/data.frame?

On Wed, May 27, 2009 at 6:34 PM, Maithili Shiva
 wrote:
> Dear R helpers,
>
> Following is a R script I am using to run the Fast Fourier Transform. The csv 
> files has 10 columns with titles m1, m2, m3 .m10.
>
> When I use the following commands, I am getting the required results. The 
> probelm is if there are 100 columns, it is not wise to define 100 commands as 
> fk <- ONS$mk and so on. Thus, I need some guidance to write the loop for the 
> STEP A and STEP B.
>
> Thanking in advance
>
> Regards
>
> Maithili
>
>
>
> My R Script
>
> ---
>
> ONS <- read.csv("fast fourier transform.csv", header = TRUE)
>
>   # STEP A
>
>   f1 <- ONS$m1
>
>   f2 <- ONS$m2
>
>   f3 <- ONS$m3
>
>   f4 <- ONS$m4
>
>   f5 <- ONS$m5
>
>   f6 <- ONS$m6
>
>   f7 <- ONS$m7
>
>   f8 <- ONS$m8
>
>   f9 <- ONS$m9
>
>   f10 <- ONS$m10
>
> #
>
>
>   # STEP B
>
>   g1 <- fft(f1)
>
>   g2 <- fft(f2)
>
>   g3 <- fft(f3)
>
>   g4 <- fft(f4)
>
>   g5 <- fft(f5)
>
>   g6 <- fft(f6)
>
>   g7 <- fft(f7)
>
>   g8 <- fft(f8)
>
>   g9 <- fft(f9)
>
>   g10 <- fft(f10)
>
>
> #
>
>   h <- g1*g2*g3*g4*g5*g6*g7*g8*g9*g10
>
>   j <- fft((h), inverse = TRUE)/length(h)
>
>
> #
>
>
>
>
>      Cricket on your mind? Visit the ultimate cricket website. Enter 
> http://beta.cricket.yahoo.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] How to exclude a column by name?

2009-05-27 Thread Linlin Yan
Hope this helps:

> df <- data.frame(matrix(1:10,2))
> df
  X1 X2 X3 X4 X5
1  1  3  5  7  9
2  2  4  6  8 10
> df[,-2]
  X1 X3 X4 X5
1  1  5  7  9
2  2  6  8 10
> df[,-which(names(df)=="X2")]
  X1 X3 X4 X5
1  1  5  7  9
2  2  6  8 10


On Wed, May 27, 2009 at 6:37 PM, Zeljko Vrba  wrote:
> Given an arbitrary data frame, it is easy to exclude a column given its index:
> df[,-2].  How to do the same thing given the column name?  A naive attempt
> df[,-"name"] did not work :)

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

2009-05-27 Thread Paul Hiemstra

Zeljko Vrba wrote:

Given an arbitrary data frame, it is easy to exclude a column given its index:
df[,-2].  How to do the same thing given the column name?  A naive attempt
df[,-"name"] did not work :)

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

This piece of code does the trick. Most important is the which() command:

df = data.frame(a = runif(10), b = runif(10))
df[,-which(names(df) == "a")]

cheers,
Paul

--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul

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

2009-05-27 Thread Zeljko Vrba
On Wed, May 27, 2009 at 12:52:41PM +0200, Paul Hiemstra wrote:
> 
> This piece of code does the trick. Most important is the which() command:
> 
> df = data.frame(a = runif(10), b = runif(10))
> df[,-which(names(df) == "a")]
> 
Thanks to you and Linlin.  It did not occur to me to use which(); I thought
that there would be a shorter way to accomplish this since names are
first-class indices for data frames and arrays.  (Or are they?  What happens
under the hood when I write df[,"a"]?)

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

2009-05-27 Thread Peter Dalgaard
Paul Hiemstra wrote:
> Zeljko Vrba wrote:
>> Given an arbitrary data frame, it is easy to exclude a column given
>> its index:
>> df[,-2].  How to do the same thing given the column name?  A naive
>> attempt
>> df[,-"name"] did not work :)
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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,
> 
> This piece of code does the trick. Most important is the which() command:
> 
> df = data.frame(a = runif(10), b = runif(10))
> df[,-which(names(df) == "a")]
> 

You don't actually need which() (and the approach runs into problems if
"a" isn't there). Just select the others:

df[, names(df) != "a"]

Or, BTW, you can use within()

aq <- within(airquality, rm(Day))

-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

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


Re: [R] Multiple ANOVA tests

2009-05-27 Thread Mike Lawrence
#create some data
y=rnorm(20)
x=factor(rep(c('A','B'),each=10))

#run the anova
my_aov = aov(y~x)

#summarize the anova
my_aov_summary = summary(my_aov)

#show the anova summary
print(my_aov_summary)

#lets see what's in the summary object
str(my_aov_summary)

#looks like it's a list with 1 element which
#in turn is a data frame with columns.
#The "Pr(>F)" column looks like what we want
my_aov_summary[[1]]$P

#yup, that's it. Grab the first value
p = my_aov_summary[[1]]$P[1]


On Wed, May 27, 2009 at 7:11 AM, Imri  wrote:
>
> Hi all -
> I'm trying to do multiple one-way ANOVA tests of different factors on the
> same variable. As a result I have a list with all the ANOVA tables, for
> exemple:
>
> $X11_20502
> Analysis of Variance Table
>
> Response: MPH
>           Df  Sum Sq Mean Sq F value    Pr(>F)
> x           3   369.9   123.3   6.475 0.0002547 ***
> Residuals 635 12093.2    19.0
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> $X11_21067
> Analysis of Variance Table
>
> Response: MPH
>           Df  Sum Sq Mean Sq F value Pr(>F)
> x           1    26.7    26.7  1.3662 0.2429
> Residuals 637 12436.4    19.5
>
> $X11_10419
> Analysis of Variance Table
>
> Response: MPH
>           Df  Sum Sq Mean Sq F value    Pr(>F)
> x           3   527.8   175.9   9.361 4.621e-06 ***
> Residuals 635 11935.3    18.8
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> My question is how can I extract from this list, just the Pr(>F) values for
> each x ?
> --
> View this message in context: 
> http://www.nabble.com/Multiple-ANOVA-tests-tp23739615p23739615.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.
>



-- 
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tr.im/mikes_public_calendar

~ Certainty is folly... I think. ~

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


Re: [R] r-plot

2009-05-27 Thread Gavin Simpson
On Wed, 2009-05-27 at 02:52 -0700, durden10 wrote:
> Dear R-community
> 
> I have a grueling problem which appears to be impossible to solve:
> I want to make a simple plot, here is my code: http://gist.github.com/118550
> Unfortunately, the annotation of both the x- and y-axis are not correct, as
> you can see in the following picture: 
> http://www.nabble.com/file/p23739356/plot.png 
> I am not an expert of R, so maybe someone can point me to the solution of
> this problem, i.e. both of the axes should start and end at the min / max
> values of the two vectors.

But you asked it to do that, explicitly:

par(tcl=0.35,xaxs="r")

xaxs = "r" is the default and if you read ?par it will tell you that
this extends the range of the plot by 4%. Pretty labels are then found
within this range.

Try xaxs = "i" and yaxs = "i" in your call instead.

Then you do this:

axis(2, tcl=0.35,at=0:11)

But 11 is outside the range of the plotted data (+4%) so this tick isn't
drawn. The plot() call sets up the region - a subsequent call to axis()
won't change the axis limits. If you want it to extend up to 11, then
add:

ylim = c(0,11) in your call to plot.

Note also that either the tcl in the first par() call or the ones in the
two axis calls is redundant. Use one or the other.

Here is a simplified example:

set.seed(123)
y <- 0:11 + rnorm(12)
x <- runif(12)
## if you want the 4% padding, then xaxs = "r" etc
op <- par(xaxs = "i", yaxs = "i", tcl = 0.35)
plot(x, y, ylim = c(0,11), axes = FALSE)
axis(2, at = 0:11)
axis(1)
box()
par(op)

Finally, as you have your data in a DF, you could make use of this
instead of relying on getting the ordering correct, and also simplify
your lm call:

plot(Calgary ~ Win, data = data_corr, )

and

abline(lm(Calgary ~ Win, data = data_corr, ))

would be a better way to make use of the formula interface, and be
explicit in the plot about which variable is on the x and which is on
the y axis.

HTH

G

> 
> Thanks in advance!!
> 
> Best,
> Durden
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



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


Re: [R] Intra-observer reliability

2009-05-27 Thread Gavin Simpson
On Wed, 2009-05-27 at 18:08 +0800, Shreyasee wrote:
> Hi,
> 
> I searched a lot on the internet but was unable to find the function for
> calculating the kappa statistics for intra-observer reliabilty.
> Can anybody help me in the this regards.

See classAgreement() in package e1071 for example. There are others

You could have found this yourself using the search tools provided. See:

RSiteSearch("Cohen and Kappa", restrict = "functions")

for other related functions.

HTH

G

> 
> Thanks,
> Shreyasee
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



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


Re: [R] Intra-observer reliability

2009-05-27 Thread Jim Lemon

Shreyasee wrote:

Hi,

I searched a lot on the internet but was unable to find the function for
calculating the kappa statistics for intra-observer reliabilty.
Can anybody help me in the this regards.

  

Hi Shreyasee,
Thanks for reminding me that I had promised to rewrite Tore 
Wentzel-Larsen's relInterIntra function for the irr package. I had 
completely lost track of it. Attached is the function.


Jim

# relInterIntra
# gives the reliability coefficients in the article by 
 # Eliasziw et. al. 1994; Phys. Therapy 74.8; 777-788.
# all references in this function are to this article.
# Arguments
# x: data frame representing a data structure as in Table 1 (p 779), 
#  with consecutive measurements for each rater in adjacent columns.
#  i.e. rater1measure1 rater1measure2 ... rater2measure1 rater2measure2 
# rho0inter: null hypothesis value of the interrater reliability coefficient
# rho0intra: null hypothesis value of the intrarater reliability coefficient
# conf.level: confidence level of the one-sided confidence intervals reported
# for the reliability coefficients
# output reformatted as an "irrlist" stucture - Jim Lemon 2009-05-27

relInterIntra<-function(x,nrater=1,raterLabels=NULL,
 rho0inter=0.6,rho0intra=0.8,conf.level=.95) {

 xdim<-dim(x)
 nsubj<-xdim[1]
 nmeas<-xdim[2]/nrater
 if(is.null(raterLabels)) raterLabels<-letters[1:nrater]
 Frame1<-data.frame(cbind(rep(1:nsubj,nrater*nmeas),
  rep(1:nrater,rep(nsubj*nmeas,nrater)),
  rep(rep(1:nmeas,rep(nsubj,nmeas)),nrater),
  matrix(as.matrix(x),ncol=1)))
 names(Frame1)<-c('Subject','Rater','Repetition','Result')
 Frame1$Subject<-factor(Frame1$Subject)
 Frame1$Rater<-factor(Frame1$Rater,labels=raterLabels)
 Frame1$Repetition<-factor(Frame1$Repetition)
 # this and following two commands:
 # aliases for compatibility with Eliasziw et. al. notation
 nn<-nsubj
 tt<-nrater
 mm<-nmeas
 aovFull<-aov(Result~Subject*Rater,data=Frame1)
 meanSquares<-summary(aovFull)[[1]][,3]
 for(raterAct in 1:tt) {
  raterActCat<-raterLabels[raterAct]
  aovAct<-aov(Result~Subject,data=Frame1[Frame1$Rater==raterActCat,])
  meanSquares<-c(meanSquares,summary(aovAct)[[1]][2,3])
 }
 names(meanSquares)<-
  c('MSS','MSR','MSSR','MSE',paste('MSE',levels(Frame1$Rater),sep=''))
 MSS<-meanSquares[1]
 MSR<-meanSquares[2]
 MSSR<-meanSquares[3]
 MSE<-meanSquares[4]
 # the same for random and fixed, see table 2 (p. 780) and 3 (p. 281)
 MSEpart<-meanSquares[-(1:4)] 
 sighat2Srandom<-(MSS-MSSR)/(mm*tt)
 sighat2Rrandom<-(MSR-MSSR)/(mm*nn)
 sighat2SRrandom<-(MSSR-MSE)/mm
 # the same for random and fixed, see table 2 (p. 780) and 3 (p. 281)
 sighat2e<-MSE 
 sighat2Sfixed<-(MSS-MSE)/(mm*tt)
 sighat2Rfixed<-(MSR-MSSR)/(mm*nn)
 sighat2SRfixed<-(MSSR-MSE)/mm
 # the same for random and fixed, see table 2 (p. 780) and 3 (p. 281)
 sighat2e.part<-MSEpart 
 rhohat.inter.random<-sighat2Srandom/
  (sighat2Srandom+sighat2Rrandom+sighat2SRrandom+sighat2e)
 rhohat.inter.fixed<-(sighat2Sfixed-sighat2SRfixed/tt)/
  (sighat2Sfixed+(tt-1)*sighat2SRfixed/tt+sighat2e)
 rhohat.intra.random<-(sighat2Srandom+sighat2Rrandom+sighat2SRrandom)/
  (sighat2Srandom+sighat2Rrandom+sighat2SRrandom+sighat2e)
 rhohat.intra.fixed<-(sighat2Sfixed+(tt-1)*sighat2SRfixed/tt)/
  (sighat2Sfixed+(tt-1)*sighat2SRfixed/tt+sighat2e)
 rhohat.intra.random.part<-(sighat2Srandom+sighat2Rrandom+sighat2SRrandom)/
  (sighat2Srandom+sighat2Rrandom+sighat2SRrandom+sighat2e.part)
 rhohat.intra.fixed.part<-(sighat2Sfixed+(tt-1)*sighat2SRfixed/tt)/
  (sighat2Sfixed+(tt-1)*sighat2SRfixed/tt+sighat2e.part)
 Finter<-(1-rho0inter)*MSS/((1+(tt-1)*rho0inter)*MSSR)
 Finter.p<-1-pf(Finter,df1=nn-1,df2=(nn-1)*(tt-1))
 alpha<-1-conf.level
 nu1<-(nn-1)*(tt-1)*
  (tt*rhohat.inter.random*(MSR-MSSR)+
  nn*(1+(tt-1)*rhohat.inter.random)*MSSR+
  nn*tt*(mm-1)*rhohat.inter.random*MSE)^2/
  ((nn-1)*(tt*rhohat.inter.random)^2*MSR^2+
  (nn*(1+(tt-1)*rhohat.inter.random)-tt*rhohat.inter.random)^2*MSSR^2+
  (nn-1)*(tt-1)*(nn*tt*(mm-1))*rhohat.inter.random^2*MSE^2)
 nu2<-(nn-1)*(tt-1)*
  (nn*(1+(tt-1)*rhohat.inter.fixed)*MSSR+
  nn*tt*(mm-1)*rhohat.inter.fixed*MSE)^2/
  ((nn*(1+(tt-1)*rhohat.inter.fixed))^2*MSSR^2+
  (nn-1)*(tt-1)*(nn*tt*(mm-1))*rhohat.inter.fixed^2*MSE^2)
 F1<-qf(1-alpha,df1=nn-1,df2=nu1)
 F2<-qf(1-alpha,df1=nn-1,df2=nu2)
 lowinter.random<-nn*(MSS-F1*MSSR)/
  (nn*MSS+F1*(tt*(MSR-MSSR)+nn*(tt-1)*MSSR+nn*tt*(mm-1)*MSE))
 lowinter.random<-min(c(lowinter.random,1))
 lowinter.fixed<-nn*(MSS-F2*MSSR)/
  (nn*MSS+F2*(nn*(tt-1)*MSSR+nn*tt*(mm-1)*MSE))
 lowinter.fixed<-min(c(lowinter.fixed,1))
 Fintra<-(1-rho0intra)*MSS/((1+(mm-1)*rho0intra)*MSE*tt)
 Fintra.p<-1-pf(Fintra,df1=nn-1,df2=nn*(mm-1))
 Fintra.part<-(1-rho0intra)*MSS/((1+(mm-1)*rho0intra)*MSEpart*tt)
 Fintra.part.p<-1-pf(Fintra.part,df1=nn-1,df2=nn*(mm-1))
 F3<-qf(1-alpha,df1=nn-1,df2=nn*(mm-1))
 lowintra<-(MSS/tt-F3*MSE)/(MSS/tt+F3*(mm-1)*MSE)
 lowintra<-min(c(lowintra,1))
 F4<-qf(1-alpha,df1=nn-1,df2=nn*(mm-1))
 lowintra.part<-(MSS/tt-F4*MSEpart)/(MSS/tt+F4*(mm-1)*MSEpart)
 for(raterAct in 1:tt)
  lowint

Re: [R] Intra-observer reliability

2009-05-27 Thread Shreyasee
Thanks a lot

On Wed, May 27, 2009 at 7:47 PM, Gavin Simpson wrote:

> On Wed, 2009-05-27 at 18:08 +0800, Shreyasee wrote:
> > Hi,
> >
> > I searched a lot on the internet but was unable to find the function for
> > calculating the kappa statistics for intra-observer reliabilty.
> > Can anybody help me in the this regards.
>
> See classAgreement() in package e1071 for example. There are others
>
> You could have found this yourself using the search tools provided. See:
>
> RSiteSearch("Cohen and Kappa", restrict = "functions")
>
> for other related functions.
>
> HTH
>
> G
>
> >
> > Thanks,
> > Shreyasee
> --
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>  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
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>
>

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

2009-05-27 Thread Stefan Uhmann

Dear list,

I want to move some files that should keep their time stamps, which is 
not the case if I use file.copy in combination with file.remove. 
file.move would be nice, is there a package providing such a function?


Regards,
Stefan

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


Re: [R] Intra-observer reliability

2009-05-27 Thread Shreyasee
Thanks a lot

On Wed, May 27, 2009 at 7:55 PM, Jim Lemon  wrote:

> Shreyasee wrote:
>
>> Hi,
>>
>> I searched a lot on the internet but was unable to find the function for
>> calculating the kappa statistics for intra-observer reliabilty.
>> Can anybody help me in the this regards.
>>
>>
>>
> Hi Shreyasee,
> Thanks for reminding me that I had promised to rewrite Tore
> Wentzel-Larsen's relInterIntra function for the irr package. I had
> completely lost track of it. Attached is the function.
>
> Jim
>
>
> # relInterIntra
> # gives the reliability coefficients in the article by
>  # Eliasziw et. al. 1994; Phys. Therapy 74.8; 777-788.
> # all references in this function are to this article.
> # Arguments
> # x: data frame representing a data structure as in Table 1 (p 779),
> #  with consecutive measurements for each rater in adjacent columns.
> #  i.e. rater1measure1 rater1measure2 ... rater2measure1 rater2measure2
> # rho0inter: null hypothesis value of the interrater reliability
> coefficient
> # rho0intra: null hypothesis value of the intrarater reliability
> coefficient
> # conf.level: confidence level of the one-sided confidence intervals
> reported
> # for the reliability coefficients
> # output reformatted as an "irrlist" stucture - Jim Lemon 2009-05-27
>
> relInterIntra<-function(x,nrater=1,raterLabels=NULL,
>  rho0inter=0.6,rho0intra=0.8,conf.level=.95) {
>
>  xdim<-dim(x)
>  nsubj<-xdim[1]
>  nmeas<-xdim[2]/nrater
>  if(is.null(raterLabels)) raterLabels<-letters[1:nrater]
>  Frame1<-data.frame(cbind(rep(1:nsubj,nrater*nmeas),
>  rep(1:nrater,rep(nsubj*nmeas,nrater)),
>  rep(rep(1:nmeas,rep(nsubj,nmeas)),nrater),
>  matrix(as.matrix(x),ncol=1)))
>  names(Frame1)<-c('Subject','Rater','Repetition','Result')
>  Frame1$Subject<-factor(Frame1$Subject)
>  Frame1$Rater<-factor(Frame1$Rater,labels=raterLabels)
>  Frame1$Repetition<-factor(Frame1$Repetition)
>  # this and following two commands:
>  # aliases for compatibility with Eliasziw et. al. notation
>  nn<-nsubj
>  tt<-nrater
>  mm<-nmeas
>  aovFull<-aov(Result~Subject*Rater,data=Frame1)
>  meanSquares<-summary(aovFull)[[1]][,3]
>  for(raterAct in 1:tt) {
>  raterActCat<-raterLabels[raterAct]
>  aovAct<-aov(Result~Subject,data=Frame1[Frame1$Rater==raterActCat,])
>  meanSquares<-c(meanSquares,summary(aovAct)[[1]][2,3])
>  }
>  names(meanSquares)<-
>  c('MSS','MSR','MSSR','MSE',paste('MSE',levels(Frame1$Rater),sep=''))
>  MSS<-meanSquares[1]
>  MSR<-meanSquares[2]
>  MSSR<-meanSquares[3]
>  MSE<-meanSquares[4]
>  # the same for random and fixed, see table 2 (p. 780) and 3 (p. 281)
>  MSEpart<-meanSquares[-(1:4)]
>  sighat2Srandom<-(MSS-MSSR)/(mm*tt)
>  sighat2Rrandom<-(MSR-MSSR)/(mm*nn)
>  sighat2SRrandom<-(MSSR-MSE)/mm
>  # the same for random and fixed, see table 2 (p. 780) and 3 (p. 281)
>  sighat2e<-MSE
>  sighat2Sfixed<-(MSS-MSE)/(mm*tt)
>  sighat2Rfixed<-(MSR-MSSR)/(mm*nn)
>  sighat2SRfixed<-(MSSR-MSE)/mm
>  # the same for random and fixed, see table 2 (p. 780) and 3 (p. 281)
>  sighat2e.part<-MSEpart
>  rhohat.inter.random<-sighat2Srandom/
>  (sighat2Srandom+sighat2Rrandom+sighat2SRrandom+sighat2e)
>  rhohat.inter.fixed<-(sighat2Sfixed-sighat2SRfixed/tt)/
>  (sighat2Sfixed+(tt-1)*sighat2SRfixed/tt+sighat2e)
>  rhohat.intra.random<-(sighat2Srandom+sighat2Rrandom+sighat2SRrandom)/
>  (sighat2Srandom+sighat2Rrandom+sighat2SRrandom+sighat2e)
>  rhohat.intra.fixed<-(sighat2Sfixed+(tt-1)*sighat2SRfixed/tt)/
>  (sighat2Sfixed+(tt-1)*sighat2SRfixed/tt+sighat2e)
>  rhohat.intra.random.part<-(sighat2Srandom+sighat2Rrandom+sighat2SRrandom)/
>  (sighat2Srandom+sighat2Rrandom+sighat2SRrandom+sighat2e.part)
>  rhohat.intra.fixed.part<-(sighat2Sfixed+(tt-1)*sighat2SRfixed/tt)/
>  (sighat2Sfixed+(tt-1)*sighat2SRfixed/tt+sighat2e.part)
>  Finter<-(1-rho0inter)*MSS/((1+(tt-1)*rho0inter)*MSSR)
>  Finter.p<-1-pf(Finter,df1=nn-1,df2=(nn-1)*(tt-1))
>  alpha<-1-conf.level
>  nu1<-(nn-1)*(tt-1)*
>  (tt*rhohat.inter.random*(MSR-MSSR)+
>  nn*(1+(tt-1)*rhohat.inter.random)*MSSR+
>  nn*tt*(mm-1)*rhohat.inter.random*MSE)^2/
>  ((nn-1)*(tt*rhohat.inter.random)^2*MSR^2+
>  (nn*(1+(tt-1)*rhohat.inter.random)-tt*rhohat.inter.random)^2*MSSR^2+
>  (nn-1)*(tt-1)*(nn*tt*(mm-1))*rhohat.inter.random^2*MSE^2)
>  nu2<-(nn-1)*(tt-1)*
>  (nn*(1+(tt-1)*rhohat.inter.fixed)*MSSR+
>  nn*tt*(mm-1)*rhohat.inter.fixed*MSE)^2/
>  ((nn*(1+(tt-1)*rhohat.inter.fixed))^2*MSSR^2+
>  (nn-1)*(tt-1)*(nn*tt*(mm-1))*rhohat.inter.fixed^2*MSE^2)
>  F1<-qf(1-alpha,df1=nn-1,df2=nu1)
>  F2<-qf(1-alpha,df1=nn-1,df2=nu2)
>  lowinter.random<-nn*(MSS-F1*MSSR)/
>  (nn*MSS+F1*(tt*(MSR-MSSR)+nn*(tt-1)*MSSR+nn*tt*(mm-1)*MSE))
>  lowinter.random<-min(c(lowinter.random,1))
>  lowinter.fixed<-nn*(MSS-F2*MSSR)/
>  (nn*MSS+F2*(nn*(tt-1)*MSSR+nn*tt*(mm-1)*MSE))
>  lowinter.fixed<-min(c(lowinter.fixed,1))
>  Fintra<-(1-rho0intra)*MSS/((1+(mm-1)*rho0intra)*MSE*tt)
>  Fintra.p<-1-pf(Fintra,df1=nn-1,df2=nn*(mm-1))
>  Fintra.part<-(1-rho0intra)*MSS/((1+(mm-1)*rho0intra)*MSEpart*tt)
>  Fintra.part.p<-1-pf(Fintra.part,df1=nn-1,df2

Re: [R] Constrained fits: y~a+b*x-c*x^2, with a,b,c >=0

2009-05-27 Thread Liaw, Andy
There's also the "nnls" (non-negative least squares) package on CRAN
that might be useful, although I'm puzzled by the negative sign in front
of c in Alex post...

Cheers,
Andy 

From: Berwin A Turlach
> 
> G'day Alex,
> 
> On Wed, 27 May 2009 11:51:39 +0200
> Alex van der Spek  wrote:
> 
> > I wonder whether R has methods for constrained fitting of linear
> > models.
> > 
> > I am trying fm<-lm(y~x+I(x^2), data=dat) which most of the 
> time gives
> > indeed the coefficients of an inverted parabola. I know in advance
> > that it has to be an inverted parabola with the maximum 
> constrained to
> > positive (or zero) values of x.
> > 
> > The help pages for lm do not contain any info on 
> constrained fitting.
> > 
> > Does anyone know how to?
> 
> Look at the package nnls on CRAN.
> 
> According to your subject line, you are trying to solve what is known
> as a quadratic program, and there are at least two quadratic
> programming solvers (ipop in kernlab and solve.qp in quadprog)
> available for R.
> 
> HTH.
> 
> Cheers,
> 
>   Berwin
> 
> === Full address =
> Berwin A TurlachTel.: +65 6516 4416 (secr)
> Dept of Statistics and Applied Probability+65 6516 6650 (self)
> Faculty of Science  FAX : +65 6872 3919   
> National University of Singapore 
> 6 Science Drive 2, Blk S16, Level 7  e-mail: sta...@nus.edu.sg
> Singapore 117546http://www.stat.nus.edu.sg/~statba
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
Notice:  This e-mail message, together with any attachme...{{dropped:12}}

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

2009-05-27 Thread Henrique Dallazuanna
You can try this:

DF[,"columnName"] <- NULL

On Wed, May 27, 2009 at 7:37 AM, Zeljko Vrba  wrote:

> Given an arbitrary data frame, it is easy to exclude a column given its
> index:
> df[,-2].  How to do the same thing given the column name?  A naive attempt
> df[,-"name"] did not work :)
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

[[alternative HTML version deleted]]

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


Re: [R] r-plot

2009-05-27 Thread Richard . Cotton
> I want to make a simple plot, here is my code: 
http://gist.github.com/118550
> Unfortunately, the annotation of both the x- and y-axis are not correct, 
as
> you can see in the following picture: 
> http://www.nabble.com/file/p23739356/plot.png 
> I am not an expert of R, so maybe someone can point me to the solution 
of
> this problem, i.e. both of the axes should start and end at the min / 
max
> values of the two vectors.

>From the help page on par:

'xaxs' The style of axis interval calculation to be used for the
  x-axis.  Possible values are '"r"', '"i"', '"e"', '"s"',
  '"d"'.  The styles are generally controlled by the range of
  data or 'xlim', if given. Style '"r"' (regular) first extends
  the data range by 4 percent at each end and then finds an
  axis with pretty labels that fits within the extended range.
  Style '"i"' (internal) just finds an axis with pretty labels
  that fits within the original data range.

You've explicitly set xaxs="r", when you really want xaxs="i".  You can 
also explicitly set the axis limits using xlim/ylim parameters in the call 
to plot.

Compare these examples:
#Ex 1
plot(1:10)  #implicitly uses par(xaxs="r", yaxs="r") unless you've 
changed something

#Ex 2
oldpar <- par(xaxs="i", yaxs="i")
plot(1:10)
par(oldpar)

#Ex 3
plot(1:10, xlim=c(-5, 15), ylim=c(-100, 100))

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

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


Re: [R] Harmonic Analysis

2009-05-27 Thread Uwe Ligges



Dieter Menne wrote:

  alice.it> writes:

I am looking for a package to perform harmonic analysis with the goal of 
estimating the period of the

dominant high frequency component in some mono-channel signals.


You should widen your scope by looking a "time series" instead of harmonic
analysis. There is a task view on the subject at

http://cran.at.r-project.org/web/views/TimeSeries.html



... or take a look at package tuneR.

Uwe Ligges





Dieter

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

2009-05-27 Thread Zeljko Vrba
I apologize for not pasting a complete example, but the data-set is too large,
so I hope someone can help me just by description of symptoms. 

I define a generic plot object name (note the missing y=.. in aes()) to
plot different y-values against the same set of x-values.

p.b4.generic.wg <-
  ggplot(subset(b4.all.medians, ncpus==8, TRUE), aes(x=wg)) +
  geom_line(aes(linetype=graph, group=interaction(graph,nwrk,ncpus))) +
  geom_point(aes(shape=nwrk)) +
  scale_shape(name="# of workers") + scale_linetype(name="Workload") +
  xlab("Work division") + ylab("N/A")

Now,

p.b4.stealspins <- p.b4.generic.wg + aes(y=v.stealspins / v.realtime) +
  ylab("Steal rate")

draws the correct graph EXCEPT that the y-axis label is wrong.  The ylab() is
ignored and the y-label is set to "v.stealspins / v.realtime".  What am I
doing wrong here?

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

2009-05-27 Thread Ullrika Sahlin
R users,

 

I am making model selection with an accelerated failure time model using the
command survreg within the library survival.

 

As I want to compare models with different probability distributions I need
to have the full likelihood.

 

How can I find out what survreg generates: the full likelihood or a
likelihood with "unnecessary" constants dropped?

 

Example I want to compare the likelihoods in Fit1 and Fit2. Is it
straightforward, or should I e.g. add a syntax asking for the full
likelihood?

Fit1<-survreg(Surv(Time, Event) ~ x, data, dist='weibull')

Fit2<-survreg(Surv(Time, Event) ~ x, data, dist='loglogistic')

 

Ullrika


[[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] Multiple ANOVA tests

2009-05-27 Thread Imri

Thanks for the answer!!!
I Know how to extract the Pr(>F) value from single ANOVA table, but I have a
list of many ANOVA tables recived by :
a<-function(x)(aov(MPH~x))
q<-apply(assoc[,18:20],2,a) # just for example, I have more than 3
factors(x) 

> print(q)
$X11_20502
 Df  Sum Sq Mean Sq F valuePr(>F)
x 3   369.9   123.3   6.475 0.0002547 ***
Residuals   635 12093.219.0  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
246 observations deleted due to missingness

$X11_21067
 Df  Sum Sq Mean Sq F value Pr(>F)
x 126.726.7  1.3662 0.2429
Residuals   637 12436.419.5   
246 observations deleted due to missingness

$X11_10419
 Df  Sum Sq Mean Sq F valuePr(>F)
x 3   527.8   175.9   9.361 4.621e-06 ***
Residuals   635 11935.318.8  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
246 observations deleted due to missingness

> summary(q)
  Length Class   Mode
X11_20502 1  summary.aov list
X11_21067 1  summary.aov list
X11_10419 1  summary.aov list
 How can I extract all the Pr(>F) values from q (not one by one)?

Thanks
Imri

 

Mike Lawrence wrote:
> 
> #create some data
> y=rnorm(20)
> x=factor(rep(c('A','B'),each=10))
> 
> #run the anova
> my_aov = aov(y~x)
> 
> #summarize the anova
> my_aov_summary = summary(my_aov)
> 
> #show the anova summary
> print(my_aov_summary)
> 
> #lets see what's in the summary object
> str(my_aov_summary)
> 
> #looks like it's a list with 1 element which
> #in turn is a data frame with columns.
> #The "Pr(>F)" column looks like what we want
> my_aov_summary[[1]]$P
> 
> #yup, that's it. Grab the first value
> p = my_aov_summary[[1]]$P[1]
> 
> 
> On Wed, May 27, 2009 at 7:11 AM, Imri  wrote:
>>
>> Hi all -
>> I'm trying to do multiple one-way ANOVA tests of different factors on the
>> same variable. As a result I have a list with all the ANOVA tables, for
>> exemple:
>>
>> $X11_20502
>> Analysis of Variance Table
>>
>> Response: MPH
>>           Df  Sum Sq Mean Sq F value    Pr(>F)
>> x           3   369.9   123.3   6.475 0.0002547 ***
>> Residuals 635 12093.2    19.0
>> ---
>> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>>
>> $X11_21067
>> Analysis of Variance Table
>>
>> Response: MPH
>>           Df  Sum Sq Mean Sq F value Pr(>F)
>> x           1    26.7    26.7  1.3662 0.2429
>> Residuals 637 12436.4    19.5
>>
>> $X11_10419
>> Analysis of Variance Table
>>
>> Response: MPH
>>           Df  Sum Sq Mean Sq F value    Pr(>F)
>> x           3   527.8   175.9   9.361 4.621e-06 ***
>> Residuals 635 11935.3    18.8
>> ---
>> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>>
>> My question is how can I extract from this list, just the Pr(>F) values
>> for
>> each x ?
>> --
>> View this message in context:
>> http://www.nabble.com/Multiple-ANOVA-tests-tp23739615p23739615.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.
>>
> 
> 
> 
> -- 
> Mike Lawrence
> Graduate Student
> Department of Psychology
> Dalhousie University
> 
> Looking to arrange a meeting? Check my public calendar:
> http://tr.im/mikes_public_calendar
> 
> ~ Certainty is folly... I think. ~
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Multiple-ANOVA-tests-tp23739615p23741437.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] Problem with adding labels in ggplot2

2009-05-27 Thread Zeljko Vrba
On Wed, May 27, 2009 at 01:40:52PM +0200, Zeljko Vrba wrote:
>
> I apologize for not pasting a complete example, but the data-set is too large,
> so I hope someone can help me just by description of symptoms. 
> 
-snip-

I have solved the problem by introducing an artificial variable in the original
plot specification and plotting the data using the %+% operator, e.g.:

p.b4.idletime <- p.b4.generic.wg %+%
  within(b4.all.medians.8, { y <- v.idletime }) +
ylab("Idle time (s)")

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


Re: [R] split strings

2009-05-27 Thread Monica Pisica

Hi,
 
Luckily for me - until now i did not have too many times to do these type of 
parsing - but who knows???  Up to now i was pretty happy with strsplit 
.Anyway - thanks again for all the help, i really appreciate it.
 
Monica


> From: ggrothendi...@gmail.com
> Date: Tue, 26 May 2009 16:40:21 -0400
> Subject: Re: [R] split strings
> To: waclaw.marcin.kusnierc...@idi.ntnu.no
> CC: pisican...@hotmail.com; r-help@r-project.org
>
> Although speed is really immaterial here this is likely
> to be faster than all shown so far:
>
> sub(".tif", "", basename(metr_list), fixed = TRUE)
>
> It does not allow file names with .tif in the middle
> of them since it will delete the first occurrence rather
> than the last but such a situation is highly unlikely.
>
>
> On Tue, May 26, 2009 at 4:24 PM, Wacek Kusnierczyk
> wrote:
>> Monica Pisica wrote:
>>> Hi everybody,
>>>
>>> Thank you for the suggestions and especially the explanation Waclaw 
>>> provided for his code. Maybe one day i will be able to wrap my head around 
>>> this.
>>>
>>> Thanks again,
>>>
>>
>> you're welcome. note that if efficiency is an issue, you'd better have
>> perl=TRUE there:
>>
>> output = sub('.*//(.*)[.]tif$', '\\1', input, perl=TRUE)
>>
>> with perl=TRUE, the one-pass solution is somewhat faster than the
>> two-pass solution of gabor's -- which, however, is probably easier to
>> understand; with perl=FALSE (the default), the performance drops:
>>
>> strings = sprintf(
>> 'f:/foo/bar//%s.tif',
>> replicate(1000, paste(sample(letters, 10), collapse='')))
>> library(rbenchmark)
>> benchmark(columns=c('test', 'elapsed'), replications=1000, order=NULL,
>> 'one-pass, perl'=sub('.*//(.*)[.]tif$', '\\1', strings, perl=TRUE),
>> 'two-pass, perl'=sub('.tif$', '', basename(strings), perl=TRUE),
>> 'one-pass, no perl'=sub('.*//(.*)[.]tif$', '\\1', strings,
>> perl=FALSE),
>> 'two-pass, no perl'=sub('.tif$', '', basename(strings), perl=FALSE))
>> # 1 one-pass, perl 3.391
>> # 2 two-pass, perl 4.944
>> # 3 one-pass, no perl 18.836
>> # 4 two-pass, no perl 5.191
>>
>> vQ
>>
>>
>>>
>>> Monica
>>>
>>> 
>>>
 Date: Tue, 26 May 2009 15:46:21 +0200
 From: waclaw.marcin.kusnierc...@idi.ntnu.no
 To: pisican...@hotmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] split strings

 Monica Pisica wrote:

> Hi everybody,
>
> I have a vector of characters and i would like to extract certain parts. 
> My vector is named metr_list:
>
> [1] "F:/Naval_Live_Oaks/2005/data//BE.tif"
> [2] "F:/Naval_Live_Oaks/2005/data//CH.tif"
> [3] "F:/Naval_Live_Oaks/2005/data//CRR.tif"
> [4] "F:/Naval_Live_Oaks/2005/data//HOME.tif"
>
> And i would like to extract BE, CH, CRR, and HOME in a different vector 
> named "names.id"
>
 one way that seems reasonable is to use sub:

 output = sub('.*//(.*)[.]tif$', '\\1', input)

 which says 'from each string remember the substring between the
 rigthmost two slashes and a .tif extension, exclusive, and replace the
 whole thing with the captured part'. if the pattern does not match, you
 get the original input:

 sub('.*//(.*)[.]tif$', '\\1', 'f:/foo/bar//buz.tif')
 # buz

 vQ

>>> _
>>
>>

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


Re: [R] moving from Windows to Linux - need help

2009-05-27 Thread Millo Giovanni
Dear Robert,
a different option, just to give you one more choice: you should be able
to keep the standard Xandros and install R if you don't feel like
changing the operating system. You just have to add the standard Debian
repositories. I found it easier to have R, Emacs and LaTeX working on
the standard system first, before experimenting with other distros.

Memorandum, just in case: I've been there a few months ago so I know
where a Windows useR is like to stumble ;^) (if you already know this,
just skip): in Linux you don't download "setup.exe" files and execute
them to install things as you would on Windows: there are different
systems. Programs are supposed to be downloaded from standard
repositories over the Internet and installed by special software, which
may vary across Linux distributions. 

Xandros is Debian-like and the wonderful packaging system of Debian (and
Ubuntu, and Mepis...) works there as well, resolving all package
dependencies for you. There are three tools available, two command-line
driven (apt-get and aptitude) and a graphical one (Synaptic). All three
do the same job. These tools already have predefined repositories, which
you may alter. 

The Xandros repositories only have old versions of R if at all, so you'd
better add the Debian ones (but be careful to either 1) disable them
afterwards or better 2) to 'pin' them (=assign them different
priorities), else you could damage your system by downloading other
Debian packages instead of the Xandros ones in cases when this does
*not* work). R from the Debian repos. works fine on Xandros but some
other programs might screw your system up.

So all you have to do is just open up a terminal window (CTRL+ALT+T) and
do

sudo apt-get install 

('sudo' you need to act as administrator)
In particular, quoting from the R-Wiki, "if you just want to be 
able to run R, you can get r-base-core and all the recommended packages 
by doing: 

sudo apt-get install r-base 

If you want to be able to build and install R packages (including those 
from CRAN), you can get all the common header files, as well as 
r-base-core by doing: 

sudo apt-get install r-base-dev 

If you want to be able to build R from its source code, you can get 
build dependencies for R (e.g., compilers, header files) by doing: 

sudo apt-get build-dep r-base"

Of course you can download the same packages with Synaptic (but start it
as 'sudo Synaptic', for the above reasons! else you don't have rights to
install anything).

You can find much more detailed step by step instructions from some
other people put together in this old post of mine:
http://www.nabble.com/R-on-an-ASUS-eee-PC,-continued---installing-packag
es-td17862000.html

The same principles apply, e.g., for LaTeX and Emacs if you need them.
Have fun!
Giovanni

## original message ##
--

Message: 8
Date: Tue, 26 May 2009 12:56:39 +0200
From: Paul Hiemstra 
Subject: Re: [R] moving from Windows to Linux - need help
To: Robert Kinley 
Cc: r-help@r-project.org
Message-ID: <4a1bcae7.8010...@geo.uu.nl>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi Robert,

I had the exact same problem on my eeepc 900. I replaced the 
xandros-like linux in this way:

- Download an Ubuntu iso file (I use 8.04, Kubuntu)
- Put the .iso file on a usb stick (use unetbootin)
- Install the ubuntu version
- Install the eeepc specific stuff from http://array.org/ubuntu/ (this 
is a repository with an eeepc kernel available and other stuff, the site

provides a lot of info on how to install the eeepc specific things)

Now you have a "normal" linux distro (ubuntu) and you can use the normal

cran repositories (debian) to install R.

This worked very well for me, it was quite easy to get ubuntu running. I

know that this isn't an exact answer to your question, but I found that 
re installing linux was the best option.

cheers and hth,
Paul

Robert Kinley wrote:
> hi
>
> I've used R for many years on windows machines, but
> have now acquired an Asus eee 1000 linux machine.
>
> In order to get the best out of the machine, I used the
> 'pimpmyeee.sh' script, to get the full KDE desktop.
>
> The version of Linux is Xandros, which I believe is
> a close relative of Debian, but sadly I have only a
> nodding acquaintance with Linux at present.
>
> Naturally I want to have the current version of R on it,
> and I understand (or possibly misunderstand) that the
> binary for the Debian flavour of Linux should do the trick.
>
> I have tried -
>
> 1. using synaptic to add the appropriate (I think) CRAN 
> repository  ... but every combination I have tried
> gives a 404 error
>
> 2. downloading from CRAN what I think is a zipped-up version of 
> r-base software, and thewn using the eee's file-manager 
> 'install DEB package' option ... but this returns 'cannot load ...

> '.
>
>
> I'm a bit stuck ... can anyone help please ?
>
>
> thanks  Bob Kinley
>   [[alternative HTML version deleted]]

Re: [R] Multivariate Transformations

2009-05-27 Thread stephen sefick
It depends on what you are after.  I am by no means a wunderkind when
it comes to transformation, but in the package vegan type
?wisconsin
and that should give you a start,  but if you know what
transformations you would like to preform then apply should do what
you need with whatever transformation you are trying to use.

Stephen Sefick

On Wed, May 27, 2009 at 5:26 AM, Hollix  wrote:
>
> Hello folks,
>
> many multivariate anayses (e.g., structural equation modeling) require
> multivariate normal distributions.
> Real data, however, most often significantly depart from the multinormal
> distribution. Some researchers (e.g., Yuan et al., 2000) have proposed a
> multivariate transformation of the variables.
>
> Can you tell me, if and how such a transformation can be handeled in R?
>
> Thanks in advance.
> With best regards
> Holger
>
>
> ---
> Yuan, K.-H., Chan, W., & Bentler, P. M. (2000). Robust transformation with
> applications to structural equation modeling. British Journal of
> Mathematical and Statistical Psychology, 53, 31–50.
> --
> View this message in context: 
> http://www.nabble.com/Multivariate-Transformations-tp23739013p23739013.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.
>



-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

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


Re: [R] C4.5 implementation in R

2009-05-27 Thread Lazy Tiger

Thanks Tony. I will look into it.



Tony Breyal wrote:
> 
> I think Rweka implements the C4.5 (revision 8) algorithm, but it calls
> it J4.8 (because it's written in Java instead of C, and also the
> revision number, and is uses an open source licence, i think).
> 
> You might want to look at this paper by Schauerhuber, Zeileis & Hornik
> called 'Benchmarking Open-Source Tree Learners in R/RWeka':
> 
> http://epub.wu-wien.ac.at/dyn/virlib/wp/eng/mediate/epub-wu-01_bd8.pdf?ID=epub-wu-01_bd8
> 
> otherwise, try: http://cran.r-project.org/web/views/MachineLearning.html
> 
> Hope that helps a little bit, i've been meaning to have a play around
> with that package myself actually, just need to find the time :D
> 
> Tony
> 
> 
> 
> On 27 May, 07:39, Lazy Tiger  wrote:
>> Greetings,
>>
>> Does anyone know if the C4.5 algorithm is already implemented in R? If
>> yes,
>> please let me know the package. Thanks.
>> --
>> View this message in
>> context:http://www.nabble.com/C4.5-implementation-in-R-tp23736785p23736785.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> r-h...@r-project.org mailing
>> listhttps://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting
>> guidehttp://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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/C4.5-implementation-in-R-tp23736785p23740177.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] Sort matrix by column 1 ascending then by column 2 decending

2009-05-27 Thread Paul Geeleher
I've got a matrix with 2 columns and n rows. I need to sort it first
by the values in column 1 ascending. Then for values which are the
same in column 1, sort by column 2 decending. For example:

2 .5
1 .3
1 .5
3 .2

Goes to:

1 .5
1 .3
2 .5
3 .2

This is easy to do in spreadsheet programs but I can't seem to work
out how to do it in R and haven't been able to find a solution
anywhere.


Thanks!

-Paul.

-- 
Paul Geeleher
School of Mathematics, Statistics and Applied Mathematics
National University of Ireland
Galway
Ireland

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Warning message as a result of logistic regression performed

2009-05-27 Thread Winter, Katherine
I am sorry if this question sounds basic but I am having trouble understanding 
a warning message I have been receiving in R after attempting logistic 
regression.

I have been using the logistic regression function in R to analyse a simulated 
data set. The dependent variable "failure" has an outcome of either 0 (success) 
or 1 (failure). Both the independent variables have been previously generated 
in a mathematical model and stored in a data.frame for analysis. I am currently 
using a sample size of 1000 and I use the following commands in R:

   log.reg.1 <- glm(failure ~ age +weight +init.para.log.value 
+k.d1,family=binomial(logit), data=test)
log.reg.1.summary <- summary(log.reg.1); print(log.reg.1.summary)
log.reg.1.exp <- exp(log.reg.1$coef); print(log.reg.1.exp)

When I execute these commands I get the following warning message: 

"In glm.fit(x = X, y = Y, weights = weights, start = start, etastart = 
etastart,  :fitted probabilities numerically 0 or 1 occurred"

I am unsure what this warning is referring to. I have tried using google to 
answer this question but have had no luck. 

I have been on the following website 
https://stat.ethz.ch/pipermail/r-sig-ecology/2008-July/000278.html but found it 
was not helpful as I when I ran the example given I received no warning message 
(I am using R version 2.8.1). 

I am working with simulated data so there are no missing values in the data set.

I have also looked at the following website 
http://tolstoy.newcastle.edu.au/R/help/05/07/7759.html they suggest that the 
warning is as a result of "perfect separation" of the results (a possibility 
with simulated data). However, when I added an extra row to my data.frame of 
results that I knew to be false and hence to prevent "perfect separation" 
subsequent logistic regression still resulted in the same warning message. 

I am still at a loss as to the meaning of this message and any help in 
understanding this warning would be much appreciated.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] r-plot

2009-05-27 Thread Jim Lemon

durden10 wrote:

Dear R-community

I have a grueling problem which appears to be impossible to solve:
I want to make a simple plot, here is my code: http://gist.github.com/118550
Unfortunately, the annotation of both the x- and y-axis are not correct, as
you can see in the following picture: 
http://www.nabble.com/file/p23739356/plot.png 
I am not an expert of R, so maybe someone can point me to the solution of

this problem, i.e. both of the axes should start and end at the min / max
values of the two vectors.

  

Hi Durden,
This example seems to work for me. Is it just the X and Y axis labels 
that you want?


data_corr<-data.frame(
Win=c(-0.08,-0.07,-0.01,-0.01,0.03,0.08,0.1,0.13,
 0.18,0.19,0.195,0.2,0.28,0.3,0.4),
Calgary=c(11,7,5,4,3,8,6,7,3,2,1,8,0,1,3)
)
par(tcl=0.35,xaxs="r") # Switch tick marks to insides of axes
plot(data_corr, type = "p", xlab="VS signal change",
ylab="Depression scale",axes=FALSE, col = "blue", lwd = 2)
#y-axis
axis(2, tcl=0.35,at=0:11)
#x-axis
test2<-seq(0,0.4,by=0.1)
axis(1, tcl=0.35,at=test2)
box()
abline(lm(data_corr[,2]~data_corr[,1]))

Jim

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


Re: [R] Multiple ANOVA tests

2009-05-27 Thread Mike Lawrence
you could use ldply from the plyr package:

p = ldply(q,function(x){x$P})

Without you data I can't confirm that works, but something like that
should do it

On Wed, May 27, 2009 at 9:23 AM, Imri  wrote:
>
> Thanks for the answer!!!
> I Know how to extract the Pr(>F) value from single ANOVA table, but I have a
> list of many ANOVA tables recived by :
> a<-function(x)(aov(MPH~x))
> q<-apply(assoc[,18:20],2,a) # just for example, I have more than 3
> factors(x)
>
>> print(q)
> $X11_20502
>             Df  Sum Sq Mean Sq F value    Pr(>F)
> x             3   369.9   123.3   6.475 0.0002547 ***
> Residuals   635 12093.2    19.0
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 246 observations deleted due to missingness
>
> $X11_21067
>             Df  Sum Sq Mean Sq F value Pr(>F)
> x             1    26.7    26.7  1.3662 0.2429
> Residuals   637 12436.4    19.5
> 246 observations deleted due to missingness
>
> $X11_10419
>             Df  Sum Sq Mean Sq F value    Pr(>F)
> x             3   527.8   175.9   9.361 4.621e-06 ***
> Residuals   635 11935.3    18.8
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 246 observations deleted due to missingness
>
>> summary(q)
>          Length Class       Mode
> X11_20502 1      summary.aov list
> X11_21067 1      summary.aov list
> X11_10419 1      summary.aov list
>  How can I extract all the Pr(>F) values from q (not one by one)?
>
> Thanks
> Imri
>
>
>
> Mike Lawrence wrote:
>>
>> #create some data
>> y=rnorm(20)
>> x=factor(rep(c('A','B'),each=10))
>>
>> #run the anova
>> my_aov = aov(y~x)
>>
>> #summarize the anova
>> my_aov_summary = summary(my_aov)
>>
>> #show the anova summary
>> print(my_aov_summary)
>>
>> #lets see what's in the summary object
>> str(my_aov_summary)
>>
>> #looks like it's a list with 1 element which
>> #in turn is a data frame with columns.
>> #The "Pr(>F)" column looks like what we want
>> my_aov_summary[[1]]$P
>>
>> #yup, that's it. Grab the first value
>> p = my_aov_summary[[1]]$P[1]
>>
>>
>> On Wed, May 27, 2009 at 7:11 AM, Imri  wrote:
>>>
>>> Hi all -
>>> I'm trying to do multiple one-way ANOVA tests of different factors on the
>>> same variable. As a result I have a list with all the ANOVA tables, for
>>> exemple:
>>>
>>> $X11_20502
>>> Analysis of Variance Table
>>>
>>> Response: MPH
>>>           Df  Sum Sq Mean Sq F value    Pr(>F)
>>> x           3   369.9   123.3   6.475 0.0002547 ***
>>> Residuals 635 12093.2    19.0
>>> ---
>>> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>>>
>>> $X11_21067
>>> Analysis of Variance Table
>>>
>>> Response: MPH
>>>           Df  Sum Sq Mean Sq F value Pr(>F)
>>> x           1    26.7    26.7  1.3662 0.2429
>>> Residuals 637 12436.4    19.5
>>>
>>> $X11_10419
>>> Analysis of Variance Table
>>>
>>> Response: MPH
>>>           Df  Sum Sq Mean Sq F value    Pr(>F)
>>> x           3   527.8   175.9   9.361 4.621e-06 ***
>>> Residuals 635 11935.3    18.8
>>> ---
>>> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>>>
>>> My question is how can I extract from this list, just the Pr(>F) values
>>> for
>>> each x ?
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Multiple-ANOVA-tests-tp23739615p23739615.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.
>>>
>>
>>
>>
>> --
>> Mike Lawrence
>> Graduate Student
>> Department of Psychology
>> Dalhousie University
>>
>> Looking to arrange a meeting? Check my public calendar:
>> http://tr.im/mikes_public_calendar
>>
>> ~ Certainty is folly... I think. ~
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
> --
> View this message in context: 
> http://www.nabble.com/Multiple-ANOVA-tests-tp23739615p23741437.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.
>



-- 
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tr.im/mikes_public_calendar

~ Certainty is folly... I think. ~

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

Re: [R] Harmonic Analysis

2009-05-27 Thread stephen sefick
why will a fourier transform not work?
2009/5/27 Uwe Ligges :
>
>
> Dieter Menne wrote:
>>
>>   alice.it> writes:
>>
>>> I am looking for a package to perform harmonic analysis with the goal of
>>> estimating the period of the
>>> dominant high frequency component in some mono-channel signals.
>>
>> You should widen your scope by looking a "time series" instead of harmonic
>> analysis. There is a task view on the subject at
>>
>> http://cran.at.r-project.org/web/views/TimeSeries.html
>
>
> ... or take a look at package tuneR.
>
> Uwe Ligges
>
>
>
>
>> Dieter
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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.
>



-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

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


Re: [R] Sort matrix by column 1 ascending then by column 2 decending

2009-05-27 Thread Henrique Dallazuanna
Try this:

cbind(sort(x[,1]), unlist(tapply(x[,2], x[,1], sort, decreasing = T)))

On Wed, May 27, 2009 at 9:39 AM, Paul Geeleher wrote:

> I've got a matrix with 2 columns and n rows. I need to sort it first
> by the values in column 1 ascending. Then for values which are the
> same in column 1, sort by column 2 decending. For example:
>
> 2 .5
> 1 .3
> 1 .5
> 3 .2
>
> Goes to:
>
> 1 .5
> 1 .3
> 2 .5
> 3 .2
>
> This is easy to do in spreadsheet programs but I can't seem to work
> out how to do it in R and haven't been able to find a solution
> anywhere.
>
>
> Thanks!
>
> -Paul.
>
> --
> Paul Geeleher
> School of Mathematics, Statistics and Applied Mathematics
> National University of Ireland
> Galway
> Ireland
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

[[alternative HTML version deleted]]

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


[R] Hierarchical glm with binomial family

2009-05-27 Thread Johan Stenberg
Dear members of the R help list,

I want to do a hierarchical glm with binomial family but am unsure
about how to write the syntax which involves nesting.

I want to test whether the risk of being attacked by Herbivores for
Meadowsweet plants is significantly dependent on the Distance to
heterospecific source plants.

Dependent variable = Herbivory (yes/no)
Explanatory continuous variable = Distance to heterospecific source plant

Distance should be nested within Subpopulation which in turn should be
nested within Population.
The number of replicates per subpopulation varies between 8 and 36.
The number of subpopulations per population varies between 4 and 9.

I haven't figured out how to do nesting, but guessing that nesting is
denoted with brackets I guess the syntax should look something like
this (below). Could you please help me to correct this syntax so that
it becomes useful in R?

model<-glm(Herbivory~Distance(Subpopulation(Population)), family=binomial)

Thanks a lot! I deeply appreciate your non-profit engagement!

Johan

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


Re: [R] optim() question

2009-05-27 Thread John C Nash

Some thought about this overnight led to conclusion that a capability
to follow from one method to another could be quite useful. Moreover,
it should be pretty easy to fit it into our current trial version of 
optimx()

as we call the function. More at UseR.

JN


Ravi Varadhan wrote:
 
Stephen,


No.  Currently, AFAIK, there is no such switching algorithm for optimization
in R.  John Nash and I are working on a package for integrating various
optimization tools (for smooth, box-constrained optimization) in R.  This
will have a function that can run through multiple algorithms.  While this
is not exactly what you are asking for, it can be quite useful for your
purposes, which I assume is to find a local optimum in a reliable fashion.

Ravi.

...
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Stephen Collins
Sent: Tuesday, May 26, 2009 2:48 PM
To: r-h...@stat.math.ethz.ch
Subject: [R] optim() question

I've seen with other software the capability for the optimizer to switch
algorithms if it is not making progress between iterations.  Is this
capability available in optim()?

Thanks,
 
Stephen Collins, MPP | Analyst

Health & Benefits | Aon Consulting



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


Re: [R] Harmonic Analysis

2009-05-27 Thread Gerard M. Keogh
My thoughts exactly.

?FFT should do the job.

And define the dominant term - a_n**2 + b_n**2 - the Parseval Relation.



   
 stephen sefick
  To 
 Sent by:  r-h...@stat.math.ethz.ch
 r-help-boun...@r-  cc 
 project.org   
   Subject 
   Re: [R] Harmonic Analysis   
 27/05/2009 13:58  
   
   
   
   
   




why will a fourier transform not work?
2009/5/27 Uwe Ligges :
>
>
> Dieter Menne wrote:
>>
>>   alice.it> writes:
>>
>>> I am looking for a package to perform harmonic analysis with the goal
of
>>> estimating the period of the
>>> dominant high frequency component in some mono-channel signals.
>>
>> You should widen your scope by looking a "time series" instead of
harmonic
>> analysis. There is a task view on the subject at
>>
>> http://cran.at.r-project.org/web/views/TimeSeries.html
>
>
> ... or take a look at package tuneR.
>
> Uwe Ligges
>
>
>
>
>> Dieter
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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.
>



--
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.


   -K. Mullis

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



**
The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential and/or privileged material. Any 
review, retransmission, dissemination or other use of, or taking of any action 
in reliance upon, this information by persons or entities other than the 
intended recipient is prohibited. If you received this in error, please contact 
the sender and delete the material from any computer.  It is the policy of the 
Department of Justice, Equality and Law Reform and the Agencies and Offices 
using its IT services to disallow the sending of offensive material.
Should you consider that the material contained in this message is offensive 
you should contact the sender immediately and also mailminder[at]justice.ie.

Is le haghaidh an duine nó an eintitis ar a bhfuil sí dírithe, agus le haghaidh 
an duine nó an eintitis sin amháin, a bheartaítear an fhaisnéis a tarchuireadh 
agus féadfaidh sé go bhfuil ábhar faoi rún agus/nó faoi phribhléid inti. 
Toirmisctear aon athbhreithniú, atarchur nó leathadh a dhéanamh ar an 
bhfaisnéis seo, aon úsáid eile a bhaint aisti nó aon ghníomh a dhéanamh ar a 
hiontaoibh, ag daoine nó ag eintitis seachas an faighteoir beartaithe. Má fuair 
tú é seo trí dhearmad, téigh i dteagmháil leis an seoltóir, le do thoil, agus 
scrios an t-ábhar as aon ríomhaire. Is é beartas na Roinne Dlí agus Cirt, 
Comhionannais agus Athchóirithe Dlí, agus na nOifígí agus na nGníomhaireachtaí 
a úsáideann seirbhísí TF na Roinne, seoladh ábhair cholúil a dhícheadú.
Más rud é go measann tú gur ábhar colúil atá san ábhar atá sa teachtaireacht 
seo is ceart duit dul i dteagmháil leis an seoltóir láithreach agus le 
mailminder[ag]justice.ie chomh maith. 
***



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

Re: [R] How to write a loop?

2009-05-27 Thread Andrew Dolman
Try

lapply(ONS, fft)

and take a look here http://cran.r-project.org/doc/manuals/R-intro.html for
the basics of data structures in R and how to apply functions to them.


Andy.



andydol...@gmail.com


2009/5/27 Linlin Yan 

> Why did you use different variable names rather than index of
> list/data.frame?
>
> On Wed, May 27, 2009 at 6:34 PM, Maithili Shiva
>  wrote:
> > Dear R helpers,
> >
> > Following is a R script I am using to run the Fast Fourier Transform. The
> csv files has 10 columns with titles m1, m2, m3 .m10.
> >
> > When I use the following commands, I am getting the required results. The
> probelm is if there are 100 columns, it is not wise to define 100 commands
> as fk <- ONS$mk and so on. Thus, I need some guidance to write the loop for
> the STEP A and STEP B.
> >
> > Thanking in advance
> >
> > Regards
> >
> > Maithili
> >
> >
> >
> > My R Script
> >
> >
> ---
> >
> > ONS <- read.csv("fast fourier transform.csv", header = TRUE)
> >
> >   # STEP A
> >
> >   f1 <- ONS$m1
> >
> >   f2 <- ONS$m2
> >
> >   f3 <- ONS$m3
> >
> >   f4 <- ONS$m4
> >
> >   f5 <- ONS$m5
> >
> >   f6 <- ONS$m6
> >
> >   f7 <- ONS$m7
> >
> >   f8 <- ONS$m8
> >
> >   f9 <- ONS$m9
> >
> >   f10 <- ONS$m10
> >
> >
> #
> >
> >
> >   # STEP B
> >
> >   g1 <- fft(f1)
> >
> >   g2 <- fft(f2)
> >
> >   g3 <- fft(f3)
> >
> >   g4 <- fft(f4)
> >
> >   g5 <- fft(f5)
> >
> >   g6 <- fft(f6)
> >
> >   g7 <- fft(f7)
> >
> >   g8 <- fft(f8)
> >
> >   g9 <- fft(f9)
> >
> >   g10 <- fft(f10)
> >
> >
> >
> #
> >
> >   h <- g1*g2*g3*g4*g5*g6*g7*g8*g9*g10
> >
> >   j <- fft((h), inverse = TRUE)/length(h)
> >
> >
> >
> #
> >
> >
> >
> >
> >  Cricket on your mind? Visit the ultimate cricket website. Enter
> http://beta.cricket.yahoo.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.
>

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

2009-05-27 Thread Prof Brian Ripley

Are you looking for file.rename?

Moving files is not really a portable concept, and nor is 'time 
stamps' (files usually have three or more times associated with them, 
and moving does not keep them all in OSes that implement it).


On Wed, 27 May 2009, Stefan Uhmann wrote:


Dear list,

I want to move some files that should keep their time stamps, which is not 
the case if I use file.copy in combination with file.remove. file.move would 
be nice, is there a package providing such a function?


Regards,
Stefan


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


Re: [R] Sort matrix by column 1 ascending then by column 2 decending

2009-05-27 Thread Paul Geeleher
Nice. Works perfectly.

On Wed, May 27, 2009 at 2:03 PM, Henrique Dallazuanna  wrote:
> Try this:
>
> cbind(sort(x[,1]), unlist(tapply(x[,2], x[,1], sort, decreasing = T)))
>
> On Wed, May 27, 2009 at 9:39 AM, Paul Geeleher 
> wrote:
>>
>> I've got a matrix with 2 columns and n rows. I need to sort it first
>> by the values in column 1 ascending. Then for values which are the
>> same in column 1, sort by column 2 decending. For example:
>>
>> 2 .5
>> 1 .3
>> 1 .5
>> 3 .2
>>
>> Goes to:
>>
>> 1 .5
>> 1 .3
>> 2 .5
>> 3 .2
>>
>> This is easy to do in spreadsheet programs but I can't seem to work
>> out how to do it in R and haven't been able to find a solution
>> anywhere.
>>
>>
>> Thanks!
>>
>> -Paul.
>>
>> --
>> Paul Geeleher
>> School of Mathematics, Statistics and Applied Mathematics
>> National University of Ireland
>> Galway
>> Ireland
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>



-- 
Paul Geeleher
School of Mathematics, Statistics and Applied Mathematics
National University of Ireland
Galway
Ireland

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

2009-05-27 Thread utkarshsinghal

I define the following function:
(Please don't wonder about the use of this function, this is just a 
simplified version of my actual function. And please don't spend your 
time in finding an alternate way of doing the same as the following does 
not exactly represent my function. I am only interested in a good 
explanation)


> f1 = function(x,ties.method="average")rank(x,ties.method)
> f1(c(1,1,2,4), ties.method="min")
[1] 1.5 1.5 3.0 4.0

I don't know why it followed ties.method="average".
Anyways I randomly tried the following:

> f2 = function(x,ties.method="average")rank(x,ties.method=ties.method)
> f2(c(1,1,2,4), ties.method="min")
[1] 1 1 3 4
Now, it follows the ties.method="min"

I don't see any explanation for this, however, I somehow mugged up that 
if I define it as in "f1", the ties.method in rank function takes its 
default value which is "average" and if I define as in "f2", it takes 
the value which is passed in "f2".


But even all my mugging is wasted when I tested the following:

> h = function(x, a=1)x^a
> g1 = function(x, a=1)h(x,a)
> g1(x=5, a=2)
[1] 25

> g2 = function(x, a=1)h(x,a=a)
> g2(x=5, a=2)
[1] 25

Here in both the cases, "h" is taking the value passed through "g1", and 
"g2".


Any comments/hints can  be helpful.

Regards
Utkarsh

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


Re: [R] Hierarchical glm with binomial family

2009-05-27 Thread Ben Bolker



Johan Stenberg-2 wrote:
> 
> Dear members of the R help list,
> 
> I want to do a hierarchical glm with binomial family but am unsure
> about how to write the syntax which involves nesting.
> 
> I want to test whether the risk of being attacked by Herbivores for
> Meadowsweet plants is significantly dependent on the Distance to
> heterospecific source plants.
> 
> Dependent variable = Herbivory (yes/no)
> Explanatory continuous variable = Distance to heterospecific source plant
> 
> Distance should be nested within Subpopulation which in turn should be
> nested within Population.
> The number of replicates per subpopulation varies between 8 and 36.
> The number of subpopulations per population varies between 4 and 9.
> 
> I haven't figured out how to do nesting, but guessing that nesting is
> denoted with brackets I guess the syntax should look something like
> this (below). Could you please help me to correct this syntax so that
> it becomes useful in R?
> 
> model<-glm(Herbivory~Distance(Subpopulation(Population)), family=binomial)
> 
> 

You probably need a GLMM (generalized linear mixed model), which is
a little bit of a can of worms.  If so, you will need the "glmer" function
inside the "lmer" package.

  I'm not entirely clear about your experimental design: I understand
that subpopulations are nested within populations, but it's not clear
whether covariates (distances to heterospecific plants) differ within
subpopulations or populations.

  If they don't differ with subpopulations, I would (strongly) recommend
aggregating the
values within subpopulations and analyzing proportions as a regression
analysis:
see Murtaugh, Paul A. “SIMPLICITY AND COMPLEXITY IN ECOLOGICAL
 DATA ANALYSIS.” Ecology 88, no. 1 (2007): 56-62.

  If they do, then your design is

model<-glmer(Herbivory~Distance+(1|Population/Subpopulation),
family=binomial)

  See also:

https://stat.ethz.ch/pipermail/r-sig-mixed-models/2009q2/002320.html
https://stat.ethz.ch/pipermail/r-sig-mixed-models/2009q2/002335.html
-- 
View this message in context: 
http://www.nabble.com/Hierarchical-glm-with-binomial-family-tp23742335p23743418.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] Warning message as a result of logistic regression performed

2009-05-27 Thread Gavin Simpson
Try reading this thread:

http://thread.gmane.org/gmane.comp.lang.r.general/134368/focus=134475

especially the posts by I Kosmidis which show you how to diagnose
problems in logit model fits like this.

There is a statement about this warning in ?glm as well and a pointer to
a reference which discusses a source of the warning.

G

On Wed, 2009-05-27 at 11:22 +0100, Winter, Katherine wrote:
> I am sorry if this question sounds basic but I am having trouble 
> understanding a warning message I have been receiving in R after attempting 
> logistic regression.
> 
> I have been using the logistic regression function in R to analyse a 
> simulated data set. The dependent variable "failure" has an outcome of either 
> 0 (success) or 1 (failure). Both the independent variables have been 
> previously generated in a mathematical model and stored in a data.frame for 
> analysis. I am currently using a sample size of 1000 and I use the following 
> commands in R:
> 
>log.reg.1 <- glm(failure ~ age +weight +init.para.log.value 
> +k.d1,family=binomial(logit), data=test)
>   log.reg.1.summary <- summary(log.reg.1); print(log.reg.1.summary)
>   log.reg.1.exp <- exp(log.reg.1$coef); print(log.reg.1.exp)
> 
> When I execute these commands I get the following warning message: 
> 
> "In glm.fit(x = X, y = Y, weights = weights, start = start, etastart = 
> etastart,  :fitted probabilities numerically 0 or 1 occurred"
> 
> I am unsure what this warning is referring to. I have tried using google to 
> answer this question but have had no luck. 
> 
> I have been on the following website 
> https://stat.ethz.ch/pipermail/r-sig-ecology/2008-July/000278.html but found 
> it was not helpful as I when I ran the example given I received no warning 
> message (I am using R version 2.8.1). 
> 
> I am working with simulated data so there are no missing values in the data 
> set.
> 
> I have also looked at the following website 
> http://tolstoy.newcastle.edu.au/R/help/05/07/7759.html they suggest that the 
> warning is as a result of "perfect separation" of the results (a possibility 
> with simulated data). However, when I added an extra row to my data.frame of 
> results that I knew to be false and hence to prevent "perfect separation" 
> subsequent logistic regression still resulted in the same warning message. 
> 
> I am still at a loss as to the meaning of this message and any help in 
> understanding this warning would be much appreciated.
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



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


Re: [R] Multivariate Transformations

2009-05-27 Thread Gavin Simpson
On Wed, 2009-05-27 at 08:39 -0400, stephen sefick wrote:
> It depends on what you are after.  I am by no means a wunderkind when
> it comes to transformation, but in the package vegan type
> ?wisconsin
> and that should give you a start,  but if you know what
> transformations you would like to preform then apply should do what
> you need with whatever transformation you are trying to use.

decostand provides (mostly) standardisations not transformations, it
even says so. What Holger is looking for is something like a Box Cox
transform for bivariate normality but to instead achieve multivariate
normality. That is a different kettle of fish to what decostand tries to
do.

HTH

G

> 
> Stephen Sefick
> 
> On Wed, May 27, 2009 at 5:26 AM, Hollix  wrote:
> >
> > Hello folks,
> >
> > many multivariate anayses (e.g., structural equation modeling) require
> > multivariate normal distributions.
> > Real data, however, most often significantly depart from the multinormal
> > distribution. Some researchers (e.g., Yuan et al., 2000) have proposed a
> > multivariate transformation of the variables.
> >
> > Can you tell me, if and how such a transformation can be handeled in R?
> >
> > Thanks in advance.
> > With best regards
> > Holger
> >
> >
> > ---
> > Yuan, K.-H., Chan, W., & Bentler, P. M. (2000). Robust transformation with
> > applications to structural equation modeling. British Journal of
> > Mathematical and Statistical Psychology, 53, 31–50.
> > --
> > View this message in context: 
> > http://www.nabble.com/Multivariate-Transformations-tp23739013p23739013.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.
> >
> 
> 
> 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



signature.asc
Description: This is a digitally signed message part
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 exclude a column by name?

2009-05-27 Thread Stavros Macrakis
On Wed, May 27, 2009 at 6:37 AM, Zeljko Vrba  wrote:

> Given an arbitrary data frame, it is easy to exclude a column given its
> index:
> df[,-2].  How to do the same thing given the column name?  A naive attempt
> df[,-"name"] did not work :)
>

Various ways:

Boolean index vector:

df[ , names(df) != "name" ]

List of wanted column names:

df[ , setdiff(names(df), "name") ]

Negated list of unwanted column indexes:

   df[ , -match("name",names(df)) ]
   df[ , -which(names(df) == "name") ]

The special 'subset' hack for column names; beware, I think this is the only
place in R where you can negate a column name.

   subset(df , select = -a )

Hope this helps,

 -s

[[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] Neural Network resource

2009-05-27 Thread Indrajit Sengupta
You are right there is a pdf file which describes the function. But let tell 
you where I am coming from.

Just to test if a neural network will work better than a ordinary least square 
regression, I created a dataset with one dependent variable and 6 other 
independent variables. Now I had deliberately created the dataset in such 
manner that we have an excellent regression model. Eg: Y = b0 + b1*x1 + b2*x2 + 
b3*x3.. + b6*x6 + e
where e is normal random variable. Naturally any statistical analysis system 
running regression would easily predict the values of b1, b2, b3, ..., b6 with 
around 30-40 observations.

I fed this data into a Neural network (3 hidden layers with 6 neurons in each 
layer) and trained the network. When I passed the input dataset and tried to 
get the predictions, all the predicted values were identical! This confused me 
a bit and was wondering whether my understanding of the Neural Network was 
wrong.

Have you ever faced anything like it?

Regards,
Indrajit




From: "markle...@verizon.net" 

Sent: Wednesday, May 27, 2009 7:54:59 PM
Subject: Re: [R] Neural Network resource

Hi: I've never used that package but most likely there is a  AMORE vignette 
that shows examples and describes the functions.
it should be on the same cran  web page where the package resides, in pdf form.






Hi All,

I am trying to learn Neural Networks. I found that R has packages which can 
help build Neural Nets - the popular one being AMORE package. Is there any book 
/ resource available which guides us in this subject using the AMORE package?

Any help will be much appreciated.

Thanks,
Indrajit

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

2009-05-27 Thread Thomas Lumley

On Wed, 27 May 2009, utkarshsinghal wrote:


I define the following function:
(Please don't wonder about the use of this function, this is just a 
simplified version of my actual function. And please don't spend your time in 
finding an alternate way of doing the same as the following does not exactly 
represent my function. I am only interested in a good explanation)



f1 = function(x,ties.method="average")rank(x,ties.method)
f1(c(1,1,2,4), ties.method="min")

[1] 1.5 1.5 3.0 4.0

I don't know why it followed ties.method="average".


Look at the arguments to rank()

args(rank)

function (x, na.last = TRUE, ties.method = c("average", "first",
"random", "max", "min"))

When you do rank(x, ties.method) you are passing "min" as the second 
argument to rank(), which is the na.last argument, not the ties.method 
argument.  This didn't give an error message because there weren't any NAs 
in your data.


You want
f1 = function(x,ties.method="average")rank(x,ties.method=ties.method)
which gives

f1(c(1,1,2,4), ties.method="min")

[1] 1 1 3 4

-thomas

Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle

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


Re: [R] Defining functions - an interesting problem

2009-05-27 Thread Gavin Simpson
On Wed, 2009-05-27 at 19:41 +0530, utkarshsinghal wrote:
> I define the following function:
> (Please don't wonder about the use of this function, this is just a 
> simplified version of my actual function. And please don't spend your 
> time in finding an alternate way of doing the same as the following does 
> not exactly represent my function. I am only interested in a good 
> explanation)
> 
>  > f1 = function(x,ties.method="average")rank(x,ties.method)
>  > f1(c(1,1,2,4), ties.method="min")
> [1] 1.5 1.5 3.0 4.0
> 
> I don't know why it followed ties.method="average".

What is the second argument of rank? It is not ties.method. You passed
"min" to na.last, not ties.method. You need to name the argument if you
are not passing in all arguments and in the correct order.

> Anyways I randomly tried the following:
> 
>  > f2 = function(x,ties.method="average")rank(x,ties.method=ties.method)
>  > f2(c(1,1,2,4), ties.method="min")
> [1] 1 1 3 4
> Now, it follows the ties.method="min"

Why randomly - ?rank tells you the argument is ties.method so you should
set it to ties.method: times.method = ties.method in your call to rank.

> 
> I don't see any explanation for this, however, I somehow mugged up that 
> if I define it as in "f1", the ties.method in rank function takes its 
> default value which is "average" and if I define as in "f2", it takes 
> the value which is passed in "f2".

Because you aren't passing ties.method as the same argument in f1 and
f2. In f1 you are passing ties.method to na.last, in f2 you do it
correctly.

> 
> But even all my mugging is wasted when I tested the following:
> 
>  > h = function(x, a=1)x^a
>  > g1 = function(x, a=1)h(x,a)
>  > g1(x=5, a=2)
> [1] 25
> 
>  > g2 = function(x, a=1)h(x,a=a)
>  > g2(x=5, a=2)
> [1] 25
> 
> Here in both the cases, "h" is taking the value passed through "g1", and 
> "g2".

Here there are only two arguments and you supplied them in the correct
place when you supplied them un-named.

HTH

G

> 
> Any comments/hints can  be helpful.
> 
> Regards
> Utkarsh
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



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


Re: [R] Defining functions - an interesting problem

2009-05-27 Thread utkarshsinghal

Yeah, seems so obvious now. What a blunder, poor me.
Perfect explanation. Thanks


Thomas Lumley wrote:

On Wed, 27 May 2009, utkarshsinghal wrote:


I define the following function:
(Please don't wonder about the use of this function, this is just a 
simplified version of my actual function. And please don't spend your 
time in finding an alternate way of doing the same as the following 
does not exactly represent my function. I am only interested in a 
good explanation)



f1 = function(x,ties.method="average")rank(x,ties.method)
f1(c(1,1,2,4), ties.method="min")

[1] 1.5 1.5 3.0 4.0

I don't know why it followed ties.method="average".


Look at the arguments to rank()

args(rank)

function (x, na.last = TRUE, ties.method = c("average", "first",
"random", "max", "min"))

When you do rank(x, ties.method) you are passing "min" as the second 
argument to rank(), which is the na.last argument, not the ties.method 
argument.  This didn't give an error message because there weren't any 
NAs in your data.


You want
f1 = function(x,ties.method="average")rank(x,ties.method=ties.method)
which gives

f1(c(1,1,2,4), ties.method="min")

[1] 1 1 3 4

-thomas

Thomas LumleyAssoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle




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


[R] R in Ubunto

2009-05-27 Thread R Heberto Ghezzo, Dr
Hello , I do not know anything abount Ubunto, but I found a Portable Ubunto for 
Windows and since so many people
prefer Linux to Windows I decided to give it a try.
It runs very nicely, so I tried to load R, following Instructions in CRAN I 
added the line
deb http://probability.ca/cran/bin/linux/ubuntu hardy/ to /etc/apt/sources.list 
and then from a console
I did
sudo apt-get update
sudo apt-get install r-base
a lot of printout and when it inishes I typed R in the console and surprise!
I got R 2.6.2!! in Windows I have R 2.9.0??
Did I do something wrong or there is another way to get the latest version of R?
Thanks for any help
Heberto Ghezzo Ph.D.
Biostatistique medical
Montreal - Canada

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


[R] vegan metaMDS question

2009-05-27 Thread stephen sefick
The design decision in metaMDS says that it uses:

Minchin, P.R. (1987) An evaluation of relative robustness of
techniques for ecological ordinations. Vegetatio 71, 145-156.

This is the paper that I found by the same name.  Is this the correct reference?

Minchin, Peter R.1987. An Evaluation of the Relative Robustness  of
Techniques for Ecological Ordination. Vegetatio. Vol. 69, No. 1/3:
89-107.

In this paper the double standardization (wisconsin()) is used then a
centering by species is preformed.  The centering by species isn't
incorporated in the metaMDS methodology, is it?  Is there a reason for
this, or am I missing something?
best regards,

-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

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


Re: [R] Neural Network resource

2009-05-27 Thread Max Kuhn
> I fed this data into a Neural network (3 hidden layers with 6 neurons in each 
> layer) and trained the network. When I passed the input dataset and tried to 
> get the predictions, all the predicted values were identical! This confused 
> me a bit and was wondering whether my understanding of the Neural Network was 
> wrong.
>
> Have you ever faced anything like it?

You should really provide code for us to help. I would initially
suspect that you didn't use a linear function between your hidden
units and the outcomes.

Also, using 3 hidden layers and 6 units per layer is a bit much for
your data set (30-40 samples). You will probably end up overfitting.

-- 

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] R in Ubunto

2009-05-27 Thread stephen sefick
I don't remember what the version of R in deb repositories is, but
2.6.2 is probably about right.  One of the things the Debian project
is focused on is the stability of the operating system, so they do not
update packages as readily as some other distributions.  I had this
with Debian 5.0 and just decided to compile R from source after
getting the R development package and some x11 development libraries.

sudo apt-get install r-base-dev


I can help you through this process if you like, or there are good
instructions for this process at the R website.

FAQ 2.5.1 How can R be installed (Unix)

On Wed, May 27, 2009 at 11:35 AM, R Heberto Ghezzo, Dr
 wrote:
> Hello , I do not know anything abount Ubunto, but I found a Portable Ubunto 
> for Windows and since so many people
> prefer Linux to Windows I decided to give it a try.
> It runs very nicely, so I tried to load R, following Instructions in CRAN I 
> added the line
> deb http://probability.ca/cran/bin/linux/ubuntu hardy/ to 
> /etc/apt/sources.list and then from a console
> I did
> sudo apt-get update
> sudo apt-get install r-base
> a lot of printout and when it inishes I typed R in the console and surprise!
> I got R 2.6.2!! in Windows I have R 2.9.0??
> Did I do something wrong or there is another way to get the latest version of 
> R?
> Thanks for any help
> Heberto Ghezzo Ph.D.
> Biostatistique medical
> Montreal - Canada
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

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

2009-05-27 Thread Dieter Menne
Peter Dalgaard  biostat.ku.dk> writes:

> Or, BTW, you can use within()
> 
> aq <- within(airquality, rm(Day))

Please add this as an example to the docs of within. 

Dieter

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


Re: [R] Defining functions - an interesting problem

2009-05-27 Thread Stavros Macrakis
The 'ties.method' argument to 'rank' is the *third* positional argument to
'rank', so either you need to put it in the third position or you need to
use a named argument.

The fact that the variable you're using to represent ties.method is called
ties.method is irrelevant.  That is, this:

  rank(x,ties.method)

is equivalent to

 rank(x, na.last = ties.method)

which is not what you want.

You need to write

 rank(x, ties.method = ties.method)

or (more concise but not as clear):

 rank(x, , ties.method)

Hope this helps,

  -s

On Wed, May 27, 2009 at 10:11 AM, utkarshsinghal <
utkarsh.sing...@global-analytics.com> wrote:

> I define the following function:
> (Please don't wonder about the use of this function, this is just a
> simplified version of my actual function. And please don't spend your time
> in finding an alternate way of doing the same as the following does not
> exactly represent my function. I am only interested in a good explanation)
>
> > f1 = function(x,ties.method="average")rank(x,ties.method)
> > f1(c(1,1,2,4), ties.method="min")
> [1] 1.5 1.5 3.0 4.0
>
> I don't know why it followed ties.method="average".
> Anyways I randomly tried the following:
>
> > f2 = function(x,ties.method="average")rank(x,ties.method=ties.method)
> > f2(c(1,1,2,4), ties.method="min")
> [1] 1 1 3 4
> Now, it follows the ties.method="min"
>
> I don't see any explanation for this, however, I somehow mugged up that if
> I define it as in "f1", the ties.method in rank function takes its default
> value which is "average" and if I define as in "f2", it takes the value
> which is passed in "f2".
>
> But even all my mugging is wasted when I tested the following:
>
> > h = function(x, a=1)x^a
> > g1 = function(x, a=1)h(x,a)
> > g1(x=5, a=2)
> [1] 25
>
> > g2 = function(x, a=1)h(x,a=a)
> > g2(x=5, a=2)
> [1] 25
>
> Here in both the cases, "h" is taking the value passed through "g1", and
> "g2".
>
> Any comments/hints can  be helpful.
>
> Regards
> Utkarsh
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] R in Ubunto

2009-05-27 Thread Jeff Newmiller

R Heberto Ghezzo, Dr wrote:

Hello , I do not know anything abount Ubunto, but I found a Portable Ubunto for 
Windows and since so many people
prefer Linux to Windows I decided to give it a try.
It runs very nicely, so I tried to load R, following Instructions in CRAN I 
added the line
deb http://probability.ca/cran/bin/linux/ubuntu hardy/ to /etc/apt/sources.list 
and then from a console
I did
sudo apt-get update
sudo apt-get install r-base
a lot of printout and when it inishes I typed R in the console and surprise!
I got R 2.6.2!! in Windows I have R 2.9.0??
Did I do something wrong or there is another way to get the latest version of R?


On the web page

  http://probability.ca/cran/bin/linux/ubuntu/

it presents instructions for activating this repository.  Special
instructions are included for hardy regarding activating backports
also.

--
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k

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

2009-05-27 Thread Luc Villandre

Dear R-users,

I have very recently started learning about object-oriented programming 
in R. I am far from being an expert in programming, although I do have 
an elementary C++ background.


Please take a look at these lines of code.

some.data = data.frame(V1 = 1:5, V2 = 6:10) ;
p.plot = ggplot(data=some.data,aes(x=V1, y=V2)) ;
class(p.plot) ;
[1] "ggplot"
My understanding is that the object p.plot belongs to the "ggplot" 
class. However, a new class definition like
setClass("AClass", representation(mFirst = "numeric", mSecond = 
"ggplot")) ;

yields the warning

Warning message:
In .completeClassSlots(ClassDef, where) :
  undefined slot classes in definition of "AClass": mSecond(class 
"ggplot")

The ggplot object is also a list :

is.list(p.plot)
[1] TRUE

So, I guess I could identify mSecond as being a list.

However, I don't understand why "ggplot" is not considered a valid slot 
type. I thought setClass() was analogous to the class declaration in 
C++, but I guess I might be wrong. Would anyone care to provide 
additional explanations about this?


I decided to explore object-oriented programming in R so that I could 
organize the output from my analysis in a more rigorous fashion and then 
define custom methods that would yield relevant output. However, I'm 
starting to wonder if this aspect is not better suited for package 
builders. R lists are already very powerful and convenient templates. 
Although it wouldn't be as elegant, I could define functions that would 
take lists outputted by the different steps of my analysis and do what I 
want with them. I'm wondering what the merits of both approaches in the 
context of R would be. If anyone has any thoughts about this, I'd be 
most glad to read them.


Cheers,
--
*Luc Villandré*
/Biostatistician
McGill University Health Center -
Montreal Children's Hospital Research Institute/

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

2009-05-27 Thread Kevin W
Having solved this problem, I am posting this so that the next time I search
for how to do this I will find an answer...

Using qqmath(..., groups=num) creates a separate qq distribution for each
group (within a panel).  Using the 'col' or 'pch' argument does not
(usually) work because panel.qqmath sorts the data (but not 'col' or 'pch')
before plotting.  Sorting the data before calling qqmath will ensure that
the sorting does not change the order of the data.

For example, to obtain one distribution per voice part and color the point
by part 1 or part 2:

library(lattice)
singer <- singer
singer <- singer[order(singer$height),]
singer$part <- factor(sapply(strsplit(as.character(singer$voice.part), split
= " "), "[", 1),
 levels = c("Bass", "Tenor", "Alto", "Soprano"))
singer$num <- factor(sapply(strsplit(as.character(singer$voice.part), split
= " "), "[", 2))
qqmath(~ height | part, data = singer,
   col=singer$num,
   layout=c(4,1))



Kevin

[[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] Hierarchical glm with binomial family

2009-05-27 Thread Douglas Bates
On Wed, May 27, 2009 at 9:17 AM, Ben Bolker  wrote:
>
>
>
> Johan Stenberg-2 wrote:
>>
>> Dear members of the R help list,
>>
>> I want to do a hierarchical glm with binomial family but am unsure
>> about how to write the syntax which involves nesting.
>>
>> I want to test whether the risk of being attacked by Herbivores for
>> Meadowsweet plants is significantly dependent on the Distance to
>> heterospecific source plants.
>>
>> Dependent variable = Herbivory (yes/no)
>> Explanatory continuous variable = Distance to heterospecific source plant
>>
>> Distance should be nested within Subpopulation which in turn should be
>> nested within Population.
>> The number of replicates per subpopulation varies between 8 and 36.
>> The number of subpopulations per population varies between 4 and 9.
>>
>> I haven't figured out how to do nesting, but guessing that nesting is
>> denoted with brackets I guess the syntax should look something like
>> this (below). Could you please help me to correct this syntax so that
>> it becomes useful in R?
>>
>> model<-glm(Herbivory~Distance(Subpopulation(Population)), family=binomial)
>>
>>
>
> You probably need a GLMM (generalized linear mixed model), which is
> a little bit of a can of worms.  If so, you will need the "glmer" function
> inside the "lmer" package.

I think you mean the lme4 package.

>  I'm not entirely clear about your experimental design: I understand
> that subpopulations are nested within populations, but it's not clear
> whether covariates (distances to heterospecific plants) differ within
> subpopulations or populations.
>
>  If they don't differ with subpopulations, I would (strongly) recommend
> aggregating the
> values within subpopulations and analyzing proportions as a regression
> analysis:
> see Murtaugh, Paul A. “SIMPLICITY AND COMPLEXITY IN ECOLOGICAL
>  DATA ANALYSIS.” Ecology 88, no. 1 (2007): 56-62.
>
>  If they do, then your design is
>
> model<-glmer(Herbivory~Distance+(1|Population/Subpopulation),
> family=binomial)
>
>  See also:
>
> https://stat.ethz.ch/pipermail/r-sig-mixed-models/2009q2/002320.html
> https://stat.ethz.ch/pipermail/r-sig-mixed-models/2009q2/002335.html
> --
> View this message in context: 
> http://www.nabble.com/Hierarchical-glm-with-binomial-family-tp23742335p23743418.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] Sort matrix by column 1 ascending then by column 2 decending

2009-05-27 Thread Linlin Yan
It's a very interesting problem. I just wrote a function for it:

order.matrix <- function(m, columnsDecreasing = c('1'=FALSE), rows = 1:nrow(m))
{
  if (length(columnsDecreasing) > 0)
  {
col <- as.integer(names(columnsDecreasing[1]));
values <- sort(unique(m[rows, col]), decreasing=columnsDecreasing[1]);
unlist(sapply(values, function(x) order.matrix(m,
columnsDecreasing[-1], which((1:nrow(m) %in% rows) & (m[,
col]==x);
  }
  else
  {
rows;
  }
}

For instance:
> m <- matrix( c(2, 1, 1, 3, .5, .3, .5, .2), 4)
> m
 [,1] [,2]
[1,]2  0.5
[2,]1  0.3
[3,]1  0.5
[4,]3  0.2
> m[order.matrix(m),]
 [,1] [,2]
[1,]1  0.3
[2,]1  0.5
[3,]2  0.5
[4,]3  0.2
> m[order.matrix(m, c("1"=FALSE, "2"=TRUE)),]
 [,1] [,2]
[1,]1  0.5
[2,]1  0.3
[3,]2  0.5
[4,]3  0.2

Any comment is welcome! ;)

On Wed, May 27, 2009 at 11:04 PM, Linlin Yan  wrote:
>> m <- matrix( c(2, 1, 1, 3, .5, .3, .5, .2), 4)
>> m
>     [,1] [,2]
> [1,]    2  0.5
> [2,]    1  0.3
> [3,]    1  0.5
> [4,]    3  0.2
>> m[unlist(sapply(sort(unique(m[,1])), function(x) 
>> which(m[,1]==x)[order(m[(m[,1]==x),2], decreasing=TRUE)])),]
>     [,1] [,2]
> [1,]    1  0.5
> [2,]    1  0.3
> [3,]    2  0.5
> [4,]    3  0.2
>
> On Wed, May 27, 2009 at 8:39 PM, Paul Geeleher  wrote:
>> I've got a matrix with 2 columns and n rows. I need to sort it first
>> by the values in column 1 ascending. Then for values which are the
>> same in column 1, sort by column 2 decending. For example:
>>
>> 2 .5
>> 1 .3
>> 1 .5
>> 3 .2
>>
>> Goes to:
>>
>> 1 .5
>> 1 .3
>> 2 .5
>> 3 .2
>>
>> This is easy to do in spreadsheet programs but I can't seem to work
>> out how to do it in R and haven't been able to find a solution
>> anywhere.
>>
>>
>> Thanks!
>>
>> -Paul.
>>
>> --
>> Paul Geeleher
>> School of Mathematics, Statistics and Applied Mathematics
>> National University of Ireland
>> Galway
>> Ireland
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] Deviance explined in GAMM, library mgcv

2009-05-27 Thread Berta Ibáñez


 

Dear R-users, 

 

To obtain the percentage of deviance explained when fitting a gam model using 
the mgcv library is straightforward:

 

summary(object.gam) $dev.expl

 

or alternatively, using the deviance (deviance(object.gam)) of the null and the 
fitted models, and then using 1 minus the quotient of deviances. 

 

However, when a gamm (generalizad aditive mixed model) is fitted,  the deviance 
is not displayed, and only the logLik of the underlying lme model can be 
derived (logLik(objetct.gamm$lme)), which is not enough to derive the 
percentage deviance explained because the logLik for the saturated model is not 
available. 

Any suggestions on how to obtain the deviance explained when a gamm is fitted 
when the typical default gauusian model is fitted? Or alternavely, are the R^2 
derived from a gam model and a gamm model comparable?

 

Thanks a lot in advance,

Berta 

_
Descárgate ahora el nuevo Internet Explorer 8 y ten a tu alcance todos lo

[[alternative HTML version deleted]]

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


[R] How to set a filter during reading tables

2009-05-27 Thread guox
We are reading big tables, such as,

Chemicals <-
read.table('ftp://ftp.bls.gov/pub/time.series/wp/wp.data.7.Chemicals',header
= TRUE, sep = '\t', as.is =T)

I was wondering if it is possible to set a filter during loading so that
we just load what we want not the whole table each time. Thanks,

-james

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Labeling barplot bars by multiple factors

2009-05-27 Thread Thomas Levine
I want to plot quantitative data as a function of three two-level factors.
How do I group the bars on a barplot by level through labeling and spacing?
Here 's what
I'm thinking of. Also, I'm pretty sure that I want a barplot, but there may
be something better.

Tom

[[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 exclude a column by name?

2009-05-27 Thread Wacek Kusnierczyk
Dieter Menne wrote:
> Peter Dalgaard  biostat.ku.dk> writes:
>
>   
>> Or, BTW, you can use within()
>>
>> aq <- within(airquality, rm(Day))
>> 
>
> Please add this as an example to the docs of within. 
>   

possibly with the slightly more generic

unwanted <- 'Day'
aq <- within(airquality, rm(list=unwanted))

vQ

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


Re: [R] vegan metaMDS question

2009-05-27 Thread Gavin Simpson
On Wed, 2009-05-27 at 11:31 -0400, stephen sefick wrote:
> The design decision in metaMDS says that it uses:
> 
> Minchin, P.R. (1987) An evaluation of relative robustness of
> techniques for ecological ordinations. Vegetatio 71, 145-156.
> 
> This is the paper that I found by the same name.  Is this the correct 
> reference?
> 
> Minchin, Peter R.1987. An Evaluation of the Relative Robustness  of
> Techniques for Ecological Ordination. Vegetatio. Vol. 69, No. 1/3:
> 89-107.

Yes, I suspect so - the other volume/pages refers to another paper of
Peter Minchin's. Jari has now fixed this in the sources and the change
will be made in the next version of Vegan released to CRAN. Thanks for
pointing this out.

> 
> In this paper the double standardization (wisconsin()) is used then a
> centering by species is preformed.  The centering by species isn't
> incorporated in the metaMDS methodology, is it?

No it isn't.

>   Is there a reason for
> this, or am I missing something?

Yes - the only mention of centring by species is in reference to PCA. If
you centre species data, you'd have negative numbers, which can't be
handled in most dissimilarity coefficients and hence doesn't make sense
for nMDS. If I've overlooked something in that paper let me know and
I'll take a closer look.

I forwarded your email to Jari Oksanen, who wrote the metaMDS code in
vegan. If he has anything more to add, I'm sure he'll reply to you
directly.

Why did you send this to R-Help and me? This is a specific
package-related question which should go to the maintainer (Jari). We
also have a forum for asking such questions on the vegan R-Forge pages.
There is no need to bother this list with such questions.

HTH

G

> best regards,
> 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



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


Re: [R] Sort matrix by column 1 ascending then by column 2 decending

2009-05-27 Thread Kevin W
See also this tip on the R wiki:
http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:sort

Also available as the orderBy function in the doBy package.

Kevin Wright


On Wed, May 27, 2009 at 11:19 AM, Linlin Yan  wrote:

> It's a very interesting problem. I just wrote a function for it:
>
> order.matrix <- function(m, columnsDecreasing = c('1'=FALSE), rows =
> 1:nrow(m))
> {
>  if (length(columnsDecreasing) > 0)
>  {
>col <- as.integer(names(columnsDecreasing[1]));
>values <- sort(unique(m[rows, col]), decreasing=columnsDecreasing[1]);
>unlist(sapply(values, function(x) order.matrix(m,
> columnsDecreasing[-1], which((1:nrow(m) %in% rows) & (m[,
> col]==x);
>  }
>  else
>  {
>rows;
>  }
> }
>
> For instance:
> > m <- matrix( c(2, 1, 1, 3, .5, .3, .5, .2), 4)
> > m
> [,1] [,2]
> [1,]2  0.5
> [2,]1  0.3
> [3,]1  0.5
> [4,]3  0.2
> > m[order.matrix(m),]
> [,1] [,2]
> [1,]1  0.3
> [2,]1  0.5
> [3,]2  0.5
> [4,]3  0.2
> > m[order.matrix(m, c("1"=FALSE, "2"=TRUE)),]
> [,1] [,2]
> [1,]1  0.5
> [2,]1  0.3
> [3,]2  0.5
> [4,]3  0.2
>
> Any comment is welcome! ;)
>
> On Wed, May 27, 2009 at 11:04 PM, Linlin Yan 
> wrote:
> >> m <- matrix( c(2, 1, 1, 3, .5, .3, .5, .2), 4)
> >> m
> > [,1] [,2]
> > [1,]2  0.5
> > [2,]1  0.3
> > [3,]1  0.5
> > [4,]3  0.2
> >> m[unlist(sapply(sort(unique(m[,1])), function(x)
> which(m[,1]==x)[order(m[(m[,1]==x),2], decreasing=TRUE)])),]
> > [,1] [,2]
> > [1,]1  0.5
> > [2,]1  0.3
> > [3,]2  0.5
> > [4,]3  0.2
> >
> > On Wed, May 27, 2009 at 8:39 PM, Paul Geeleher 
> wrote:
> >> I've got a matrix with 2 columns and n rows. I need to sort it first
> >> by the values in column 1 ascending. Then for values which are the
> >> same in column 1, sort by column 2 decending. For example:
> >>
> >> 2 .5
> >> 1 .3
> >> 1 .5
> >> 3 .2
> >>
> >> Goes to:
> >>
> >> 1 .5
> >> 1 .3
> >> 2 .5
> >> 3 .2
> >>
> >> This is easy to do in spreadsheet programs but I can't seem to work
> >> out how to do it in R and haven't been able to find a solution
> >> anywhere.
> >>
> >>
> >> Thanks!
> >>
> >> -Paul.
> >>
> >> --
> >> Paul Geeleher
> >> School of Mathematics, Statistics and Applied Mathematics
> >> National University of Ireland
> >> Galway
> >> Ireland
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] R in Ubunto

2009-05-27 Thread Jarek Jasiewicz



R Heberto Ghezzo, Dr pisze:

Hello , I do not know anything abount Ubunto, but I found a Portable Ubunto for 
Windows and since so many people
prefer Linux to Windows I decided to give it a try.
It runs very nicely, so I tried to load R, following Instructions in CRAN I 
added the line
deb http://probability.ca/cran/bin/linux/ubuntu hardy/ to /etc/apt/sources.list 
and then from a console
I did
sudo apt-get update
sudo apt-get install r-base
a lot of printout and when it inishes I typed R in the console and surprise!
I got R 2.6.2!! in Windows I have R 2.9.0??
Did I do something wrong or there is another way to get the latest version of R?
Thanks for any help
Heberto Ghezzo Ph.D.
Biostatistique medical
Montreal - Canada
  

use cran mirror:
for canada it could be:

http://cran.stat.sfu.ca/

  deb http://cran.stat.sfu.ca/bin/linux/ubuntu 
 hardy/

you will have 2.9.0

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



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


Re: [R] Sort matrix by column 1 ascending then by column 2 decending

2009-05-27 Thread Duncan Murdoch

On 5/27/2009 8:39 AM, Paul Geeleher wrote:

I've got a matrix with 2 columns and n rows. I need to sort it first
by the values in column 1 ascending. Then for values which are the
same in column 1, sort by column 2 decending. For example:


You've seen a few ways.  Here are some more:

1.  Use the fact that order() uses a stable sort algorithm, so just sort 
by the second column then the first:


x <- matrix(c(2,1,1,3,.5,.3,.5,.2), ncol=2)
x1 <- x[order(x[,2], decreasing=TRUE),]
x2 <- x1[order(x1[,1]),]
x2

2.  Use the fact that your values are numeric, so negatives sort in the 
reverse order of positives:


x[order(x[,1], -x[,2]),]

3.  If the values aren't known to be numeric, convert them to numeric 
before using them as sort keys:


x[order(xtfrm(x[,1]), -xtfrm(x[,2])),]

In any of these, watch out for NA handling.  My methods all put NA 
values last, but that might not be what you want.


Duncan Murdoch



2 .5
1 .3
1 .5
3 .2

Goes to:

1 .5
1 .3
2 .5
3 .2

This is easy to do in spreadsheet programs but I can't seem to work
out how to do it in R and haven't been able to find a solution
anywhere.


Thanks!

-Paul.



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


Re: [R] Labeling barplot bars by multiple factors

2009-05-27 Thread Mike Lawrence
You can get something close with ggplot2:

library(ggplot2)
my_data = expand.grid(
A = factor(c('A1','A2'))
, B = factor(c('B1','B2'))
, C = factor(c('C1','C2'))
)
my_data$DV = rnorm(8,mean=10,sd=1)
p = ggplot()
p = p + layer(
geom = 'bar'
, stat = 'identity'
, data = my_data
, mapping = aes(
x = C
, y = DV
, fill = B
)
, position = 'dodge'
)
p = p + facet_grid(
A ~ .
)
p = p + coord_flip()
print(p)


On Wed, May 27, 2009 at 1:01 PM, Thomas Levine  wrote:
> I want to plot quantitative data as a function of three two-level factors.
> How do I group the bars on a barplot by level through labeling and spacing?
> Here 's what
> I'm thinking of. Also, I'm pretty sure that I want a barplot, but there may
> be something better.
>
> Tom
>
>        [[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.
>



-- 
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tr.im/mikes_public_calendar

~ Certainty is folly... I think. ~

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

2009-05-27 Thread Jose Quesada
Hi all,

I often have to peek at large data.
While head and tail are convenient, at times I'd like some more
comprehensive.
I guess I debug better in a more visual way?
I was wondering if there's a way to override the default data editor.
I could of course dump to a txt file, and look at it with an
editor/spreadsheet, but after doing it a few times, it gets boring.
Maybe it's time for me to write a function to automatize the process?
I'd ask first in case there's an easier way.

Thanks!
-Jose

-- 
Jose Quesada, PhD.
Max Planck Institute,
Center for Adaptive Behavior and Cognition -ABC-, 
Lentzeallee 94, office 224, 14195 Berlin
http://www.josequesada.name/

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


[R] no internal function "int.unzip" in R 2.9.0 for Windows

2009-05-27 Thread Carson, John
> library(R2HTML)

Loading required package: R2HTML

Error in .Internal(int.unzip(zipname, NULL, dest)) : 

  no internal function "int.unzip"

Error : .onLoad failed in 'loadNamespace' for 'R2HTML'

Error: package 'R2HTML' could not be loaded

 

 

Version: R 2.9.0 for Windows



Internet Email Confidentiality Footer
Privileged/Confidential Information may be contained in this
message. If you are not the addressee indicated in this message (or
responsible for delivery of the message to such person), you may
not copy or deliver this message to anyone. In such case, you
should destroy this message and notify the sender by reply email.
Please advise immediately if you or your employer do not consent to
Internet email for messages of this kind. Opinions, conclusions and
other information in this message that do not relate to the
official business of The Shaw Group Inc. or its subsidiaries shall
be understood as neither given nor endorsed by it.
__ The Shaw Group Inc.
http://www.shawgrp.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] "Error: package/namespace load failed"

2009-05-27 Thread Rebecca Sela
I am writing my first R package, and I have been getting the following series 
of errors when I run R CMD check:

* checking S3 generic/method consistency ... WARNING
Error: package/namespace load failed for 'REEMtree'
Call sequence:
2: stop(gettextf("package/namespace load failed for '%s'", 
libraryPkgName(package)), 
   call. = FALSE, domain = NA)
1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE)
Execution halted
See section 'Generic functions and methods' of the 'Writing R Extensions'
manual.
* checking replacement functions ... WARNING
Error: package/namespace load failed for 'REEMtree'
Call sequence:
2: stop(gettextf("package/namespace load failed for '%s'", 
libraryPkgName(package)), 
   call. = FALSE, domain = NA)
1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE)
Execution halted
In R, the argument of a replacement function which corresponds to the right
hand side must be named 'value'.
* checking foreign function calls ... WARNING
Error: package/namespace load failed for 'REEMtree'
Call sequence:
2: stop(gettextf("package/namespace load failed for '%s'", 
libraryPkgName(package)), 
   call. = FALSE, domain = NA)
1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE)
Execution halted
See section 'System and foreign language interfaces' of the 'Writing R
Extensions' manual.
* checking Rd files ... OK
* checking for missing documentation entries ... ERROR
Error: package/namespace load failed for 'REEMtree'

(Everything is OK up to this point.)

Looking around online, I have found references to this error when there is 
compiled C or Fortran code, but I have none of that in my code.  I imagine this 
is a simple problem (perhaps with my NAMESPACE file), but I don't know what it 
is.  (The text of the NAMESPACE file is at the bottom of this e-mail.)

Thank you in advance for your help!

Rebecca

NAMESPACE file:

useDynLib(REEMtree)

export(AutoCorrelationLRtest, FixedEffectsTree, RandomEffectsTree, 
LMEpredict, PredictionTest, RandomEffectsTree, RMSE, simpleREEMdata, 
REEMtree, FEEMtree)

import(nlme)
import(rpart)

S3method(is,REEMtree)
S3method(logLik,REEMtree)
S3method(plot,REEMtree)
S3method(predict,REEMtree)
S3method(print, REEMtree)
S3method(ranef,REEMtree)
S3method(tree,REEMtree)
S3method(is,FEEMtree)
S3method(logLik,FEEMtree)
S3method(plot,FEEMtree)
S3method(predict,FEEMtree)
S3method(print, FEEMtree)
S3method(tree,FEEMtree)

useDynLib(REEMtree)

export(AutoCorrelationLRtest, FixedEffectsTree, RandomEffectsTree, 
LMEpredict, PredictionTest, RandomEffectsTree, RMSE, simpleREEMdata, 
REEMtree, FEEMtree)

import(nlme)
import(rpart)

S3method(is,REEMtree)
S3method(logLik,REEMtree)
S3method(plot,REEMtree)
S3method(predict,REEMtree)
S3method(print, REEMtree)
S3method(ranef,REEMtree)
S3method(tree,REEMtree)
S3method(is,FEEMtree)
S3method(logLik,FEEMtree)
S3method(plot,FEEMtree)
S3method(predict,FEEMtree)
S3method(print, FEEMtree)
S3method(tree,FEEMtree)
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] contour lines on persp plot

2009-05-27 Thread Jack Siegrist
Hello folks,

I am a beginner R user. I have been able to make a 3D surface plot using
'persp'. The surface is made by a grid of lines emanating perpendicularly
from each of the x and y axes at regular intervals.

I can get rid of that grid by setting 'border=NA'.

Can anyone suggest some ways to replace the grid with contour lines, to
create a 3-dimensional contour map?

Thanks for any help.

Here is an example of what I have so far:

#to create a perspective plot; plots funct. across all combos of x and y

fn<-function(x,y){sin(x)+2*y} #this looks like a corrugated tin roof

x<-seq(from=1,to=100,by=1) #generates a list of x values to sample
y<-seq(from=1,to=100,by=1) #generates a list of y values to sample

z<-outer(x,y,FUN=fn) #applies the funct. across the combos of x and y

persp(z,col='lightgray',shade=.5,border=NA,) #plots without gridlines

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


Re: [R] Neural Network resource

2009-05-27 Thread Indrajit Sengupta

Here is the code that i had used:

#


## Read in the raw data
fitness <- c(44,89.47,44.609,11.37,62,178,182,
40,75.07,45.313,10.07,62,185,185,
44,85.84,54.297,8.65,45,156,168,
42,68.15,59.571,8.17,40,166,172,
38,89.02,49.874,9.22,55,178,180,
47,77.45,44.811,11.63,58,176,176,
40,75.98,45.681,11.95,70,176,180,
43,81.19,49.091,10.85,64,162,170,
44,81.42,39.442,13.08,63,174,176,
38,81.87,60.055,8.63,48,170,186,
44,73.03,50.541,10.13,45,168,168,
45,87.66,37.388,14.03,56,186,192,
45,66.45,44.754,11.12,51,176,176,
47,79.15,47.273,10.6,47,162,164,
54,83.12,51.855,10.33,50,166,170,
49,81.42,49.156,8.95,44,180,185,
51,69.63,40.836,10.95,57,168,172,
51,77.91,46.672,10,48,162,168,
48,91.63,46.774,10.25,48,162,164,
49,73.37,50.388,10.08,67,168,168,
57,73.37,39.407,12.63,58,174,176,
54,79.38,46.08,11.17,62,156,165,
52,76.32,45.441,9.63,48,164,166,
50,70.87,54.625,8.92,48,146,155,
51,67.25,45.118,11.08,48,172,172,
54,91.63,39.203,12.88,44,168,172,
51,73.71,45.79,10.47,59,186,188,
57,59.08,50.545,9.93,49,148,155,
49,76.32,48.673,9.4,56,186,188,
48,61.24,47.92,11.5,52,170,176,
52,82.78,47.467,10.5,53,170,172
)
fitness2 <- data.frame(matrix(fitness,nrow = 31, byrow = TRUE))
colnames(fitness2) <- 
c("Age","Weight","Oxygen","RunTime","RestPulse","RunPulse","MaxPulse")
attach(fitness2)
## Create the input dataset
indep <- fitness2[,-3]
## Create the neural network structure 
net.start <- newff(n.neurons=c(6,6,6,1),  
 learning.rate.global=1e-2,    
 momentum.global=0.5,  
 error.criterium="LMS",   
 Stao=NA, hidden.layer="tansig",   
 output.layer="purelin",   
 method="ADAPTgdwm")
## Train the net
result <- train(net.start, indep, Oxygen, error.criterium="LMS", report=TRUE, 
show.step=100, n.shows=5 ) 
## Predict
pred <- sim(result$net, indep)
pred 
### 

Here I am trying to predict Oxygen levels using the 6 independent 
variables. But whenever I am trying to run a prediction - I am getting constant 
values throughout (In the above example - the values of pred).

Thanks & Regards,
Indrajit

 


- Original Message 
From: Max Kuhn 
To: Indrajit Sengupta 
Cc: markle...@verizon.net; R Help 
Sent: Wednesday, May 27, 2009 9:19:47 PM
Subject: Re: [R] Neural Network resource

> I fed this data into a Neural network (3 hidden layers with 6 neurons in each 
> layer) and trained the network. When I passed the input dataset and tried to 
> get the predictions, all the predicted values were identical! This confused 
> me a bit and was wondering whether my understanding of the Neural Network was 
> wrong.
>
> Have you ever faced anything like it?

You should really provide code for us to help. I would initially
suspect that you didn't use a linear function between your hidden
units and the outcomes.

Also, using 3 hidden layers and 6 units per layer is a bit much for
your data set (30-40 samples). You will probably end up overfitting.

-- 

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] alternative to built-in data editor

2009-05-27 Thread Peter Dalgaard

Jose Quesada wrote:

Hi all,

I often have to peek at large data.
While head and tail are convenient, at times I'd like some more
comprehensive.
I guess I debug better in a more visual way?
I was wondering if there's a way to override the default data editor.
I could of course dump to a txt file, and look at it with an
editor/spreadsheet, but after doing it a few times, it gets boring.
Maybe it's time for me to write a function to automatize the process?
I'd ask first in case there's an easier way.

Thanks!
-Jose



There's a tcltk-based data viewer in John Fox' Rcmdr package. Not sure 
it does what you want, but check it out.



--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

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


[R] R-beta: Re:Stats Seminar 18/02/98

2009-05-27 Thread Roland Chariatte
Bonjour,
Je recherche une ancienne amie qui porte le nom de Marylin Gabriel originaire 
des Seychelles et que j'ai perdu de vue il y à environ 20 ans.
Si cette adresse e-mail est la tienne, tu te souviendra très bien de moi, 
j'aimerais beaucoup te revoir car j'ai de superbes souvenirs de toi.
Peut être à bientôt.
Je suis toujours le même Roland Chariatte de Delémont que tu as connu en 1986 
ou 87.

RCline
Roland CHARIATTE

rue de la Croix 27 

2822 COURROUX

Switzerland
Mobile   +41 (0)78 648 19 68

i...@rcline.ch

www.rcline.ch 
[[alternative HTML version deleted]]

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


[R] r-plot 2nd attempt

2009-05-27 Thread durden10

First of all, thanks a lot for your quick & helpful comments!

I have come down to this:

Win<- c(-0.005276404,  0.081894394, -0.073461539,  0.184371967, 
0.133189670, -0.006239016,  -0.063616699,  0.196754234,  0.402148743, 
0.104408425,
  0.036910154,  0.195227863,  0.212743723,  0.280889666,  0.300277802)
Calgary<- c(5,  8, 11,  3,  7,  4,  7,  1,  3,  6,  3,  2,  8,  0,  1)

data_corr <- data.frame(Win,Calgary)
plot(data_corr, type = "p", axes=FALSE,  col = "blue", lwd = 2)

#y-axis
axis(2, tcl=0.35,seq(1,11,by=2))

#x-axis
axis(1, tcl=0.35,seq(-0.1,0.5,by=0.1))
box()

abline(lm(data_corr[,2]~data_corr[,1]))

It works for the y-axis, but unfortunately, the x-axis is still not working:
It starts at 0 and end at 0.4, but it should start at -0.1, as mentioned in
the code (cf picture) :confused: 
http://www.nabble.com/file/p23742121/Rplots_2.png 

-- 
View this message in context: 
http://www.nabble.com/r-plot-tp23739356p23742121.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] Neural Network resource

2009-05-27 Thread Tony Breyal
I haven't used the AMORE package before, but it sounds like you
haven't set linear output units or something. Here's an example using
the nnet package of what you're doing i think:

### R START###
> # set random seed to a cool number
> set.seed(42)
>
> # set up data
> x1<-rnorm(100); x2<-rnorm(100); x3<-rnorm(100)
> x4<-rnorm(100); x5<-rnorm(100); x6<-rnorm(100)
> b1<-1; b2<-2; b3<-3
> b4<-4; b5<-5; b6<-6
> y<-b1*x1 + b2*x2 + b3*x3 + b4*x4 + b5*x5 + b6*x6
> my.df <- data.frame(cbind(y, x1, x2, x3, x4, x5, x6))
>
> # 1. linear regression
> my.lm <- lm(y~., data=my.df)
>
> # look at correlation
> my.lm.predictions<-predict(my.lm)
> cor(my.df["y"], my.lm.predictions)
  [,1]
y1
>
> # 2. nnet
> library(nnet)
> my.nnet<-nnet(y~., data=my.df, size=3,
 linout=TRUE, skip=TRUE,
 trace=FALSE, maxit=1000)
>
> my.nnet.predictions<-predict(my.nnet, my.df)
> # look at correlation
> cor(my.df["y"], my.nnet.predictions)
  [,1]
y1
>
> # to look at the values side by side
> cbind(my.df["y"], my.nnet.predictions)
   y my.nnet.predictions
110.60102566 10.59958907
2 6.70939465  6.70956529
3 2.28934732  2.28928930
414.51012458 14.51043732
5   -12.85845371-12.85849345
[..etc]
### R END ###

Hope that helps a wee bit mate,

Tony Breyal


On 27 May, 15:36, Indrajit Sengupta  wrote:
> You are right there is a pdf file which describes the function. But let tell 
> you where I am coming from.
>
> Just to test if a neural network will work better than a ordinary least 
> square regression, I created a dataset with one dependent variable and 6 
> other independent variables. Now I had deliberately created the dataset in 
> such manner that we have an excellent regression model. Eg: Y = b0 + b1*x1 + 
> b2*x2 + b3*x3.. + b6*x6 + e
> where e is normal random variable. Naturally any statistical analysis system 
> running regression would easily predict the values of b1, b2, b3, ..., b6 
> with around 30-40 observations.
>
> I fed this data into a Neural network (3 hidden layers with 6 neurons in each 
> layer) and trained the network. When I passed the input dataset and tried to 
> get the predictions, all the predicted values were identical! This confused 
> me a bit and was wondering whether my understanding of the Neural Network was 
> wrong.
>
> Have you ever faced anything like it?
>
> Regards,
> Indrajit
>
> 
> From: "markle...@verizon.net" 
>
> Sent: Wednesday, May 27, 2009 7:54:59 PM
> Subject: Re: [R] Neural Network resource
>
> Hi: I've never used that package but most likely there is a  AMORE vignette 
> that shows examples and describes the functions.
> it should be on the same cran  web page where the package resides, in pdf 
> form.
>
> Hi All,
>
> I am trying to learn Neural Networks. I found that R has packages which can 
> help build Neural Nets - the popular one being AMORE package. Is there any 
> book / resource available which guides us in this subject using the AMORE 
> package?
>
> Any help will be much appreciated.
>
> Thanks,
> Indrajit
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>         [[alternative HTML version deleted]]
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://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] RWeka weka.core.SerializationHelper.write

2009-05-27 Thread Christian

Hi,

is it possible to use the writer method from the  
weka.core.SerializationHelper class in R?

What could be wrong in my trial.

many thanks
Christian

.jmethods("weka/core/SerializationHelper")
[2] "public static void 
weka.core.SerializationHelper.write(java.lang.String,java.lang.Object) 
throws java.lang.Exception"   


> NB <- make_Weka_classifier("weka/classifiers/bayes/NaiveBayes")
> data("HouseVotes84", package = "mlbench")
> model <- NB(Class ~ ., data = HouseVotes84)
>
> 
.jcall("weka/core/SerializationHelper",returnSig="V","write","nb.model",model)
Fehler in .jcall("weka/core/SerializationHelper", returnSig = "V", 
"write",  :

 method write with signature (Ljava/lang/String;)V not found

> 
.jcall("weka/core/SerializationHelper",returnSig="V","write","nb.model",model$classifier)
Fehler in .jcall("weka/core/SerializationHelper", returnSig = "V", 
"write",  :
 method write with signature 
(Ljava/lang/String;Lweka/classifiers/bayes/NaiveBayes;)V not found


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

2009-05-27 Thread Christian

Hi,

is it possible to use the writer method from the  
weka.core.SerializationHelper class in R?

When yes, what could be wrong in my trial.

many thanks
Christian

.jmethods("weka/core/SerializationHelper")
[2] "public static void 
weka.core.SerializationHelper.write(java.lang.String,java.lang.Object) 
throws java.lang.Exception"  
> NB <- make_Weka_classifier("weka/classifiers/bayes/NaiveBayes")

> data("HouseVotes84", package = "mlbench")
> model <- NB(Class ~ ., data = HouseVotes84)
>
> 
.jcall("weka/core/SerializationHelper",returnSig="V","write","nb.model",model) 

Fehler in .jcall("weka/core/SerializationHelper", returnSig = "V", 
"write",  :

method write with signature (Ljava/lang/String;)V not found

> 
.jcall("weka/core/SerializationHelper",returnSig="V","write","nb.model",model$classifier) 

Fehler in .jcall("weka/core/SerializationHelper", returnSig = "V", 
"write",  :
method write with signature 
(Ljava/lang/String;Lweka/classifiers/bayes/NaiveBayes;)V not found


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


Re: [R] Loop avoidance and logical subscripts

2009-05-27 Thread retama

Thank you! The script is now adapted to Biostrings and it is really fast! For
example, it does:

   alph_sequence <- alphabetFrequency(data$sequence, baseOnly=TRUE)
   data$GCsequence <- rowSums(alph_sequence[,c("G", "C")]) /
rowSums(alph_sequence)

in the G+C computation. It also works amazingly fast in substring extraction
(substring), reverse complement (reverseComplement sequences), palindromes
search (findComplementedPalindromes) and so on.

Now, my bottleneck is conventional string handling, because I have not found
yet how to convert DNAStringSets to vector of chars. Now, I'm doing it by:

   dna <- vector()
for (i in 1:length(dnaset)) {
c(dna, toString(data$dnaset[[i]])) -> dna
}

Regards,

Retama








-- 
View this message in context: 
http://www.nabble.com/Loop-avoidance-and-logical-subscripts-tp23652935p23745814.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] invert axis persp plot

2009-05-27 Thread Jack Siegrist
Hello folks,

Is there a way to invert the z axis in a 'persp' plot?

I tried using 'zlim=rev(range(z))', which would work with 'plot' but does
not work in this case.

Thank you for your help.

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

2009-05-27 Thread kayj

Hi All,

I have a file with two columns, the first column has the names of the
patients and the second column has the age. I am looking into creating an
output file that looks like 

1-1010-20etc
EricChris
Bob mat
Andrew
Suzan


Where each column has the name of the patients in a given age category that
is displayed in the header. For example in the output, the first column has
the name of the patients with age between 1 to 10.

The problem that I am having is that I can not use cbind since the length of
the vectors is different. Is there a way to create such a file?

Thanks for your help



-- 
View this message in context: 
http://www.nabble.com/problem-with-cbind-tp23747075p23747075.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.


  1   2   >