Re: [R] Multi-level (nested) correlation structures via geepack package

2020-07-13 Thread Phat Chau
Hi Duncan, 

Thank you for your message. All of those citations and suggestions are 
wonderful and highly relevant for GEEs. My concern is that I need 
multi-level/nested correlation structures, whereas those handle the 
specification of covariance matrices at the level of repeated observations 
within-subject. I think the paper attached contains the theory behind such 
nested correlation structures, but the coding for it is not as apparent.

Edward

On 2020-07-12, 11:06 PM, "dulcalma dulcalma"  wrote:

Hi

Your choice of package should partly depend on the type of dependent 
variable or Y that you are going to be dealing with
categorical/ordinal data may involve different packages than continuous 
or binary data see multgee for one.
The number of samples can also make a difference GEE with the "correct 
model" should normally have no problems with numbers 30-40; 25 or less 
would normally require corrections and a diffence package.

The doi for multgee  paper is 10./biom.12054 and Touloumis paper in 
Journal of Statistical Software

For longitudinal data there is the following doi:
10.2307/2531248
and
10.1097/EDE.0b013e3181caeb90
10.1093/biomet/90.1.29
10.1007/s00362-017-0881-0
10.1002/sim.2368

a search for gee in the list of available packages should show you the 
alternatives.

As a check of the result do the statistics on another package. I 
remember doing a simple gee with an example
from a book using 4 different packages 2 of which gave poor or 
unreasonable answers

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
ARMIDALE NSW 2351



-- Original Message --
From: "Phat Chau" 
To: "r-help@R-project.org" ; "sor...@math.aau.dk" 

Sent: Sunday, 12 Jul, 2020 At 11:52 PM
Subject: Re: [R]  Multi-level (nested) correlation structures via 
geepack package

Hello,

I have a multi-level, cohort dataset with three levels: repeat measures 
of a response (level 1), that are collected from individual participants 
(level 2) who are students within a school (level 3). I would like to do 
a generalized estimating equation (GEE) analysis of this clustered data, 
but to do so I need to specify ‘nested’ correlation structures (e.g. 
exchangeable, compound symmetric, Toeplitz) to account for the 
within-individual and within-cluster correlations.

Here is a reference paper that describes a nested exchangeable 
correlation structure and nested compound symmetry: 
doi:10./j.1541-0420.2009.01374.x.

The geepack is available in R to do GEE analyses, but it seems to me 
that it only allows the user to specify a correlation structure via the 
geepack(…‘corstr = ‘) option which only accounts for the 
within-individual correlations (that arise from repeated measures). 
Would it be possible to specify the nested correlation structures that I 
refer to here to also account for the within-cluster correlations using 
this package?

Thank you,

Edward


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Multi-level (nested) correlation structures via geepack package

2020-07-12 Thread dulcalma dulcalma

Hi

Your choice of package should partly depend on the type of dependent 
variable or Y that you are going to be dealing with
categorical/ordinal data may involve different packages than continuous 
or binary data see multgee for one.
The number of samples can also make a difference GEE with the "correct 
model" should normally have no problems with numbers 30-40; 25 or less 
would normally require corrections and a diffence package.


The doi for multgee  paper is 10./biom.12054 and Touloumis paper in 
Journal of Statistical Software


For longitudinal data there is the following doi:
10.2307/2531248
and
10.1097/EDE.0b013e3181caeb90
10.1093/biomet/90.1.29
10.1007/s00362-017-0881-0
10.1002/sim.2368

a search for gee in the list of available packages should show you the 
alternatives.


As a check of the result do the statistics on another package. I 
remember doing a simple gee with an example
from a book using 4 different packages 2 of which gave poor or 
unreasonable answers


Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
ARMIDALE NSW 2351



-- Original Message --
From: "Phat Chau" 
To: "r-help@R-project.org" ; "sor...@math.aau.dk" 


Sent: Sunday, 12 Jul, 2020 At 11:52 PM
Subject: Re: [R]  Multi-level (nested) correlation structures via 
geepack package


Hello,

I have a multi-level, cohort dataset with three levels: repeat measures 
of a response (level 1), that are collected from individual participants 
(level 2) who are students within a school (level 3). I would like to do 
a generalized estimating equation (GEE) analysis of this clustered data, 
but to do so I need to specify ‘nested’ correlation structures (e.g. 
exchangeable, compound symmetric, Toeplitz) to account for the 
within-individual and within-cluster correlations.


Here is a reference paper that describes a nested exchangeable 
correlation structure and nested compound symmetry: 
doi:10./j.1541-0420.2009.01374.x.


The geepack is available in R to do GEE analyses, but it seems to me 
that it only allows the user to specify a correlation structure via the 
geepack(…‘corstr = ‘) option which only accounts for the 
within-individual correlations (that arise from repeated measures). 
Would it be possible to specify the nested correlation structures that I 
refer to here to also account for the within-cluster correlations using 
this package?


Thank you,

Edward


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Multi-level (nested) correlation structures via geepack package

2020-07-12 Thread Bert Gunter
You may get lucky, but generally such package-specific questions don't get
responses here. There are about 2 packages after all. You might do
better posting on the r-sig-mixed-models list or by asking the package
maintainer (?maintainer) whether there is some sort of support list for the
package.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Jul 12, 2020 at 9:59 AM Phat Chau 
wrote:

> Hello,
>
> I have a multi-level, cohort dataset with three levels: repeat measures of
> a response (level 1), that are collected from individual participants
> (level 2) who are students within a school (level 3). I would like to do a
> generalized estimating equation (GEE) analysis of this clustered data, but
> to do so I need to specify ‘nested’ correlation structures (e.g.
> exchangeable, compound symmetric, Toeplitz) to account for the
> within-individual and within-cluster correlations.
>
> Here is a reference paper that describes a nested exchangeable correlation
> structure and nested compound symmetry:
> doi:10./j.1541-0420.2009.01374.x.
>
> The geepack is available in R to do GEE analyses, but it seems to me that
> it only allows the user to specify a correlation structure via the
> geepack(…‘corstr = ‘) option which only accounts for the within-individual
> correlations (that arise from repeated measures). Would it be possible to
> specify the nested correlation structures that I refer to here to also
> account for the within-cluster correlations using this package?
>
> Thank you,
>
> Edward
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Multi-level (nested) correlation structures via geepack package

2020-07-12 Thread Phat Chau
Hello,

I have a multi-level, cohort dataset with three levels: repeat measures of a 
response (level 1), that are collected from individual participants (level 2) 
who are students within a school (level 3). I would like to do a generalized 
estimating equation (GEE) analysis of this clustered data, but to do so I need 
to specify ‘nested’ correlation structures (e.g. exchangeable, compound 
symmetric, Toeplitz) to account for the within-individual and within-cluster 
correlations.

Here is a reference paper that describes a nested exchangeable correlation 
structure and nested compound symmetry: doi:10./j.1541-0420.2009.01374.x.

The geepack is available in R to do GEE analyses, but it seems to me that it 
only allows the user to specify a correlation structure via the 
geepack(…‘corstr = ‘) option which only accounts for the within-individual 
correlations (that arise from repeated measures). Would it be possible to 
specify the nested correlation structures that I refer to here to also account 
for the within-cluster correlations using this package?

Thank you,

Edward


[[alternative HTML version deleted]]

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


Re: [R] Multi response GAM

2020-04-20 Thread Richard O'Keefe
You might want to start by re-expressing the "amounts"
variables to
  total amount * (relative fish 1, relative fish 2, invertebrates)
and then using the Isometric Log-ratio transformation to
convert the compositional part to orthonormal coordinates.
https://stats.stackexchange.com/questions/259208/how-to-perform-isometric-log-ratio-transformation
may help.

I can't help wondering whether viewing the diet in terms of
the nutrients offered by the different components might yield
more insight.

On Sat, 18 Apr 2020 at 11:00, Tristan Kosciuch
 wrote:
>
> Hello,
>
> I am modelling the diet of Nile perch through time. I have 3 diet classes as
> my response variables; fish 1, fish 2, and invertebrates.
>
> The response variables are correlated, declines in invert consumption ~
> increase in fish consumption. Any advice on how to handle this would be
> appreciated. I would like to use GAMs as my time series shows fluctuations
> that could only be fit by high order polynomials if I were to use a linear
> model, but open to suggestions.
>
> Thank you for your time.
>
> P.s. I will be comparing the fit of the time series GAM with a model based
> on other predictors, with a training and validation split for my data.
>
>
>
> ---
>
> Tristan Kosciuch
>
> Stewart Biology Building, McGill University
>
> 1205 Dr Penfield Ave, Montreal QC H3A 1B1
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Multi response GAM

2020-04-19 Thread Tristan Kosciuch
Thanks, I think

family=mvn(d=3)

​in mgcv gam() works!



---

Tristan Kosciuch

Stewart Biology Building, McGill University

1205 Dr Penfield Ave, Montreal QC H3A 1B1


From: Bert Gunter 
Sent: Friday, April 17, 2020 7:28 PM
To: Tristan Kosciuch 
Cc: r-help@R-project.org 
Subject: Re: [R] Multi response GAM

https://cran.r-project.org/web/views/Multivariate.html
https://cran.r-project.org/web/views/Environmetrics.html
https://cran.r-project.org/web/views/TimeSeries.html

Also search on "multiresponse GAM" or similar at rseek.org<http://rseek.org>. 
This brought up what looked to me like useful hits.
And of course, don't forget Mama Google.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and 
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Apr 17, 2020 at 4:00 PM Tristan Kosciuch 
mailto:tristan.kosci...@mail.mcgill.ca>> wrote:
Hello,

I am modelling the diet of Nile perch through time. I have 3 diet classes as
my response variables; fish 1, fish 2, and invertebrates.

The response variables are correlated, declines in invert consumption ~
increase in fish consumption. Any advice on how to handle this would be
appreciated. I would like to use GAMs as my time series shows fluctuations
that could only be fit by high order polynomials if I were to use a linear
model, but open to suggestions.

Thank you for your time.

P.s. I will be comparing the fit of the time series GAM with a model based
on other predictors, with a training and validation split for my data.



---

Tristan Kosciuch

Stewart Biology Building, McGill University

1205 Dr Penfield Ave, Montreal QC H3A 1B1

[[alternative HTML version deleted]]

__
R-help@r-project.org<mailto:R-help@r-project.org> mailing list -- To 
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Multi response GAM

2020-04-18 Thread Highland Statistics Ltd
Try R-INLA. It will allow you to model all three diet class time series 
in one model (even allowing for different distributions if required). 
And you can also include correlation between the time series. And test 
whether those diet classes have the same trend or not.


Alain


--

Message: 5
Date: Fri, 17 Apr 2020 22:45:33 +
From: Tristan Kosciuch 
To: "r-help@R-project.org" 
Subject: [R] Multi response GAM
Message-ID:


Content-Type: text/plain; charset="utf-8"

Hello,

I am modelling the diet of Nile perch through time. I have 3 diet classes as
my response variables; fish 1, fish 2, and invertebrates.

The response variables are correlated, declines in invert consumption ~
increase in fish consumption. Any advice on how to handle this would be
appreciated. I would like to use GAMs as my time series shows fluctuations
that could only be fit by high order polynomials if I were to use a linear
model, but open to suggestions.

Thank you for your time.

P.s. I will be comparing the fit of the time series GAM with a model based
on other predictors, with a training and validation split for my data.



---

Tristan Kosciuch

Stewart Biology Building, McGill University

1205 Dr Penfield Ave, Montreal QC H3A 1B1

[[alternative HTML version deleted]]




--

Dr. Alain F. Zuur
Highland Statistics Ltd.
9 St Clair Wynd
AB41 6DZ Newburgh, UK
Email: highs...@highstat.com
URL:   www.highstat.com

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


Re: [R] Multi response GAM

2020-04-17 Thread Bert Gunter
https://cran.r-project.org/web/views/Multivariate.html
https://cran.r-project.org/web/views/Environmetrics.html
https://cran.r-project.org/web/views/TimeSeries.html

Also search on "multiresponse GAM" or similar at rseek.org. This brought up
what looked to me like useful hits.
And of course, don't forget Mama Google.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Apr 17, 2020 at 4:00 PM Tristan Kosciuch <
tristan.kosci...@mail.mcgill.ca> wrote:

> Hello,
>
> I am modelling the diet of Nile perch through time. I have 3 diet classes
> as
> my response variables; fish 1, fish 2, and invertebrates.
>
> The response variables are correlated, declines in invert consumption ~
> increase in fish consumption. Any advice on how to handle this would be
> appreciated. I would like to use GAMs as my time series shows fluctuations
> that could only be fit by high order polynomials if I were to use a linear
> model, but open to suggestions.
>
> Thank you for your time.
>
> P.s. I will be comparing the fit of the time series GAM with a model based
> on other predictors, with a training and validation split for my data.
>
>
>
> ---
>
> Tristan Kosciuch
>
> Stewart Biology Building, McGill University
>
> 1205 Dr Penfield Ave, Montreal QC H3A 1B1
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Multi response GAM

2020-04-17 Thread Abby Spurdle
It might be possible via the VGAM package:
https://cran.r-project.org/package=VGAM

But I've never used this package, so not sure.

It may also be possible to use a single response, by including
additional explanatory terms.
This is what I would do, if I could...

Noting that some GAM implementations allow categorical variables and
interactions.


On Sat, Apr 18, 2020 at 11:00 AM Tristan Kosciuch
 wrote:
>
> Hello,
>
> I am modelling the diet of Nile perch through time. I have 3 diet classes as
> my response variables; fish 1, fish 2, and invertebrates.
>
> The response variables are correlated, declines in invert consumption ~
> increase in fish consumption. Any advice on how to handle this would be
> appreciated. I would like to use GAMs as my time series shows fluctuations
> that could only be fit by high order polynomials if I were to use a linear
> model, but open to suggestions.
>
> Thank you for your time.
>
> P.s. I will be comparing the fit of the time series GAM with a model based
> on other predictors, with a training and validation split for my data.
>
>
>
> ---
>
> Tristan Kosciuch
>
> Stewart Biology Building, McGill University
>
> 1205 Dr Penfield Ave, Montreal QC H3A 1B1
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Multi-word column names in a data frame

2018-09-06 Thread Jeff Newmiller
You forgot to reply-all ... I don't do private consulting, so please keep 
the conversation on the mailing list.


Here are some ideas for extending your example. However, whether you WANT 
to or not, you really need to learn to manipulate your data BEFORE you 
give it to ggplot.


#
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(tidyr)
library(ggplot2)
library(rlang)
`RefDate` <- as.Date(c("2010-11-1","2010-12-01","2011-01-01"))
`Number of vegetables` <- c(14,23,45)
`Number of people` <- c(20,30,40)
MyData <- data.frame( RefDate
, `Number of vegetables`
, `Number of people`
, check.names=FALSE
)
MyVars <- c("Number of vegetables","Number of people")

# simple approach... notice "RefDate" is a string

for (A in MyVars) {
 g2 <- ggplot( MyData
 , aes_string( x = "RefDate"
 , y = paste0( "`", A, "`")
 )
 ) +
   geom_line() +
   labs( title = paste( A, "adjusted" ) )
   print( g2 )
 # ggsave( paste0( A,".jpg" )
 #   ,g2
 #   ,height=5
 #   ,width=8
 #   ,dpi=300
 #   )
}


# Using function FQPC here - works, but an inferior use of ggplot
# because ggplot does not build legends with wide data

FQPC <- function(x) {100*x/lag(x,1)-100} # % change
for (A in MyVars) {
 g2 <- ggplot( MyData
 , aes( x = RefDate
  , y = FQPC( !!sym( A ) )
  )
 ) +
   geom_line() +
   labs(title = paste( A,"adjusted" ) )
 print( g2 )
 # ggsave( paste0( A,".jpg" )
 # ,g2
 # ,height=5
 # ,width=8
 # ,dpi=300
 # )
}
#> Warning: Removed 1 rows containing missing values (geom_path).
#'
#> Warning: Removed 1 rows containing missing values (geom_path).

# superior approach is to do the computations first

for ( A in MyVars ) {
  DF <- MyData[ , c( "RefDate", A ) ]
  DF[[ 2 ]] <- FQPC( DF[[ 2 ]] )
  g2 <- ( ggplot( DF, aes( x = RefDate, y = !!sym( A ) ) )
+ geom_line()
+ labs( title = paste( A,"adjusted" ) )
)
  print( g2 )
}
#> Warning: Removed 1 rows containing missing values (geom_path).
#'
#> Warning: Removed 1 rows containing missing values (geom_path).

# Another way to do the computations first
resultDF <- data_frame( variable = MyVars
  , data = lapply( MyVars
 , function( A ) {
  DF <- setNames( MyData[ , c( 
"RefDate", A ) ]
, c( "RefDate", "value" 
)
)
  DF[[ 2 ]] <- FQPC( DF[[ 2 ]] )
  DF
   }
 )
  )
for ( i in seq.int( nrow( resultDF ) ) ) {
  A <- resultDF$variable[ i ]
  g2 <- ( ggplot( resultDF$data[[ i ]], aes( x = RefDate, y = value ) )
+ geom_line()
+ ylab( A )
+ labs( title = paste( A, "adjusted" ) )
)
  print( g2 )
}
#> Warning: Removed 1 rows containing missing values (geom_path).

#' #> Warning: Removed 1 rows containing missing values (geom_path).

# or put them together in order determined by MyVars:

resultDF %>%
mutate( variable = factor( variable, levels = MyVars ) ) %>%
unnest %>% # flattens separate data frames in data column into one long 
data frame

ggplot( aes( x = RefDate, y = value ) ) +
  geom_line() +
  facet_grid( variable ~ ., scales = "free_y" )
#> Warning: Removed 1 rows containing missing values (geom_path).

#' Created on 2018-09-05 by the [reprex package](http://reprex.tidyverse.org) 
(v0.2.0).
#33

On Wed, 5 Sep 2018, phili...@cpanel1.stormweb.net wrote:

Thanks again for your help. Your suggested solution using aes_string(), which 
I was not familiar with, worked perfectly when I plotted the column 
variables. However, I also want to plot transformations of those variables 
and the aes_string() approach does not work in that case. I implement the 
transformations with a function and the function is expecting a numeric 
rather than a string.


For example, when I use the function:

library(dplyr)
library(ggplot2)
`RefDate` <- as.Date(c("2010-11-1","2010-12-01","2011-01-01"))
`Number of vegetables` <- c(14,23,45)
`Number of people` <- c(20,30,40)
MyData <- data.frame(RefDate
   ,`Number of vegetables`
   ,`Number of people`
   ,check.names=FALSE
   )
MyVars <- c("Number of vegetables","Number of people")

# No function here - it works

for (A in MyVars) {
g2 <- ggplot(MyData
   

Re: [R] Multi-word column names in a data frame

2018-09-04 Thread Jeff Newmiller

a) missing ggplot2 library
b) cannot word wrap in the middle of a string in R without introducing 
newlines
c) aes is not recommended for working with string variables as names... 
use aes_string

d) Because aes_string will parse the string, you need to add the backticks
e) paste0() is a shorter version of paste( sep="" )

##
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
`RefDate` <- as.Date(c("2010-11-1","2010-12-01","2011-01-01"))
`Number of vegetables` <- c(14,23,45)
`Number of people` <- c(20,30,40)
MyData <- data.frame( RefDate
, `Number of vegetables`
, `Number of people`
, check.names = FALSE
)
MyVars <- c( "Number of vegetables", "Number of people" )
for ( A in MyVars ) {
  g2 <- ggplot( MyData
  , aes_string( x = RefDate
  , y = paste0( "`", A, "`" )
  )
  ) +
geom_line() +
labs( title = paste0( A, " adjusted" ) )
  g2
  ggsave( paste0( A, ".jpg" )
, g2
, height=5
, width=8
, dpi=300
)
}

#' Created on 2018-09-05 by the [reprex package](http://reprex.tidyverse.org) 
(v0.2.0).
###33

On Tue, 4 Sep 2018, phili...@cpanel1.stormweb.net wrote:

I am having trouble working with column names in a data frame. My column 
names are multi-word text strings and I like it that way. I want to loop 
through the columns, plotting graphs for each one, and I want to use the 
column names in the chart labels and in the file names when I save the 
charts. Here is a simple reproducible example that does not work.


library(dplyr)
`RefDate` <- as.Date(c("2010-11-1","2010-12-01","2011-01-01"))
`Number of vegetables` <- c(14,23,45)
`Number of people` <- c(20,30,40)
MyData <- data.frame(RefDate,`Number of vegetables`,`Number of 
people`,check.names=FALSE)

MyVars <- c("Number of vegetables","Number of people")
for (A in MyVars) {
g2 <- ggplot(MyData,aes(RefDate,eval(parse(text=A + geom_line() +
  labs(title = paste(A," adjusted",sep=""))
g2
ggsave(paste(A,".jpg",sep=""),g2,height=5,width=8,dpi=300)
}

Philip

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


---
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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Multi-word column names in a data frame

2018-09-04 Thread Jim Lemon
Hi Philip,
This may work:

library(dplyr)
`RefDate` <- as.Date(c("2010-11-1","2010-12-01","2011-01-01"))
`Number of vegetables` <- c(14,23,45)
`Number of people` <- c(20,30,40)
MyData <- data.frame(RefDate,`Number_of_vegetables`,
 `Number_of_people`,check.names=FALSE)
MyVars <- c("Number of vegetables","Number of people")
My_Vars <- c("Number_of_vegetables","Number_of_people")
nnames<-length(MyVars)
for (i in 1:nnames) {
   g2 <- ggplot(MyData,aes(RefDate,eval(parse(text=My_Vars[i] +
geom_line() +
 labs(title = paste(MyVars[i]," adjusted",sep=""))
   g2
   ggsave(paste(A,".jpg",sep=""),g2,height=5,width=8,dpi=300)
}

Jim
On Wed, Sep 5, 2018 at 1:22 PM  wrote:
>
> I am having trouble working with column names in a data frame. My
> column names are multi-word text strings and I like it that way. I
> want to loop through the columns, plotting graphs for each one, and I
> want to use the column names in the chart labels and in the file names
> when I save the charts. Here is a simple reproducible example that
> does not work.
>
> library(dplyr)
> `RefDate` <- as.Date(c("2010-11-1","2010-12-01","2011-01-01"))
> `Number of vegetables` <- c(14,23,45)
> `Number of people` <- c(20,30,40)
> MyData <- data.frame(RefDate,`Number of vegetables`,`Number of
> people`,check.names=FALSE)
> MyVars <- c("Number of vegetables","Number of people")
> for (A in MyVars) {
>g2 <- ggplot(MyData,aes(RefDate,eval(parse(text=A + geom_line() +
>  labs(title = paste(A," adjusted",sep=""))
>g2
>ggsave(paste(A,".jpg",sep=""),g2,height=5,width=8,dpi=300)
> }
>
> Philip
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] multi variable analysis

2017-10-08 Thread Ranjan Maitra
Arun,

I would suggest either getting enrolled in a multivariate statistics class and 
the pre-requisites for this or going back to your boss and asking him or her to 
hire a MS-level statistician since this is clearly beyond your current state of 
knowledge. 

Don't expect R-help to be a free consulting service. And of course, your query 
has nothing to do with R.

Thanks,
Ranjan

On Sun, 8 Oct 2017 19:57:11 +0530 Arun Kumar  wrote:

> Hi All,
> 
> I have been given three raw data csv files related to an advertising
> campaign. Impressions, clicks and conversion. They asked me to suggest
> optimisation suggestions using uni variable and multi variable analysis.
> The clicks or conversions are spread across various parameters like device,
> country, city, ad type, browser, postal code etc. How do I approach the
> analysis and modelling in this regard.
> 
> Thanks,
> Arun
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


-- 
Important Notice: This mailbox is ignored: e-mails are set to be deleted on 
receipt. Please respond to the mailing list if appropriate. For those needing 
to send personal or professional e-mail, please use appropriate addresses.

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


Re: [R] Multi-GPU "Yinyang" K-means and K-nn for R

2017-02-23 Thread Charles Determan
Hi Vadim,

I would be happy to explore helping you out with this.  I am quite active
in development for GPU use in R.  You can see my work on my github (
https://github.com/cdeterman) and the group I created for additional
packages in development (https://github.com/gpuRcore).  I believe it would
be best though to take this conversation off list though.  If you would
like to discuss this further please email me separately.

Kind regards,
Charles


On Thu, Feb 23, 2017 at 4:37 AM, Vadim Markovtsev 
wrote:

> ¡Hola!
>
> This is to announce that [kmcuda](https://github.com/src-d/kmcuda) has
> obtained native R bindings and ask for the help with CRAN packaging.
> kmcuda is my child: an efficient GPGPU (CUDA) library to do K-means
> and K-nn on as much data as fits into memory. It supports running on
> multiple GPUs simultaneously, angular distance metric, Yinyang
> refinement, float16 (well, not in R for sure), K-means++ and AFK-MC2
> initialization. I am thinking about Minibatch in the near future.
>
> Usage example:
>
> dyn.load("libKMCUDA.so")
> samples <- replicate(4, runif(16000))
> result = .External("kmeans_cuda", samples, 50, tolerance=0.01,
>  seed=777, verbosity=1)
> print(result$centroids)
> print(result$assignments[1:10,])
>
> This library only supports Linux and macOS at the moment. Windows
> port is welcome.
>
> I knew pretty much nothing about R a week ago so would be glad to your
> suggestions. Besides, I've never published anything to CRAN and it
> will take some time for me to design a full package following the
> guidelines and rules. It will be awesome If somebody is willing to
> help! It seems to be the special fun to package the CUDA+OpenMP
> code for R and this fun doubles on macOS where you need a specific
> combination of two different clang compilers to make it work.
>
> Besides, I have a question which prevents me from sleeping at night:
> how is R able to support matrices with dimensions larger than
> INT32_MAX if the only integer type in C API is int (32-bit signed on
> Linux)? Even getting the dimensions with INTEGER() automatically leads
> to the overflow.
> --
> Best regards,
>
> Vadim Markovtsev
> Lead Machine Learning Engineer || source{d} / sourced.tech / Madrid
> StackOverflow: 69708/markhor | GitHub: vmarkovtsev | data.world:
> vmarkovtsev
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Multi-level Meta-Regression using metafor

2016-11-18 Thread Michael Dewey

Dear Janina

On 18/11/2016 12:04, Janina Steinert wrote:

Hi!

I am running a multi-level meta-regression in R using the metafor package.
I have specified a univariate multi-level meta-regression as follows:

Test_MR <- rma.mv(yi = effectsize_estimates, V = effsize_sd2, data = Test,
  mods = ~ x, random = list(~ 1 | coeff, ~ 1 | study))

Can someone help explain what this code specifies exactly? Can I define
this as a mixed-effects model whereby the moderator X is a fixed effect and
random effects denote heterogeneity of effect sizes within study clusters
and between clusters?

Can someone explain what the ~1 at the end of the line specifies?


The ~ sign is part of a formula and the 1 means the intercept so you are 
saying you want a random intercept for each coeff and for each study. 
You are correct that x is the fixed effect of the moderator.


Have you looked at some of the examples on the metafor website? There is 
a whole range there which cover some of the issues you raise. Point your 
browser at http://www.metafor-project.org/ and then look for the tips 
and for the analyses in the navigation panel.



Thank you!

[[alternative HTML version deleted]]

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



--
Michael
http://www.dewey.myzen.co.uk/home.html

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


Re: [R] Multi-line forestplots, how to in R

2015-08-14 Thread Michael Dewey

Read Ella

Comments in-line below

On 14/08/2015 00:36, mcknight e. (em8g14) wrote:

Hello,


I am working on ecological data covering a meta-analysis on invasive species 
traits.


I am not very skilled in R and would love if someone could assist me in my 
production of multi-line forest plots.

The data I have is: random effects mixed model and is further divided into 
subsets, I have used metafor package and here is a breakdown of my code =

#this is my main data calculation into effect sizes

MA - escalc (measure=SMD, m1i=Invasive..mean, sd1i=sd.invasive, 
n1i=N.invasive, m2i=Control.mean, sd2i=sd.control, n2i=N.control, data=dataset)

res.MA - rma(yi,vi,data=MA,method=REML);res.MA  #random-effects models ; 
HS Viechtbauer (2005)



Why does your comment say HS when you have in fact asked for it to 
estimate tau^2 using REML (which is the default)?


#separating data
lab - subset (x=MA, Type.of.ex==Lab)
field - subset (x=MA, Type.of.ex==Field)



You do not need to do that since rma.uni has a subset parameter as you 
use later



res.MAlab - rma(yi,vi,data=lab,method=REML);res.MAlab  #random-effects models ; 
HS Viechtbauer (2005)
res.MAfield - rma(yi,vi,data=field,method=REML);res.MAfield  #random-effects models ; 
HS Viechtbauer (2005)



Could you not get the estimates you want by using Type.of.ex as a 
moderator here with the full dataset?


From here on it is difficult to be sure what to say without more 
knowledge about your dataset and the underlying science but I wonder 
whether in fact you need to fit a multivariate model instead if you have 
(say) k studies each giving 6 trait estimates, and so on. If that is the 
way to go you need to read


?rma.mv

Please set your mailer to not send HTML as it mangles your messages and 
it is more readable if you (a) put each command on a separate line (b) 
use more spaces. Disk space is cheap.




res.traitlab - rma(yi,vi,mods= ~ factor(Trait)-1,data=lab);res.traitlab #model 
for traits

res.traitfield - rma(yi,vi,mods= ~ factor(Trait)-1,data=field);res.traitfield

#model for each lab traits

res.labct - rma(yi,vi,subset=Trait==Consumption,data=lab);res.labct
res.labec - rma(yi,vi,subset=Trait==Exploitative 
competition,data=lab);res.labec
res.labgr - rma(yi,vi,subset=Trait==Growth,data=lab);res.labgr
res.labic - rma(yi,vi,subset=Trait==Interference 
competition,data=lab);res.labic
res.labpa - rma(yi,vi,subset=Trait==Predator avoidance,data=lab);res.labpa
res.labpe - rma(yi,vi,subset=Trait==Predator escape,data=lab);res.labpe

#model for each field traits

res.fieldct - rma(yi,vi,subset=Trait==Consumption,data=field);res.labct
res.fieldec - rma(yi,vi,subset=Trait==Exploitative 
competition,data=field);res.labec
res.fieldgr - rma(yi,vi,subset=Trait==Growth,data=field);res.labgr
res.fieldic - rma(yi,vi,subset=Trait==Interference 
competition,data=field);res.labic
res.fieldpa - rma(yi,vi,subset=Trait==Predator 
avoidance,data=field);res.labpa
res.fieldpe - rma(yi,vi,subset=Trait==Predator escape,data=field);res.labpe

#producing a graph for lab data

estimateslab - c(coef(res.labct), coef(res.labec), coef(res.labgr), 
coef(res.labic), coef(res.labpa),coef(res.labpe))
varianceslab - c(vcov(res.labct), vcov(res.labec), vcov(res.labgr), 
vcov(res.labic), vcov(res.labpa),vcov(res.labpe))
labelslab - c(Consumption (109),Exploitative competition (21),Growth (33),Interference 
competition (31),Predator avoidance (4),Predator escape (61))
forest(estimateslab, varianceslab, slab=labelslab, digit=0, annotate=F, xlab=Mean 
effect size,ylim=c(0,11))

#producing a graph for field data

estimatesfield - c(coef(res.fieldct),coef(res.fieldec), coef(res.fieldgr), 
coef(res.fieldic),coef(res.fieldpa),coef(res.fieldpe))
variancesfield - c(vcov(res.fieldct),vcov(res.fieldec), vcov(res.fieldgr), 
vcov(res.fieldic), vcov(res.fieldpa),   vcov(res.fieldpe))
labelsfield - c(Consumption (7),Exploitative competition (19),Growth (2),Interference 
competition (34),Predator avoidance (2),Predator escape (15))
forest(estimatesfield, variancesfield, slab=labelsfield,digit=0,annotate=F,xlab=Mean effect 
size,ylim=c(0,11)) # psize=1 size of mean box on forest plot
addpoly(res.MAfield, row=0.2, cex=1, atransf=F, mlab=RE Model Field Studies 
(79),annotate=F)


OK, so sorry for code overload... I hope you can understand what i have done.

What i need it to produce one graph with both data sets Lab and field showing 
effect sizes for each of the mentioned traits. Im not super up to scratch on R 
and some of the current code was shared through a colleague, however this 
person isnt great at plots.


Please please can someone help me. Im currently wasting heaps of my time and 
getting no where.

Sincerely grateful

Ella

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 

Re: [R] multi core procesing

2015-07-15 Thread Duncan Murdoch
On 15/07/2015 2:33 PM, Vyshnnavi Parthasarathy wrote:
 Hello,
 I am using a 8 core processor system. Is there a way to run different R
 scripts on different cores instead of all scripts running on the same core?
 If I open a new RStudio session for each script, can I somehow assign each
 Rstudio session to a particular core processor so as to make the process
 efficient? I have looked at the doParallel package and from my
 understanding including the package enables one script to be run using
 multiple cores but what I am looking for is being able to run different
 scripts on different cores.

This is a question about your OS, isn't it?  Does your OS allow you to
run multiple processes on different cores?  Or maybe this is a question
about RStudio.  Does it allow multiple instances to run on the same
computer, so your OS can allocate them to different cores?

If you run your scripts in R (not under RStudio) it's certainly possible
to have multiple R processes running at the same time.  Just do it.

Duncan Murdoch

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


Re: [R] multi-threading

2014-09-10 Thread Pascal Oettli
Hi Yuan,

You can start reading the following site:
http://cran.r-project.org/web/views/HighPerformanceComputing.html

Regards,
Pascal

On Wed, Sep 10, 2014 at 2:56 PM, Yuan Luo yuan.hypnos@gmail.com wrote:
 Hi,
 I am merging large data frames and it would be great if I can run merge in
 multi-threading/parallel mode. Can someone point me to the right way to do
 it?

 Best,
 Yuan

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



-- 
Pascal Oettli
Project Scientist
JAMSTEC
Yokohama, Japan

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


Re: [R] multi

2013-11-05 Thread arun
Hi,
May be this helps:
set.seed(42)
 list1 - lapply(1:3, function(i) matrix(rnorm(4),2,2))
g - c(1,2,3)

fun1 - function(g,hessianList){
  mat1 - vector(mode=list,length=length(g))
   for(i in seq_along(g)){
 mat1[[i]] - g[i]*hessianList[[i]]
      }
Reduce(`+`,mat1)
  
}

#or
fun2 - function(g,hessianList){
lst1 - lapply(seq_along(g),function(i) g[i]*hessianList[[i]])
Reduce(`+`,lst1)
}
identical(fun1(g,list1),fun2(g,list1))
#[1] TRUE
A.K.



On Tuesday, November 5, 2013 1:02 PM, IZHAK shabsogh ishaqb...@yahoo.com 
wrote:


[[1]]
 [,1]  [,2]
[1,]  0.003632559 0.2190629
[2,] -2.090772847 0.2190629

[[2]]
    [,1]   [,2]
[1,] 0.004278991 0.04337005
[2,] 0.190723602 0.04337005

[[3]]
   [,1]    [,2]
[1,] 0.01237827 -0.01544811
[2,] 0.06452200 -0.01544811

g-c(1,2,3)

function(g,hessianList){
   for(i in 1:3){
         ft1-g[2]*hessianList[[2]]
         ft2-sum(ft1)
         ft2
   }
}

can u please help me find out what is the problem with this code

i want to multiply matrix 1-3 by a vector g and sum the result.


thanks
    [[alternative HTML version deleted]]

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


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


Re: [R] multi

2013-11-05 Thread Adams, Jean
It's easier for folks to help you if you make your data available by
reproducible code.  You can do this using the dput() function.  So, for
example, you could share your hessianList with us using
 dput(hessianList)
and then including this code in your post

hessianList - list(structure(c(0.003632559, -2.090772847, 0.2190629,
0.2190629
), .Dim = c(2L, 2L)), structure(c(0.004278991, 0.190723602, 0.04337005,
 0.04337005), .Dim = c(2L, 2L)), structure(c(0.01237827, 0.064522,
-0.01544811, -0.01544811), .Dim = c(2L, 2L)))

I'm not exactly sure what output you're looking for, but this may help ...

# perform the calculation straight out
sapply(seq(hessianList), function(i) sum(g[i]*hessianList[[i]]))

# or

# define a function to do the calculation on the provided vector and list
myfun - function(V, L){
sapply(seq(L), function(i) sum(V[i]*L[[i]]))
 }
myfun(g, hessianList)

Jean


On Tue, Nov 5, 2013 at 11:40 AM, IZHAK shabsogh ishaqb...@yahoo.com wrote:



 [[1]]
  [,1]  [,2]
 [1,]  0.003632559 0.2190629
 [2,] -2.090772847 0.2190629

 [[2]]
 [,1]   [,2]
 [1,] 0.004278991 0.04337005
 [2,] 0.190723602 0.04337005

 [[3]]
[,1][,2]
 [1,] 0.01237827 -0.01544811
 [2,] 0.06452200 -0.01544811

 g-c(1,2,3)

 function(g,hessianList){
for(i in 1:3){
  ft1-g[2]*hessianList[[2]]
  ft2-sum(ft1)
  ft2
}
 }

 can u please help me find out what is the problem with this code

 i want to multiply matrix 1-3 by a vector g and sum the result.


 thanks
 [[alternative HTML version deleted]]


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



[[alternative HTML version deleted]]

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


Re: [R] Multi Correspondence Analysis

2013-08-16 Thread arun
Hi,

You can upload the dataset using:
library(XLConnect)
 wb-loadWorkbook(excel_data.xlsx)
 dat1- readWorksheet(wb,sheet=excel data,region=A1:DA101) #region can be 
specified to read a subset of the dataset.  Here, I read the full #dataset.

dim(dat1)
#[1] 100 105
str(dat1)
#'data.frame':    100 obs. of  105 variables:
# $ cid : num  17226 26226 32226 47226 48226 ...
# $ q14a_1  : chr  6 5 6 6 ...
# $ q14a_2  : chr  6 7 6 5 ...
# $ q14a_3  : chr  6 6 6 5 ...



There are a lot of missing values.  


Other option would be to save the file .csv and call by read.csv().  In that 
case, only the active sheet will be saved.

#For example: after saving the file as excel_data.csv

dat2- read.csv(excel_data.csv,header=TRUE,stringsAsFactors=FALSE)

 dim(dat2)
#[1] 100 105


Regarding the multi correspondence analysis, the link below may help you.
http://gastonsanchez.wordpress.com/2012/10/13/5-functions-to-do-multiple-correspondence-analysis-in-r/

A.K.





Hi everyone, 

I am new with R and I need some help. 

I have the following data 

excel_data.xlsx

And I would like to upload it in R and run a multi correspondence analysis. 

Any help will be really appreciate it. 

Thanks in advance, 

mils

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


Re: [R] multi-condition summing puzzle

2013-07-12 Thread arun
Hi,
May be this helps:

dat1- read.table(text=
ID county date company 
1   x  1   comp1
2   y  1   comp3
3   y  2   comp1
4   y  3   comp1
5    x  2  comp2
,sep=,header=TRUE,stringsAsFactors=FALSE)
dat2- dat1
dat1$answer-unsplit(lapply(split(dat1,dat1$county),function(x) 
do.call(rbind,lapply(seq_len(nrow(x)),function(i) {x1-x[1:i,]; 
x2-table(x1$company)/sum(table(x1$company));sum(x2^2)}))),dat1$county)
 dat1
#  ID county date company    answer
#1  1  x    1   comp1 1.000
#2  2  y    1   comp3 1.000
#3  3  y    2   comp1 0.500
#4  4  y    3   comp1 0.556
#5  5  x    2   comp2 0.500

#or
dat2$answer-with(dat2,unlist(ave(company,county,FUN=function(x) 
lapply(seq_along(x),function(i) {x1-table(x[1:i]);sum((x1/sum(x1))^2)}
 dat2
#  ID county date company    answer
#1  1  x    1   comp1 1.000
#2  2  y    1   comp3 1.000
#3  3  y    2   comp1 0.500
#4  4  y    3   comp1 0.556
#5  5  x    2   comp2 0.500

A.K.

Hi - 

I have a seemingly complex data summarizing problem that I am having a hard 
time wrapping my mind around. 

What I'm trying to do is sum the square of all company market 
shares  in a given county, UP TO that corresponding time. Sum of market 
share is defined as: Number of company observations/ Total observations. 

Here is example data and desired answer: 

ID  county  datecompany answer
1      x      1        comp1           1
2      y      1        comp3           1
3      y      2        comp1           0.5
4      y      3        comp1           0.6
5       x     2       comp2           0.5

For example, to get the answer for ID 4, we look at county y, dates 1, 2, 3 and 
sum:  [(2/3)comp1]^2 +[(1/3)comp3]^2 = 0.6 

I've tried cumsum, but am simply stuck given all of the 
different conditions.  I have a large matrix of data for this with 
several hundred companies, tens of counties and unique dates. 

Any help would be extremely appreciated. 

Thank you,

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


Re: [R] multi user environment concept of access/authorization levels

2013-04-05 Thread Uwe Ligges



On 05.04.2013 14:15, lejeczek wrote:

hi everybody

the subject may seem a bit over the top but,
I wonder if there is way in R to separate/segregate users
into different access levels/categories
simply, user A cannot perform certain tasks, cannot use
certain libraries or their certainfunctions?

possible now? in the futuremaybe?



You want to restrict access to the t-test for graduated students? And 
quantile regression requires a phd degree?


Honestly: hopefully not. R is open source software and does not 
distinguish between users.


Best,
Uwe Ligges


regards

[[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] multi-comparison of means

2013-03-14 Thread meng
Many thanks
 





 


At 2013-03-14 00:23:43,Richard M. Heiberger r...@temple.edu wrote:
Meng,


What seems to be going on is that the covariates are handled very differently 
in TukeyHSD and in glht.


Please see the interaction_average and covariate_average arguments to glht.


I ran your example twice, first as you did, with the covariates after the 
factor.
x2 is not significant if the factor comes first.


The second time I placed the covariates before the factor.




 result_aov - aov(y ~ method + x1 + x2, data=meng)
 anova(result_aov)
Analysis of Variance Table


Response: y
  Df Sum Sq Mean Sq F valuePr(F)
method 2 4.4705 2.23525 41.3822 1.170e-08 ***
x1 1 2.8352 2.83519 52.4892 1.363e-07 ***
x2 1 0.0747 0.07469  1.38270.2507
Residuals 25 1.3504 0.05401  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
 result2_aov - aov(y ~ x1 + x2 + method, data=meng)
 anova(result2_aov)
Analysis of Variance Table


Response: y
  Df Sum Sq Mean Sq  F valuePr(F)
x1 1 5.4399  5.4399 100.7113 2.985e-10 ***
x2 1 0.3134  0.3134   5.8017   0.02371 *  
method 2 1.6271  0.8135  15.0616 5.100e-05 ***
Residuals 25 1.3504  0.0540   
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 




Looking at the plot of your data shows a very interesting pattern.


 xyplot(y ~ x1 + x2 | method, outer=TRUE, data=meng)


b and c both give higher values of y than does a.  You will also see
that in the table of means.


Although I leave the interpretation of x1 and x2 to you, my inclination is
to drop x2 and look at the ancova of method and x1.


ancova is in the HH package.
## install.packages(HH)  ## if you don't have it yet.
library(HH)


 result3_aov - ancova(y ~ method + x1, data=meng)
 result3_aov
Analysis of Variance Table


Response: y
  Df Sum Sq Mean Sq F valuePr(F)
method 2 4.4705 2.23525  40.782 9.616e-09 ***
x1 1 2.8352 2.83519  51.728 1.226e-07 ***
Residuals 26 1.4251 0.05481  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
 update(attr(result3_aov, trellis), ylim=c(3.5, 6.7))
 


Now it looks like conditional on x1, all three methods differ.

Rich


On Wed, Mar 13, 2013 at 7:15 AM, meng laomen...@163.com wrote:
Hi all:
I have a question about multi-comparison.

The data is in the attachment.

My purpose:
Compare the predicted means of the 3 methods(a,b,c) pairwisely.

I have 3 ideas:

#idea1
result_aov-aov(y~ method + x1 + x2)
TukeyHSD(result_aov)
 difflwr   upr p adj
b-a  0.845  0.5861098 1.1038902 0.001
c-a  0.790  0.5311098 1.0488902 0.002
c-b -0.055 -0.3138902 0.2038902 0.8578386

#idea2
library(multcomp)
summary(glht(result_aov,linfct=mcp(method=Tukey)))
 Estimate Std. Error t value Pr(|t|)
b - a == 0   0.3239 0.1402   2.309   0.0683 .
c - a == 0  -0.3332 0.1937  -1.720   0.2069
c - b == 0  -0.6570 0.1325  -4.960   0.001 ***

#idea3
#ref=a
dat$method - relevel(dat$method, ref=a)
lm_ref_a-lm(y~method + x1 + x2)
summary(lm_ref_a)
Coefficients:
Estimate Std. Error t value Pr(|t|)
(Intercept)  0.922020.64418   1.431   0.1647
methodb  0.323890.14025   2.309   0.0295 *
methodc -0.333160.19372  -1.720   0.0978 .
x1   0.579350.09356   6.192 1.78e-06 ***
x2   0.135960.11563   1.176   0.2507

#ref=b
dat$method - relevel(dat$method, ref=b)
lm_ref_b-lm(y~method + x1 + x2)
summary(lm_ref_b)

Coefficients:
Estimate Std. Error t value Pr(|t|)
(Intercept)  1.245910.73770   1.689   0.1037
methoda -0.323890.14025  -2.309   0.0295 *
methodc -0.657050.13248  -4.960 4.14e-05 ***


In summary:
idea1:
a vs b:pvalue=0.001
a vs c:pvalue=0.002
b vs c:pvalue=0.8578386
idea2:
a vs b:pvalue=0.0683
a vs c:pvalue=0.2069
b vs c:pvalue0.001
idea3:
a vs b:pvalue=0.0295
a vs c:pvalue=0.0978
b vs c:pvalue=4.14e-05

So the result of 3 ideas are different,and I don't know which one is correct.
Many thanks for your help.

My best
 
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] multi-comparison of means

2013-03-13 Thread Richard M. Heiberger
Meng,

What seems to be going on is that the covariates are handled very
differently in TukeyHSD and in glht.

Please see the interaction_average and covariate_average arguments to glht.

I ran your example twice, first as you did, with the covariates after the
factor.
x2 is not significant if the factor comes first.

The second time I placed the covariates before the factor.


 result_aov - aov(y ~ method + x1 + x2, data=meng)
 anova(result_aov)
Analysis of Variance Table

Response: y
  Df Sum Sq Mean Sq F valuePr(F)
method 2 4.4705 2.23525 41.3822 1.170e-08 ***
x1 1 2.8352 2.83519 52.4892 1.363e-07 ***
x2 1 0.0747 0.07469  1.38270.2507
Residuals 25 1.3504 0.05401
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
 result2_aov - aov(y ~ x1 + x2 + method, data=meng)
 anova(result2_aov)
Analysis of Variance Table

Response: y
  Df Sum Sq Mean Sq  F valuePr(F)
x1 1 5.4399  5.4399 100.7113 2.985e-10 ***
x2 1 0.3134  0.3134   5.8017   0.02371 *
method 2 1.6271  0.8135  15.0616 5.100e-05 ***
Residuals 25 1.3504  0.0540
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Looking at the plot of your data shows a very interesting pattern.

 xyplot(y ~ x1 + x2 | method, outer=TRUE, data=meng)

b and c both give higher values of y than does a.  You will also see
that in the table of means.

Although I leave the interpretation of x1 and x2 to you, my inclination is
to drop x2 and look at the ancova of method and x1.

ancova is in the HH package.
## install.packages(HH)  ## if you don't have it yet.
library(HH)

 result3_aov - ancova(y ~ method + x1, data=meng)
 result3_aov
Analysis of Variance Table

Response: y
  Df Sum Sq Mean Sq F valuePr(F)
method 2 4.4705 2.23525  40.782 9.616e-09 ***
x1 1 2.8352 2.83519  51.728 1.226e-07 ***
Residuals 26 1.4251 0.05481
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
 update(attr(result3_aov, trellis), ylim=c(3.5, 6.7))


Now it looks like conditional on x1, all three methods differ.

Rich

On Wed, Mar 13, 2013 at 7:15 AM, meng laomen...@163.com wrote:

 Hi all:
 I have a question about multi-comparison.

 The data is in the attachment.

 My purpose:
 Compare the predicted means of the 3 methods(a,b,c) pairwisely.

 I have 3 ideas:

 #idea1
 result_aov-aov(y~ method + x1 + x2)
 TukeyHSD(result_aov)
  difflwr   upr p adj
 b-a  0.845  0.5861098 1.1038902 0.001
 c-a  0.790  0.5311098 1.0488902 0.002
 c-b -0.055 -0.3138902 0.2038902 0.8578386

 #idea2
 library(multcomp)
 summary(glht(result_aov,linfct=mcp(method=Tukey)))
  Estimate Std. Error t value Pr(|t|)
 b - a == 0   0.3239 0.1402   2.309   0.0683 .
 c - a == 0  -0.3332 0.1937  -1.720   0.2069
 c - b == 0  -0.6570 0.1325  -4.960   0.001 ***

 #idea3
 #ref=a
 dat$method - relevel(dat$method, ref=a)
 lm_ref_a-lm(y~method + x1 + x2)
 summary(lm_ref_a)
 Coefficients:
 Estimate Std. Error t value Pr(|t|)
 (Intercept)  0.922020.64418   1.431   0.1647
 methodb  0.323890.14025   2.309   0.0295 *
 methodc -0.333160.19372  -1.720   0.0978 .
 x1   0.579350.09356   6.192 1.78e-06 ***
 x2   0.135960.11563   1.176   0.2507

 #ref=b
 dat$method - relevel(dat$method, ref=b)
 lm_ref_b-lm(y~method + x1 + x2)
 summary(lm_ref_b)

 Coefficients:
 Estimate Std. Error t value Pr(|t|)
 (Intercept)  1.245910.73770   1.689   0.1037
 methoda -0.323890.14025  -2.309   0.0295 *
 methodc -0.657050.13248  -4.960 4.14e-05 ***


 In summary:
 idea1:
 a vs b:pvalue=0.001
 a vs c:pvalue=0.002
 b vs c:pvalue=0.8578386
 idea2:
 a vs b:pvalue=0.0683
 a vs c:pvalue=0.2069
 b vs c:pvalue0.001
 idea3:
 a vs b:pvalue=0.0295
 a vs c:pvalue=0.0978
 b vs c:pvalue=4.14e-05

 So the result of 3 ideas are different,and I don't know which one is
 correct.
 Many thanks for your help.

 My best

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

2012-12-18 Thread Berend Hasselman

Forgot to cc the help list.

On 18-12-2012, at 19:40, Lu, James T wrote:

 I am attempting to use optim to solve a neural network problem.  I would like 
 to optimize coefficients that are currently stored in a matrix
 
 Y=270 x 1
 X= 27- x 14
 b1= 10x14
 b2= 11x1
 V= 10 x 14 set of prior variances.
 
 I have the following function:
 
 posterior.mode1=function(y,X,b_0,b2,V) {
 
 log.like=function(b1) {
   a_g=compute(b1)
   z_g=tanh(a_g);
   z_g=cbind(1,z_g)
   p=softmax(z_g%*%b2);
   a=sum(y*log(p)+(1-y)*log(1-p));
   return(a);
 }
 
 compute=function(b1) {
   a_g=NULL;
   for(i in 1:nrow(b1)){
 a_g=cbind(a_g,X%*%b1[i,])
   }
   return(a_g);
 }
 
 log.posterior=function(b1) {
   -log.like(b1)+1/2*t(as.vector(b1))%*%diag(as.vector(V))%*%as.vector(b1)
 }
 
 a=optim(b_0,log.posterior,method=CG,hessian=TRUE)
 return(a);
 }
 
 When I run
 
 posterior.mode1(y,X,b1,b2,b1)
 
 
 
 I get the following error
 
 
 
 Error in 1:nrow(b1) : argument of length 0

optim  treats parameter b_0 as a vector and passes as such to the function it 
is trying to optimize.
So in log.like you should convert b1 back to a matrix of the correct dimensions 
like so

  b1 - matrix(b1,nrow=10)

Then it should work.
Note: you haven't provided function softmax.

Berend

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


Re: [R] multi-panel figure: overall title for each row

2012-10-24 Thread Jean V Adams
Hannes,

A bit inelegant, but it works.  Try this:
mtext(Overall Title Row 2, outer=TRUE, line=-17) 
mtext(Overall Title Row 3, outer=TRUE, line=-34) 

Jean


capy_bara hettl...@few.vu.nl wrote on 10/23/2012 09:08:39 AM:
 
 Dear all,
 I have a 3x2 plot and in addition to the title of the individual plots I
 would like to have an overall title
 for each row.  I managed to get an overall title for the whole plot 
matrix
 with mtext:
 
 par(mfrow=(c(3,2)), mar=c(6.4,4.5,4.2, 1.8), oma=c(0,0,3,0))
 for (i in 1:6)
   barplot(sample(1:10,5), main=paste(Plot #,i))
 mtext(Overall Title Row 1, outer=TRUE)
 
 but I  cannot put an overall title in the middle above the titles of the
 plots in the second or third row. 
 If I use mtext within the loop, I can only add another title above an
 individual plot.
 
 I hope someone can help me, many thanks in advance
 
 Hannes

[[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] multi-panel figure: overall title for each row

2012-10-24 Thread Bert Gunter
A perhaps more elegant way to do it would be to use the ?layout
function rather than the ancient mfrow() to create space for both
titles and graphs. You could then e.g. draw your titles in the space
you created for titles.

-- Bert

On Wed, Oct 24, 2012 at 5:33 AM, Jean V Adams jvad...@usgs.gov wrote:
 Hannes,

 A bit inelegant, but it works.  Try this:
 mtext(Overall Title Row 2, outer=TRUE, line=-17)
 mtext(Overall Title Row 3, outer=TRUE, line=-34)

 Jean


 capy_bara hettl...@few.vu.nl wrote on 10/23/2012 09:08:39 AM:

 Dear all,
 I have a 3x2 plot and in addition to the title of the individual plots I
 would like to have an overall title
 for each row.  I managed to get an overall title for the whole plot
 matrix
 with mtext:

 par(mfrow=(c(3,2)), mar=c(6.4,4.5,4.2, 1.8), oma=c(0,0,3,0))
 for (i in 1:6)
   barplot(sample(1:10,5), main=paste(Plot #,i))
 mtext(Overall Title Row 1, outer=TRUE)

 but I  cannot put an overall title in the middle above the titles of the
 plots in the second or third row.
 If I use mtext within the loop, I can only add another title above an
 individual plot.

 I hope someone can help me, many thanks in advance

 Hannes

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

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


Re: [R] multi-column factor

2012-09-17 Thread Hadley Wickham
If you have a million levels is it really necessary to use a factor? I'm
not sure what advantages it will to have to a string in this circumstance
(especially since you don't seem to know the levels a priori but have to
learn them from the data).

Hadley

On Sunday, September 16, 2012, Sam Steingold wrote:

 I have a data frame with columns which draw on the same underlying
 universe, so I want them to be factors with the same level set:

 --8---cut here---start-8---
  z - data.frame(a=c(a,b,c),b=c(b,c,d),stringsAsFactors=FALSE)
  str(z)
 'data.frame':   3 obs. of  2 variables:
  $ a: chr  a b c
  $ b: chr  b c d
  z$a - factor(z$a,levels=union(z$a,z$b))
  z$b - factor(z$b,levels=union(z$a,z$b))
  str(z)
 'data.frame':   3 obs. of  2 variables:
  $ a: Factor w/ 4 levels a,b,c,d: 1 2 3
  $ b: Factor w/ 4 levels a,b,c,d: 2 3 4
 --8---cut here---end---8---
 factor(z$a,levels=union(z$a,z$b))
 is factor(z$a,levels=union(z$a,z$b)) the right way to handle this?
 maybe there is a better way to extract levels than union()?
 (bear in mind that I have ~10M rows and ~1M levels, so performance is an
 issue).

 Thanks!

 --
 Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X
 11.0.11103000
 http://www.childpsy.net/ http://iris.org.il http://honestreporting.com
 http://camera.org http://www.memritv.org http://jihadwatch.org
 When you talk to God, it's prayer; when He talks to you, it's
 schizophrenia.

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



-- 
RStudio / Rice University
http://had.co.nz/

[[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] multi-column factor

2012-09-16 Thread Rui Barradas

Hello,

The obvious simplification is to call union()  only once. With 10M rows 
it should save time.

Then I've asked myself whether unique() wouldn't be faster.


f1 - function(x){
x[[1]] - factor(x[[1]], levels = union(x[[1]], x[[2]]))
x[[2]] - factor(x[[2]], levels = union(x[[1]], x[[2]]))
x
}

f2 - function(x){
levels - union(x[[1]], x[[2]])
x[[1]] - factor(x[[1]], levels = levels)
x[[2]] - factor(x[[2]], levels = levels)
x
}

f3 - function(x){
levels - unique(c(x[[1]], x[[2]]))
x[[1]] - factor(x[[1]], levels = levels)
x[[2]] - factor(x[[2]], levels = levels)
x
}

set.seed(5467)
n - 1e7
z - data.frame(a = sample(letters[1:3], n, TRUE),
b = sample(letters[2:4], n, TRUE),
stringsAsFactors=FALSE)

t1 - system.time(z1 - f1(z))
t2 - system.time(z2 - f2(z))
t3 - system.time(z3 - f3(z))

identical(z1, z2) #[1] TRUE
identical(z1, z3) #[1] TRUE

rbind(t1, t2, t3)
   user.self sys.self elapsed user.child sys.child
t1  2.55 0.473.01 NANA
t2  1.57 0.291.87 NANA
t3  1.51 0.261.78 NANA

Hope this helps,

Rui Barradas

Em 16-09-2012 17:46, Sam Steingold escreveu:

I have a data frame with columns which draw on the same underlying
universe, so I want them to be factors with the same level set:

--8---cut here---start-8---

z - data.frame(a=c(a,b,c),b=c(b,c,d),stringsAsFactors=FALSE)
str(z)

'data.frame':   3 obs. of  2 variables:
  $ a: chr  a b c
  $ b: chr  b c d

z$a - factor(z$a,levels=union(z$a,z$b))
z$b - factor(z$b,levels=union(z$a,z$b))
str(z)

'data.frame':   3 obs. of  2 variables:
  $ a: Factor w/ 4 levels a,b,c,d: 1 2 3
  $ b: Factor w/ 4 levels a,b,c,d: 2 3 4
--8---cut here---end---8---
factor(z$a,levels=union(z$a,z$b))
is factor(z$a,levels=union(z$a,z$b)) the right way to handle this?
maybe there is a better way to extract levels than union()?
(bear in mind that I have ~10M rows and ~1M levels, so performance is an
issue).

Thanks!



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


Re: [R] Multi-threads in R

2012-06-17 Thread R. Michael Weylandt michael.weyla...@gmail.com
Take a look at the parallel package which ships with all current versions of R. 

Michael

On Jun 17, 2012, at 11:39 AM, Gary Dong pdxgary...@gmail.com wrote:

 Dear R users,
 
 I'm wonder if there is a easy way to make R use multi-CPUs on my computer.
 My computer has four CPUs but R uses only one. Thanks.
 
 Gary
 
[[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Multi-threads in R

2012-06-17 Thread Uwe Ligges



On 17.06.2012 19:04, R. Michael Weylandt michael.weyla...@gmail.com wrote:

Take a look at the parallel package which ships with all current versions of R.


which is the right answer for the body of the message. For the subject 
line: Take a look at multi-threaded BLAS which can be used with R.


Uwe Ligges


Michael

On Jun 17, 2012, at 11:39 AM, Gary Dongpdxgary...@gmail.com  wrote:


Dear R users,

I'm wonder if there is a easy way to make R use multi-CPUs on my computer.
My computer has four CPUs but R uses only one. Thanks.

Gary

[[alternative HTML version deleted]]

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


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

2012-06-17 Thread Gary Dong
Thanks for all replied.

I read the introduction of R parallel. Is it for loops only?

Gary


On Sun, Jun 17, 2012 at 10:04 AM, R. Michael Weylandt 
michael.weyla...@gmail.com michael.weyla...@gmail.com wrote:

 Take a look at the parallel package which ships with all current versions
 of R.

 Michael

 On Jun 17, 2012, at 11:39 AM, Gary Dong pdxgary...@gmail.com wrote:

  Dear R users,
 
  I'm wonder if there is a easy way to make R use multi-CPUs on my
 computer.
  My computer has four CPUs but R uses only one. Thanks.
 
  Gary
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

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


Re: [R] Multi-threads in R

2012-06-17 Thread R. Michael Weylandt
I would argue (somewhat emphatically) that the parallel facilities you
are looking at are absolutely not for `for` loops. `for` loops are a
control structure native to imperative programming and, as such, are
inherently stateful. This provides many advantages, but easy
parallelization is absolutely not one of them. Rather consider R as a
functional language and the appropriate control structure is the
Map(), most famously of MapReduce, but also inherent in R's *apply()
family of functions. The careful reader will note that here is where
parallelization is exposed. By being state-free, there's no inherent
sequentiality and, consequently, no barriers to parallel computing.

For a somewhat concrete example consider what it would take to do a
state-dependent simulation (like a gibbs sampler) in parallel: it is,
to my mind, quite non-trivial. Compare this to the question of doing
column sums of a matrix in parallel -- effectively trivial. The
parallelization afforded by R is of that second sort.

A red herring in this discussion is the foreach() formalism, but a
moment's thought suggests to me that foreach() is much closer to Map()
than to for().

Best,
Michael

On Sun, Jun 17, 2012 at 1:23 PM, Gary Dong pdxgary...@gmail.com wrote:
 Thanks for all replied.

 I read the introduction of R parallel. Is it for loops only?

 Gary


 On Sun, Jun 17, 2012 at 10:04 AM, R. Michael Weylandt
 michael.weyla...@gmail.com michael.weyla...@gmail.com wrote:

 Take a look at the parallel package which ships with all current versions
 of R.

 Michael

 On Jun 17, 2012, at 11:39 AM, Gary Dong pdxgary...@gmail.com wrote:

  Dear R users,
 
  I'm wonder if there is a easy way to make R use multi-CPUs on my
  computer.
  My computer has four CPUs but R uses only one. Thanks.
 
  Gary
 
     [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.



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


Re: [R] Multi-threads in R

2012-06-17 Thread Fabrice Tourre
I think multicore is one of answer if you can write your function in to lapply.

On Mon, Jun 18, 2012 at 12:14 PM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
 I would argue (somewhat emphatically) that the parallel facilities you
 are looking at are absolutely not for `for` loops. `for` loops are a
 control structure native to imperative programming and, as such, are
 inherently stateful. This provides many advantages, but easy
 parallelization is absolutely not one of them. Rather consider R as a
 functional language and the appropriate control structure is the
 Map(), most famously of MapReduce, but also inherent in R's *apply()
 family of functions. The careful reader will note that here is where
 parallelization is exposed. By being state-free, there's no inherent
 sequentiality and, consequently, no barriers to parallel computing.

 For a somewhat concrete example consider what it would take to do a
 state-dependent simulation (like a gibbs sampler) in parallel: it is,
 to my mind, quite non-trivial. Compare this to the question of doing
 column sums of a matrix in parallel -- effectively trivial. The
 parallelization afforded by R is of that second sort.

 A red herring in this discussion is the foreach() formalism, but a
 moment's thought suggests to me that foreach() is much closer to Map()
 than to for().

 Best,
 Michael

 On Sun, Jun 17, 2012 at 1:23 PM, Gary Dong pdxgary...@gmail.com wrote:
 Thanks for all replied.

 I read the introduction of R parallel. Is it for loops only?

 Gary


 On Sun, Jun 17, 2012 at 10:04 AM, R. Michael Weylandt
 michael.weyla...@gmail.com michael.weyla...@gmail.com wrote:

 Take a look at the parallel package which ships with all current versions
 of R.

 Michael

 On Jun 17, 2012, at 11:39 AM, Gary Dong pdxgary...@gmail.com wrote:

  Dear R users,
 
  I'm wonder if there is a easy way to make R use multi-CPUs on my
  computer.
  My computer has four CPUs but R uses only one. Thanks.
 
  Gary
 
     [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.



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

2012-04-21 Thread Uwe Ligges



On 21.04.2012 06:34, ivo welch wrote:

the vignette to the library(parallel) mentions snow repeatedly (esp
differences in its implementation in parallel from the original).
unfortunately, it doesn't give an example or tutorial for
multi-machine use with sockets.

could someone please point me to a simple working example, where a
master just has both itself and a 4-core slave on a second machine
(IP), and wants to execute an mclapply on a list on both machines,
like

master.ip- localhost
slave.ip- Rfriend@192.168.2.10  ## has key ssh access
mclapply( 1:100, function(x) { cat(x); Sys.sleep(1); x } )  # on both, 
please

iaw




With appropriate ssh keys that do not need passwords and with the same 
username on all machines, it should work out of the box. At least, it 
does for me:


Say you want two, one on your own machine, the other one on your friends:

 cl - makeCluster(c(localhost, 192.168.2.10), SOCK)

BEst,
Uwe Ligges




On Wed, Apr 18, 2012 at 1:01 PM, ivo welchivo.we...@gmail.com  wrote:

Dear R experts:

could someone please point me to a page that explains how to set up
more than 1 machine for library parallel (which is quickly becoming my
favorite!)

...

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

2012-04-21 Thread ivo welch
hi uwe---my box is different:

cl - makeCluster(c(localhost, welch, calc), SOCK)
Error in loadNamespace(name) : there is no package called 'snow'

this seems to be part of snow, not parallel.  ok, install snow first,
then rerun.

library(snow)
Attaching package: 'snow'

The following object(s) are masked from 'package:parallel':

clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, clusterSplit, makeCluster, parApply,
parCapply, parLapply,
parRapply, parSapply, splitIndices, stopCluster

bash: /Library/Frameworks/R.framework/Resources/bin/Rscript: No such
file or directory

but if I use two linux machines, it works.

now, how do I use parallel's mclapply with it?

best,

/iaw


Ivo Welch (ivo.we...@gmail.com)
J. Fred Weston Professor of Finance
Anderson School at UCLA, C519
http://www.ivo-welch.info/
Editor, Critical Finance Review, http://www.critical-finance-review.org/



2012/4/21 Uwe Ligges lig...@statistik.tu-dortmund.de:


 On 21.04.2012 06:34, ivo welch wrote:

 the vignette to the library(parallel) mentions snow repeatedly (esp
 differences in its implementation in parallel from the original).
 unfortunately, it doesn't give an example or tutorial for
 multi-machine use with sockets.

 could someone please point me to a simple working example, where a
 master just has both itself and a 4-core slave on a second machine
 (IP), and wants to execute an mclapply on a list on both machines,
 like

    master.ip- localhost
    slave.ip- Rfriend@192.168.2.10  ## has key ssh access
    mclapply( 1:100, function(x) { cat(x); Sys.sleep(1); x } )  # on both,
 please

 iaw




 With appropriate ssh keys that do not need passwords and with the same
 username on all machines, it should work out of the box. At least, it does
 for me:

 Say you want two, one on your own machine, the other one on your friends:

  cl - makeCluster(c(localhost, 192.168.2.10), SOCK)

 BEst,
 Uwe Ligges



 On Wed, Apr 18, 2012 at 1:01 PM, ivo welchivo.we...@gmail.com  wrote:

 Dear R experts:

 could someone please point me to a page that explains how to set up
 more than 1 machine for library parallel (which is quickly becoming my
 favorite!)

 ...

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

2012-04-21 Thread Uwe Ligges



On 21.04.2012 17:20, ivo welch wrote:

hi uwe---my box is different:

cl- makeCluster(c(localhost, welch, calc), SOCK)
Error in loadNamespace(name) : there is no package called 'snow'

this seems to be part of snow, not parallel.  ok, install snow first,
then rerun.



No, you just need snow to be installed, using the functions from 
parallel will load the snow Namespace, if installed.






library(snow)
Attaching package: 'snow'

The following object(s) are masked from 'package:parallel':

 clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, clusterSplit, makeCluster, parApply,
parCapply, parLapply,
 parRapply, parSapply, splitIndices, stopCluster

bash: /Library/Frameworks/R.framework/Resources/bin/Rscript: No such
file or directory

but if I use two linux machines, it works.

now, how do I use parallel's mclapply with it?



as I said.

As you seem to be under some heterogeneous setup (unstated before, as 
far as I remember), you may need to specify paths to the loaction of R 
etc. See the documentation for the parallel package.


Uwe




best,

/iaw


Ivo Welch (ivo.we...@gmail.com)
J. Fred Weston Professor of Finance
Anderson School at UCLA, C519
http://www.ivo-welch.info/
Editor, Critical Finance Review, http://www.critical-finance-review.org/



2012/4/21 Uwe Liggeslig...@statistik.tu-dortmund.de:



On 21.04.2012 06:34, ivo welch wrote:


the vignette to the library(parallel) mentions snow repeatedly (esp
differences in its implementation in parallel from the original).
unfortunately, it doesn't give an example or tutorial for
multi-machine use with sockets.

could someone please point me to a simple working example, where a
master just has both itself and a 4-core slave on a second machine
(IP), and wants to execute an mclapply on a list on both machines,
like

master.ip- localhost
slave.ip- Rfriend@192.168.2.10  ## has key ssh access
mclapply( 1:100, function(x) { cat(x); Sys.sleep(1); x } )  # on both,
please

iaw





With appropriate ssh keys that do not need passwords and with the same
username on all machines, it should work out of the box. At least, it does
for me:

Say you want two, one on your own machine, the other one on your friends:

  cl- makeCluster(c(localhost, 192.168.2.10), SOCK)

BEst,
Uwe Ligges




On Wed, Apr 18, 2012 at 1:01 PM, ivo welchivo.we...@gmail.comwrote:


Dear R experts:

could someone please point me to a page that explains how to set up
more than 1 machine for library parallel (which is quickly becoming my
favorite!)


...

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

2012-04-21 Thread Joshua Wiley
On Sat, Apr 21, 2012 at 8:20 AM, ivo welch ivo.we...@gmail.com wrote:
 hi uwe---my box is different:

 cl - makeCluster(c(localhost, welch, calc), SOCK)
 Error in loadNamespace(name) : there is no package called 'snow'

 this seems to be part of snow, not parallel.  ok, install snow first,
 then rerun.

 library(snow)
 Attaching package: 'snow'

 The following object(s) are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
 clusterExport, clusterMap, clusterSplit, makeCluster, parApply,
 parCapply, parLapply,
    parRapply, parSapply, splitIndices, stopCluster

 bash: /Library/Frameworks/R.framework/Resources/bin/Rscript: No such
 file or directory

 but if I use two linux machines, it works.

 now, how do I use parallel's mclapply with it?

parLapply(cl = cl, X = data, fun = mean)

AFAIK, mclapply() does not take a cluster argument, but the par* functions do.

Cheers,

Josh


 best,

 /iaw

 
 Ivo Welch (ivo.we...@gmail.com)
 J. Fred Weston Professor of Finance
 Anderson School at UCLA, C519
 http://www.ivo-welch.info/
 Editor, Critical Finance Review, http://www.critical-finance-review.org/



 2012/4/21 Uwe Ligges lig...@statistik.tu-dortmund.de:


 On 21.04.2012 06:34, ivo welch wrote:

 the vignette to the library(parallel) mentions snow repeatedly (esp
 differences in its implementation in parallel from the original).
 unfortunately, it doesn't give an example or tutorial for
 multi-machine use with sockets.

 could someone please point me to a simple working example, where a
 master just has both itself and a 4-core slave on a second machine
 (IP), and wants to execute an mclapply on a list on both machines,
 like

    master.ip- localhost
    slave.ip- Rfriend@192.168.2.10  ## has key ssh access
    mclapply( 1:100, function(x) { cat(x); Sys.sleep(1); x } )  # on both,
 please

 iaw




 With appropriate ssh keys that do not need passwords and with the same
 username on all machines, it should work out of the box. At least, it does
 for me:

 Say you want two, one on your own machine, the other one on your friends:

  cl - makeCluster(c(localhost, 192.168.2.10), SOCK)

 BEst,
 Uwe Ligges



 On Wed, Apr 18, 2012 at 1:01 PM, ivo welchivo.we...@gmail.com  wrote:

 Dear R experts:

 could someone please point me to a page that explains how to set up
 more than 1 machine for library parallel (which is quickly becoming my
 favorite!)

 ...

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



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

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


Re: [R] multi-machine parallel setup?

2012-04-21 Thread ivo welch
thx, guys, almost there.  This is good fodder for the vignette or ?parallel.

Steps:

(1) install package snow on all machines which you want to be part
of a cluster.
(2) run under R

library(parallel)
cl - makeCluster(c(localhost, calc.localdomain), SOCK)
result - parLapply(cl=cl, X=1:100, function(x) {
paste(x,system(hostname, intern=TRUE)) } )
stopCluster(cl)

in my case, with two linux ubuntu machines and R 2.14...this hangs (!)
because I made a small mistake, using TRUE instead of TRUE.  if I
fix it, it works fine.  is there a way to have the slave signal abort
the parLapply job when it encounters an error?  [or is it something
with my setup that prevents the abort?  does it abort correctly on
your machines?]

(I run not R 2.15 but R 2.14.1 on ubuntu 12.04LTS beta, because in
/etc/apt/sources.list, deb http://cran.cnr.Berkeley.edu precise
multiverse still installs 2.14.1.)

regards,

/iaw

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


Re: [R] multi-machine parallel setup?

2012-04-20 Thread ivo welch
the vignette to the library(parallel) mentions snow repeatedly (esp
differences in its implementation in parallel from the original).
unfortunately, it doesn't give an example or tutorial for
multi-machine use with sockets.

could someone please point me to a simple working example, where a
master just has both itself and a 4-core slave on a second machine
(IP), and wants to execute an mclapply on a list on both machines,
like

   master.ip - localhost
   slave.ip - Rfriend@192.168.2.10  ## has key ssh access
   mclapply( 1:100, function(x) { cat(x); Sys.sleep(1); x } )  # on both, please

iaw


On Wed, Apr 18, 2012 at 1:01 PM, ivo welch ivo.we...@gmail.com wrote:
 Dear R experts:

 could someone please point me to a page that explains how to set up
 more than 1 machine for library parallel (which is quickly becoming my
 favorite!)
...

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


Re: [R] multi-histogram plotting

2012-03-14 Thread R. Michael Weylandt
It's easier to do log plots as

plot(h$density, log = L)

where L is one of x, y, or xy as you choose. This is well documented.

Michael

On Wed, Mar 14, 2012 at 12:02 AM, Sam Steingold s...@gnu.org wrote:
 * David Winsemius qjvafrz...@pbzpnfg.arg [2012-03-13 17:53:14 -0400]:
 On Mar 13, 2012, at 5:33 PM, Sam Steingold wrote:
 I can, of course, plot log(h$density), but then the number labels will
 be wrong.

 You could try apply a log transform to the appropriate component of
 the h object and using barplot to display the results.

 that's what I said above: plot log(h$density).
 However, the ordinate will be labeled with log values, not the original
 values. how do I get the log ticks on the ordinate?


 --
 Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 
 11.0.11004000
 http://www.childpsy.net/ http://jihadwatch.org http://www.memritv.org
 http://dhimmi.com http://memri.org http://pmw.org.il http://truepeace.org
 Profanity is the one language all programmers know best.

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

2012-03-13 Thread David Winsemius


On Mar 13, 2012, at 5:33 PM, Sam Steingold wrote:


I have a vector x:
table(x)

   2 3 4 5 6 7 8 9101112 
1314
45547 11835  4692  2241  1386   820   593   425   298   239   176
158   115
  1516171819202122232425 
2627
  9488766747464020302220 
3314
  2829303132333435363738 
3940
  2010121011 8 9 8 9 9 8  
7 4
  4142434445464748495051 
5253
   5 4 6 5 2 5 4 4 3 1 6  
4 3
  5455565758596061636465 
6667
   2 2 1 4 5 2 5 1 3 2 1  
1 4
  7172757879828384868890 
9293
   2 3 1 2 2 2 2 1 2 2 1  
1 1
  949596979899   100   106   109   110   111
112   119
   1 2 1 1 3 1 1 3 1 2 2  
1 1
 122   125   126   128   132   133   135   140   143   147   148
157   162
   1 1 1 1 1 1 1 1 1 1 1  
1 1
 165   166   167   169   174   176   193   197   201   208   224
236   339
   1 1 1 1 1 1 1 1 1 1 1  
1 1
 350   390   391   410   421   447   450   453   479   512   608
679   754
   1 1 1 1 1 1 1 1 1 1 1  
1 1

 774   788   956   961  9597 14821
   1 1 1 1 1 1

I want to plot its histogram; moreover,
I want to plot histograms of its several subsets on the same device
(plot+lines+lines+... - right?)
This means that I need a freq=FALSE plots.
Now, a simple hist(x) produces a useless plot (vertical bar +  
horizontal

bar, which could be inferred from the table above).
So, I want
1. a logarithmic vertical scale
2. an interesting horizontal scale

so I do

h - hist(x, freq=FALSE, breaks=c(1:20,25,30,40,60,100,10),  
plot=FALSE)


now I plot h$density vs 1:length(h$mids) or against
h$mids[1:(length(h$mids)-1)] if I want to be honest,
but I still don't see how to effect a log vertical scale.
I can, of course, plot log(h$density), but then the number labels  
will be wrong.


You could try apply a log transform to the appropriate component of  
the h object and using barplot to display the results.


--
David Winsemius, MD
West Hartford, CT

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


Re: [R] multi-histogram plotting

2012-03-13 Thread Sam Steingold
 * David Winsemius qjvafrz...@pbzpnfg.arg [2012-03-13 17:53:14 -0400]:
 On Mar 13, 2012, at 5:33 PM, Sam Steingold wrote:
 I can, of course, plot log(h$density), but then the number labels will
 be wrong.

 You could try apply a log transform to the appropriate component of
 the h object and using barplot to display the results.

that's what I said above: plot log(h$density).
However, the ordinate will be labeled with log values, not the original
values. how do I get the log ticks on the ordinate?


-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://jihadwatch.org http://www.memritv.org
http://dhimmi.com http://memri.org http://pmw.org.il http://truepeace.org
Profanity is the one language all programmers know best.

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


Re: [R] multi-platform equivalent of x11() ?

2012-03-06 Thread peter dalgaard

On Mar 7, 2012, at 08:13 , Paul Johnson wrote:

 I want to write an R help example that throws up 2 graphs in separate
 windows, for comparison. In Linux I plot one, then run
 
 x11()
 
 to spawn a new on-screen device.
 
 Is there some generic equivalent so I can write an example that will
 work for Windows and Mac users as well?


dev.new(), I think.

 
 If there is none, don't you think it would be fun if there were?
 
 pj
 
 -- 
 Paul E. Johnson
 Professor, Political ScienceAssoc. Director
 1541 Lilac Lane, Room 504 Center for Research Methods
 University of Kansas   University of Kansas
 http://pj.freefaculty.orghttp://quant.ku.edu
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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

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


Re: [R] multi-regression with more than 50 independent variables

2012-02-13 Thread David L Carlson
You need to spend some time reading about multiple regression. In statistics
there is always what is possible and what is advisable. I'm not going to
address whether a regression of 57 independent variables is advisable, only
possible. For your data, it is not possible. The attached data contain only
13 observations so the maximum number of independent variables you can use
is 13. Consider the following example:

example - data.frame(y=rnorm(3), x1=rnorm(3), x2=rnorm(3), x3=rnorm(3))
lm(y~x1 + x2, example)
lm(y~x1 + x2 + x3, example)

We create four variables using random normal numbers for 3 cases (rows). The
first regression (2 independent variables works (i.e. there are no NA's).
The second produces an NA for the third independent variable. In my example,
the three random variables are not correlated with one another. In your data
there must be correlations among the 57 variables so that you are only
getting slope values for 11.

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of R DF
Sent: Monday, February 13, 2012 9:19 AM
To: r-help@r-project.org
Subject: [R] multi-regression with more than 50 independent variables

Hi R Users,

I am going to run a multiple linear regression with around 57 independent
variables. Each time I run the model with just 11 variables, the results
are reasonable. With increasing the number of independent variables more
than 11, the coefficients will get NA in the output.  Is there any
limitation for the number of independent variables in multiple linear
regressions in R? I attached my dataset as well as R codes below:



mlr.data- read.table(./multiple.txt,header=T)

mlr.output- lm(formula = CaV ~ SHG +  TrD+  CrH+ SPAD+ FlN+ FrN+   YT+
LA+ LDMP+B+Cu+  Zn+   Mn +   Fe+   K +  P+   N +Clay30 +Silt30 +Sand30
+Clay60 +Silt60 +Sand60 +ESP30 +NaEx30+ CEC30+Cl30+ SAR30 +KSol30+ NaSol30
+CaMgSol3 +ZnAv30 +FeAv30 +OC30 +PAv30 +KAv30 +TNV30+ pH30+ EC30 +SP30
+ESP60 +NaEx60 +CEC60  +Cl60 +SAR60 +KSol60 +NaSol60 +CaMgSol6
+ZnAv60+FeAv60 +OC60 +PAv60 +KAv60 +TNV60 +pH60 + EC60 +SP60, data=mlr.data)

summary (mlr.output)




Regards,

Reza

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


Re: [R] Multi-page PDF using dev.copy2pdf(filename, onefile=TRUE)?

2012-02-06 Thread ilai
Doug,
dev.copy2pdf closes the connection after it's done, so onefile is
meaningless. To look at each plot before copy to a single pdf, you
could open a pdf(...) but revert between it and your graphic device:
graphics.off()
plot(1:7, 1:7)
x11c- dev.cur()   # your current graphics device
pdf(file=test.pdf)
dev.set(which=x11c)   # back from pdf
dev.copy()  # copy
dev.set(which=x11c)# back to graphic
plot(1:5, 1:5,col=2,pch=2)
dev.copy()
dev.set(which=x11c)
# ...   etc. however many more plots
# don't forget to close the pdf device at the end:
dev.off(which=x11c+1)
# Both plots are in 'test.pdf'

Depending on your application you might be able to simplify things
with dev.next/dev.prev, or wrap this sequence into a little helper
function to be used in a loop.

Enjoy,
Elai


On Mon, Feb 6, 2012 at 6:44 AM, Doug Hill logic...@yahoo.com wrote:
 Hi all. I want to generate a sequence of n plots and save them into a single 
 PDF file, one plot per page. From the R docs and other sources I gather the 
 basic way to do this is save plot 1 into a file then append the 2:n plots to 
 the same file.
 This code shows my basic approach, but for some reason only the last plot is 
 saved into the pdf. I've tried different variations (e.g. using onefile only 
 in the second call, or only in the first), to no avail. The comments show 
 what I see if I step through the code one line at a time:
 scratch-function() {
 graphics.off()
 plot(1:7, 1:7) # Opens a graphics window and displays a 7-point plot in it, 
 as expected
 dev.copy2pdf(file=test.pdf, onefile=TRUE) # I see the 7-point plot in Adobe 
 reader, as expected
 plot(1:5, 1:5) # Overwrites in the graphics window the 7-point plot with a 
 5-point, as expected
 dev.copy2pdf(file=test.pdf, onefile=TRUE) # Overwrites test.pdf so that it 
 contains only the 7-point plot
 }
 A couple things:
 (1) The reason I don't just use something like pdf(filename) plot(...) 
 plot(...) dev.off() is that I also want to see the plots before they're saved 
 (I pause after each plot() command). But according to the docs for 
 dev.copy2pdf(), that function accepts the same args as pdf() does, including 
 onefile.
 (2) I wrap my code in a function to be able to use it in the StatEt debugger 
 in Eclipse.
 If you know what I'm doing wrong, or know of a different/better way, advise 
 away! Thanks, Doug
        [[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] Multi-page PDF using dev.copy2pdf(filename, onefile=TRUE)?

2012-02-06 Thread Doug Hill
Thanks Elai, that did it! I never considered using any X11 options, as I'm on 
Windows, and in the docs I read it sounded like X11 options only pertained to 
the OSX/Linux/.. world. Thanks for your help, Doug

--- On Mon, 2/6/12, ilai ke...@math.montana.edu wrote:

From: ilai ke...@math.montana.edu
Subject: Re: [R] Multi-page PDF using dev.copy2pdf(filename, onefile=TRUE)?
To: Doug Hill logic...@yahoo.com
Cc: r-help@r-project.org
Date: Monday, February 6, 2012, 12:24 PM

Doug,
dev.copy2pdf closes the connection after it's done, so onefile is
meaningless. To look at each plot before copy to a single pdf, you
could open a pdf(...) but revert between it and your graphic device:
graphics.off()
plot(1:7, 1:7)
x11c- dev.cur()       # your current graphics device
pdf(file=test.pdf)
dev.set(which=x11c)   # back from pdf
dev.copy()                  # copy
dev.set(which=x11c)    # back to graphic
plot(1:5, 1:5,col=2,pch=2)
dev.copy()
dev.set(which=x11c)
# ...   etc. however many more plots
# don't forget to close the pdf device at the end:
dev.off(which=x11c+1)
# Both plots are in 'test.pdf'

Depending on your application you might be able to simplify things
with dev.next/dev.prev, or wrap this sequence into a little helper
function to be used in a loop.

Enjoy,
Elai


On Mon, Feb 6, 2012 at 6:44 AM, Doug Hill logic...@yahoo.com wrote:
 Hi all. I want to generate a sequence of n plots and save them into a single 
 PDF file, one plot per page. From the R docs and other sources I gather the 
 basic way to do this is save plot 1 into a file then append the 2:n plots to 
 the same file.
 This code shows my basic approach, but for some reason only the last plot is 
 saved into the pdf. I've tried different variations (e.g. using onefile only 
 in the second call, or only in the first), to no avail. The comments show 
 what I see if I step through the code one line at a time:
 scratch-function() {
 graphics.off()
 plot(1:7, 1:7) # Opens a graphics window and displays a 7-point plot in it, 
 as expected
 dev.copy2pdf(file=test.pdf, onefile=TRUE) # I see the 7-point plot in Adobe 
 reader, as expected
 plot(1:5, 1:5) # Overwrites in the graphics window the 7-point plot with a 
 5-point, as expected
 dev.copy2pdf(file=test.pdf, onefile=TRUE) # Overwrites test.pdf so that it 
 contains only the 7-point plot
 }
 A couple things:
 (1) The reason I don't just use something like pdf(filename) plot(...) 
 plot(...) dev.off() is that I also want to see the plots before they're saved 
 (I pause after each plot() command). But according to the docs for 
 dev.copy2pdf(), that function accepts the same args as pdf() does, including 
 onefile.
 (2) I wrap my code in a function to be able to use it in the StatEt debugger 
 in Eclipse.
 If you know what I'm doing wrong, or know of a different/better way, advise 
 away! Thanks, Doug
        [[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] Multi-page PDF using dev.copy2pdf(filename, onefile=TRUE)?

2012-02-06 Thread David Winsemius


On Feb 6, 2012, at 2:51 PM, Doug Hill wrote:

Thanks Elai, that did it! I never considered using any X11 options,  
as I'm on Windows, and in the docs I read it sounded like X11  
options only pertained to the OSX/Linux/.. world. Thanks for your  
help, Doug


You are confused about the difference of a named variable and its  
contents. There is no X11 device in that solution,  just a name for  
the current device which in your case is probably not an X11 device.  
If you looked at the value of `x11c`, you would see it's just a number.


Elai is just switching back and forth between the screen device and  
the file device.


--
David.



--- On Mon, 2/6/12, ilai ke...@math.montana.edu wrote:

From: ilai ke...@math.montana.edu
Subject: Re: [R] Multi-page PDF using dev.copy2pdf(filename,  
onefile=TRUE)?

To: Doug Hill logic...@yahoo.com
Cc: r-help@r-project.org
Date: Monday, February 6, 2012, 12:24 PM

Doug,
dev.copy2pdf closes the connection after it's done, so onefile is
meaningless. To look at each plot before copy to a single pdf, you
could open a pdf(...) but revert between it and your graphic device:
graphics.off()
plot(1:7, 1:7)
x11c- dev.cur()   # your current graphics device
pdf(file=test.pdf)
dev.set(which=x11c)   # back from pdf
dev.copy()  # copy
dev.set(which=x11c)# back to graphic
plot(1:5, 1:5,col=2,pch=2)
dev.copy()
dev.set(which=x11c)
# ...   etc. however many more plots
# don't forget to close the pdf device at the end:
dev.off(which=x11c+1)
# Both plots are in 'test.pdf'

Depending on your application you might be able to simplify things
with dev.next/dev.prev, or wrap this sequence into a little helper
function to be used in a loop.

Enjoy,
Elai


On Mon, Feb 6, 2012 at 6:44 AM, Doug Hill logic...@yahoo.com wrote:
Hi all. I want to generate a sequence of n plots and save them into  
a single PDF file, one plot per page. From the R docs and other  
sources I gather the basic way to do this is save plot 1 into a  
file then append the 2:n plots to the same file.
This code shows my basic approach, but for some reason only the  
last plot is saved into the pdf. I've tried different variations  
(e.g. using onefile only in the second call, or only in the first),  
to no avail. The comments show what I see if I step through the  
code one line at a time:

scratch-function() {
graphics.off()
plot(1:7, 1:7) # Opens a graphics window and displays a 7-point  
plot in it, as expected
dev.copy2pdf(file=test.pdf, onefile=TRUE) # I see the 7-point  
plot in Adobe reader, as expected
plot(1:5, 1:5) # Overwrites in the graphics window the 7-point plot  
with a 5-point, as expected
dev.copy2pdf(file=test.pdf, onefile=TRUE) # Overwrites test.pdf  
so that it contains only the 7-point plot

}
A couple things:
(1) The reason I don't just use something like pdf(filename)  
plot(...) plot(...) dev.off() is that I also want to see the plots  
before they're saved (I pause after each plot() command). But  
according to the docs for dev.copy2pdf(), that function accepts the  
same args as pdf() does, including onefile.
(2) I wrap my code in a function to be able to use it in the StatEt  
debugger in Eclipse.
If you know what I'm doing wrong, or know of a different/better  
way, advise away! Thanks, Doug

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] multi-line query

2011-11-08 Thread jim holtman
Why not just send it in as is.  I use SQLite (via sqldf) and here is
the way I write my SQL statements:

inRange - sqldf('
select t.*
, r.start
, r.end
from total t, commRange r
where t.comm = r.comm and
t.loc between r.start and r.end and
t.loc != t.new
')

On Tue, Nov 8, 2011 at 11:43 AM, Ben quant ccqu...@gmail.com wrote:
 Hello,

 I'm using package RpgSQL. Is there a better way to create a multi-line
 query/character string? I'm looking for less to type and readability.

 This is not very readable for large queries:
 s -  'create table r.BOD(id int primary key,name varchar(12))'

 I write a lot of code, so I'm looking to type less than this, but it is
 more readable from and SQL standpoint:
 s - gsub(\n, , 'create table r.BOD(
 id int primary key
 ,name varchar(12))
 ')

 How it is used:
 dbSendUpdate(con, s)

 Regards,

 Ben

        [[alternative HTML version deleted]]

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




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


Re: [R] multi-line query

2011-11-08 Thread Ben quant
Because I don't know anything about sqldf. :)

Here is what happens, but Im sure it is happening because I didn't read
the manual yet:

 s - sqldf('create table r.dat(id int primary key,val int)')
Error in ls(envir = envir, all.names = private) :
  invalid 'envir' argument
Error in !dbPreExists : invalid argument type

ben

On Tue, Nov 8, 2011 at 10:41 AM, jim holtman jholt...@gmail.com wrote:

 Why not just send it in as is.  I use SQLite (via sqldf) and here is
 the way I write my SQL statements:

inRange - sqldf('
select t.*
, r.start
, r.end
from total t, commRange r
where t.comm = r.comm and
t.loc between r.start and r.end and
t.loc != t.new
')

 On Tue, Nov 8, 2011 at 11:43 AM, Ben quant ccqu...@gmail.com wrote:
  Hello,
 
  I'm using package RpgSQL. Is there a better way to create a multi-line
  query/character string? I'm looking for less to type and readability.
 
  This is not very readable for large queries:
  s -  'create table r.BOD(id int primary key,name varchar(12))'
 
  I write a lot of code, so I'm looking to type less than this, but it is
  more readable from and SQL standpoint:
  s - gsub(\n, , 'create table r.BOD(
  id int primary key
  ,name varchar(12))
  ')
 
  How it is used:
  dbSendUpdate(con, s)
 
  Regards,
 
  Ben
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 



 --
 Jim Holtman
 Data Munger Guru

 What is the problem that you are trying to solve?
 Tell me what you want to do, not how you want to do it.


[[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] multi-line query

2011-11-08 Thread Gabor Grothendieck
On Tue, Nov 8, 2011 at 11:43 AM, Ben quant ccqu...@gmail.com wrote:
 Hello,

 I'm using package RpgSQL. Is there a better way to create a multi-line
 query/character string? I'm looking for less to type and readability.

 This is not very readable for large queries:
 s -  'create table r.BOD(id int primary key,name varchar(12))'

 I write a lot of code, so I'm looking to type less than this, but it is
 more readable from and SQL standpoint:
 s - gsub(\n, , 'create table r.BOD(
 id int primary key
 ,name varchar(12))
 ')

 How it is used:
 dbSendUpdate(con, s)


The gsub is not needed:

s - create table x (
   a real,
   b integer
)
dbSendUpdate(con, s)


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

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


Re: [R] multi-line query

2011-11-08 Thread Gabor Grothendieck
On Tue, Nov 8, 2011 at 1:04 PM, Ben quant ccqu...@gmail.com wrote:
 Because I don't know anything about sqldf. :)

 Here is what happens, but Im sure it is happening because I didn't read
 the manual yet:

 s - sqldf('create table r.dat(id int primary key,val int)')
 Error in ls(envir = envir, all.names = private) :
  invalid 'envir' argument
 Error in !dbPreExists : invalid argument type


Assuming you have loaded RpgSQL and sqldf it works for me so there is
likely some configuration in your setup, either with RpgSQL or with
PostgreSQL itself.

 s - sqldf('create table dat(id int primary key, val int)')
 sqldf(select * from dat)
[1] id  val
0 rows (or 0-length row.names)

If you are going to use your own create statements then you might be
better off using RpgSQL directly rather than sqldf.

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

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


Re: [R] Multi t tests

2011-10-14 Thread R. Michael Weylandt
It's usually standard to provide an example of what code you've tried
and also to put your data in a form that can be more easily
cut-and-pasted into R.

That said, would something like this work if you know you only have
two sorts of cross in each level?

lapply(spl, function(x) {x - split(x[,1],x[,2]); t.test(x[[1]], x[[2]])})

Michael

On Fri, Oct 14, 2011 at 10:38 AM, Imri bisr...@agri.huji.ac.il wrote:
 hi all

 I have R object look like this:
 spl
 $SB012XSB044
    DPW       Cross
 1  66.6 SB012XSB044
 2  96.5 SB012XSB044
 3  78.8 SB012XSB044
 4  68.6 SB012XSB044
 5  62.0 SB012XSB044
 6  72.1 SB044XSB012
 7  72.2 SB044XSB012
 8  69.6 SB044XSB012
 9  87.9 SB044XSB012
 10 84.4 SB044XSB012
 11 51.9 SB044XSB012
 12 65.5 SB044XSB012

 $SB012XSB099
     DPW       Cross
 13 100.9 SB012XSB099
 14  44.4 SB012XSB099
 15  83.5 SB012XSB099
 16  89.9 SB012XSB099
 17  78.0 SB012XSB099
 18  83.0 SB012XSB099
 19 114.3 SB099XSB012
 20 173.1 SB099XSB012
 21 114.3 SB099XSB012
 22  58.8 SB099XSB012
 23  98.1 SB099XSB012
 24  12.8 SB099XSB012

 I want to do a t test for DPW values by the 2 different Cross types for each
 of spl components.
 Any suggestions? I just got errors till now

 Thanks,
 Imri.

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Multi-t-tests-tp3905075p3905075.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] Multi-output regression

2011-09-11 Thread Daniel Malter
I am not a Bayesian. In the non-Bayesian case you would use SUR to model both
equations simultaneously. If both use the exact same matrix of data, X
(i.e., the value are numerically absolutely identical), then SUR will
collapse to OLS. In that sense you get a combined estimate using SUR that
respects the correlation of the error terms between equations. However, it
will be efficient to estimate each equation individually if the Xs are
exactly the same.

Daniel


zeec wrote:
 
 Hi,
 
 I have a question regarding the modeling methodology of the following
 problem:
 
 * I have two data sets {X_i,y_i} {X_i,z_i}, i=1..N,
   where y_i = f(X_i) + i.i.d. Gaussian noise 
   and   z_i = g(X_i) + i.i.d. Gaussian noise
 * I apply bayesian linear regression to each of them and obtain
   p(y|X) and p(z|X)
   
 I would like to improve the prediction of the two models using the
 knowledge that
 f and g are related (for example f(X_i) = g(X_i) - 1). I can obtain a
 model p(y,z).
 
 I know that there are methods for multi-output regression, but I hope both
 can be modeled independently and then combined. 
 
 Thank you for your help!
 Steffan
 --
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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://r.789695.n4.nabble.com/Multi-output-regression-tp3804766p3804855.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] Multi-dimensional non-linear fitting - advice on best method?

2011-04-26 Thread Julian Gilbey
On Mon, Apr 25, 2011 at 12:57:46AM +0200, peter dalgaard wrote:
  I have a set of data of the form (x, y1, y2) where x is the
  independent variable and (y1, y2) is the response pair.  The model is
  some messy non-linear function:
  
   (y1, y2) = f(x; param1, param2, ..., paramk) + (y1error, y2error)
  
  where the parameters param1, ..., paramk are to be estimated, and I'll
  assume the errors to be normal for sake of simplicity.
  
  If there were only one response per input, I would use the nls()
  function, but what can I do in this case?
 
 I believe the gnls function in the nlme package is your friend. It's a bit 
 involved but the basic idea is to stack the two response variables and use a 
 weights argument with a varIdent structure with variance depending on whether 
 it is a y1 or a y2 observation. You can also specify a within-pair 
 correlation.

Will take a look, thanks!

   Julian

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


Re: [R] Multi-dimensional non-linear fitting - advice on best method?

2011-04-26 Thread Julian Gilbey
On Sun, Apr 24, 2011 at 07:02:48PM -0400, Ravi Varadhan wrote:
 Julian,
 
 You have not specified your problem fully.  What is the nature of f?  Is f a 
 scalar function or is it a vector function (2-dim)?

It's something like this (only a bit worse):

given x, work out alpha from
  cos(alpha) = sin(delta) * sin(x) * sin(theta) - cos(delta) * cos(theta)

then y1 = h * cos(alpha) + offset1 + err1
 y2 = h * sin(alpha) + offset2 + err2

where theta is known, and delta, offset1, offset2 and h are to be
estimated and err1, err2 are measurement errors.

x is known, (y1, y2) are observed.

   Julian

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


Re: [R] Multi-dimensional non-linear fitting - advice on best method?

2011-04-24 Thread David Winsemius


On Apr 23, 2011, at 8:38 PM, Julian Gilbey wrote:


Hello!

I have a set of data of the form (x, y1, y2) where x is the
independent variable and (y1, y2) is the response pair.  The model is
some messy non-linear function:

 (y1, y2) = f(x; param1, param2, ..., paramk) + (y1error, y2error)

where the parameters param1, ..., paramk are to be estimated, and I'll
assume the errors to be normal for sake of simplicity.

If there were only one response per input, I would use the nls()
function, but what can I do in this case?


I wonder it would be sensible or at least informative to consider  
solving for the inverse case. i.e. solve for:


x = f(y1, y2)

--
David Winsemius, MD
West Hartford, CT

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


Re: [R] Multi-dimensional non-linear fitting - advice on best method?

2011-04-24 Thread peter dalgaard

On Apr 24, 2011, at 02:38 , Julian Gilbey wrote:

 Hello!
 
 I have a set of data of the form (x, y1, y2) where x is the
 independent variable and (y1, y2) is the response pair.  The model is
 some messy non-linear function:
 
  (y1, y2) = f(x; param1, param2, ..., paramk) + (y1error, y2error)
 
 where the parameters param1, ..., paramk are to be estimated, and I'll
 assume the errors to be normal for sake of simplicity.
 
 If there were only one response per input, I would use the nls()
 function, but what can I do in this case?


I believe the gnls function in the nlme package is your friend. It's a bit 
involved but the basic idea is to stack the two response variables and use a 
weights argument with a varIdent structure with variance depending on whether 
it is a y1 or a y2 observation. You can also specify a within-pair correlation.

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

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

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


Re: [R] Multi-dimensional non-linear fitting - advice on best method?

2011-04-24 Thread Ravi Varadhan
Julian,

You have not specified your problem fully.  What is the nature of f?  Is f a 
scalar function or is it a vector function (2-dim)?

Here are some examples showing different possibilities:

(1) y1 = f + e1 = a + b*exp(-c*x) + e1; y2 = f + e2 = a + b*exp(-c*x) + e2; 
(e1, e2) ~ bivariate normal

(2) y1 = f + e1 = a + b*exp(-c*x) + e1; y2 = f + e2 = a + b*exp(-c*x) + e2; 
(e1, e2) ~ independently normal

(3) y1 = f1 + e1 = a1 + b1*exp(-c1*x) + e1; y2 = f2 + e2 = a2 + b2*exp(-c2*x) + 
e2; (e1, e2) ~ bivariate normal

(4) y1 = f1 + e1 = a1 + b1*exp(-c1*x) + e1; y2 = f2 + e2 = a2 + b2*exp(-c2*x) + 
e2; (e1, e2) ~ independently normal

For scenario (2), you form a single `y' vector by concatenating all the y1 and 
y2 and then do a single application of nls.  For (4), you do 2 separate nls 
runs, one for y1 and another for y2.  

For (1) and (3) you can do a likelihood maximization.

You have more scenarios where f1 and f2 can have different functional forms.  
Which scenario is the one that you are considering?

Ravi.

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
David Winsemius [dwinsem...@comcast.net]
Sent: Sunday, April 24, 2011 6:25 PM
To: Julian Gilbey
Cc: r-help@r-project.org
Subject: Re: [R] Multi-dimensional non-linear fitting - advice on best  method?

On Apr 23, 2011, at 8:38 PM, Julian Gilbey wrote:

 Hello!

 I have a set of data of the form (x, y1, y2) where x is the
 independent variable and (y1, y2) is the response pair.  The model is
 some messy non-linear function:

  (y1, y2) = f(x; param1, param2, ..., paramk) + (y1error, y2error)

 where the parameters param1, ..., paramk are to be estimated, and I'll
 assume the errors to be normal for sake of simplicity.

 If there were only one response per input, I would use the nls()
 function, but what can I do in this case?

I wonder it would be sensible or at least informative to consider
solving for the inverse case. i.e. solve for:

x = f(y1, y2)

--
David Winsemius, MD
West Hartford, CT

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

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


Re: [R] Multi-dimensional non-linear fitting - advice on best method?

2011-04-24 Thread ancienthart
If y1 and y2 are only dependent on x, can't you model them separately?

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


Re: [R] multi process support in R

2011-03-28 Thread Alaios
Dear all,
I would like to ask your help of how I can convert the loop below to a mclapply 
(this is the apply to many cores)

 for (i in seq(from=-1,to=1-2/ncol(sr),length=ncol(sr))){
  for (j in seq(from=-1,to=1-2/nrow(sr),length=nrow(sr))){
estimatedsr[findC(c(i,j),sr)[1],findC(c(i,j),sr)[2]  ]-fxy(c(i,j))
  }
}
lst[[i,j]] -estimatedsr

What the loop above does is that calculates a value and then saves it inside 
the lst matrix.

I am not sure how I should convert this process to  run with many cores. What 
confuses me that my in this code one should track the i,j values so each cores 
saves at the right place inside the lst matrix.

Could you please help me with that?
Regards
Alex


--- On Thu, 2/17/11, Ben Haller rh...@sticksoftware.com wrote:

 From: Ben Haller rh...@sticksoftware.com
 Subject: Re: [R] multi process support in R
 To: Alaios ala...@yahoo.com
 Cc: R-help@r-project.org
 Date: Thursday, February 17, 2011, 10:47 AM
 On Feb 17, 2011, at 11:40 AM, Alaios
 wrote:
 
  ...Is it possible to split work in many cores in R and
 if yes how is this library called?
 
   I'd recommend the mclapply function in the
 multicore package.  The only drawback is that you
 can't run your code in a GUI any more.
 
 Ben Haller
 McGill University
 
 


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


Re: [R] Multi-line input to rsympy

2011-03-05 Thread Gabor Grothendieck
On Fri, Mar 4, 2011 at 6:48 AM, Joanna Lewis joanna.le...@ucl.ac.uk wrote:
 Dear R users,

 I have been using rsympy to solve a set of simultaneous equations from R.
 There are two solutions for the variable I'm interested in, xx[0] and xx[1],
 which are in terms of symbols called lam and conc. I'd like to pick out the
 one which is positive at (lam=0, conc=0) and call it mysol.

 In python I could write:

 if (xx[0].subs(lam,0)).subs(conc,0)0:
  mysol=xx[0]
 else:
  mysol=xx[1]

 but I'm not sure how to do it from R via rsympy. The various combinations of
 \t and \n characters and spaces I've tried haven't worked, and I haven't
 been able to find any examples online or in the help file.

 Do you know whether it is possible to enter multi-line input using rsympy,
 and if so how?


You can run multi-line python commands in Jython:

 .Jython$exec(x = 1)
 .Jython$exec(if x == 1:
+z = 2
+ else:
+z = 3)
 z - .Jython$get(z)
 .jstrVal(z)
[1] 2


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

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


Re: [R] multi process support in R

2011-02-17 Thread Ben Haller
On Feb 17, 2011, at 11:40 AM, Alaios wrote:

 ...Is it possible to split work in many cores in R and if yes how is this 
 library called?

  I'd recommend the mclapply function in the multicore package.  The only 
drawback is that you can't run your code in a GUI any more.

Ben Haller
McGill University

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


Re: [R] multi process support in R

2011-02-17 Thread Prof Brian Ripley
He said 'pc' in the part you excised, but failed to follow the posting 
guide and tell us his OS.  I am guessing this means Windows, on which 
multicore does not run.


There are several other solutions on CRAN: I'd suggest 'snow' which 
can run over sockets on a single Windows machine, and also (with a lot 
more difficulty) via Rmpi.


On Thu, 17 Feb 2011, Ben Haller wrote:


On Feb 17, 2011, at 11:40 AM, Alaios wrote:

...Is it possible to split work in many cores in R and if yes how 
is this library called?


 I'd recommend the mclapply function in the multicore package.  The only 
drawback is that you can't run your code in a GUI any more.

Ben Haller
McGill University

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



--
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] Multi-page plots (Trellis)

2011-02-10 Thread David Winsemius


On Feb 10, 2011, at 2:39 PM, sherri heck wrote:


Dear All -

I would like to make  multi-page plots, but my plots are writing  
over one

another - thus leaving just the last plot.  Here is what I am doing:

pollutionRose(temp, nox, type=hour)
update(trellis.last.object(), layout =c(3,3,3) )


update() only changes the list representation. If you want to send  
that to the active graphics device, you need to print it. See the  
relevant FAQ.




I would like 24 plots with 9 plots/page (the last page would not  
have 9

plots)

Is there any way to force layout to make 3 pages of plots but not  
re-write
them ?  I do not understand why layout is not recognizing the page  
number
request.  I have read several help pages/archives and cannot find  
what I

need.  Any help is greatly appreciated.

Thanks in advance!

Sherri Heck
Graduate Research Assistant
National Center for Atmospheric Research, Boulder CO
University of Colorado, Boulder CO

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] multi-Operations on a matrix

2011-02-01 Thread Dennis Murphy
Hi:

Try this:

 d - read.table(textConnection(
+  procedure property sensor_data  sensor_date
+ 1S_10 nord626821.0 2002-09-30T00:00:00+0200
+ 2 S_10 nord626821.0 2002-12-05T00:00:00+0100
+ 3S_10 nord626821.1 2008-07-31T00:00:00+0200
+ 4  S_1000 nord626496.8 2002-09-30T00:00:00+0200
+ 5  S_1000 nord626496.8 2002-12-05T00:00:00+0100
+ 6  S_1000 nord626496.9 2009-04-23T00:00:00+0200
+ 7  S_1000 nord626497.0 2009-11-10T00:00:00+0100
+ 8 S_1 nord626485.3 2002-09-30T00:00:00+0200
+ 9S_1 nord626485.3 2002-12-05T00:00:00+0100
+ 10S_1 nord626485.3 2003-02-07T00:00:00+0100), header = TRUE)
# Create a new date variable - the HMS+ seem to be overkill here :)
d$sensor_date - as.character(d$sensor_date)
d$stime - as.Date(substring(d$sensor_date, 1, 10))

# Create a function to determine the minimum time and produce the
differences
# in sensor_data - works for a generic input data frame
 f - function(df) {
+  mint - which.min(df$stime)
+  df$difference - with(df, sensor_data - sensor_data[mint])
#  df$stime - NULL# optional: knocks out the created date
variable
+  df
+ }

# Use the ddply() function in package plyr to map f to each subset data
frame
# defined by procedure:
 library(plyr)
 ddply(d, .(procedure), f)
   procedure property sensor_data  sensor_date  stime
difference
1S_1 nord626485.3 2002-09-30T00:00:00+0200 2002-09-30  0.0
2S_1 nord626485.3 2002-12-05T00:00:00+0100 2002-12-05  0.0
3S_1 nord626485.3 2003-02-07T00:00:00+0100 2003-02-07  0.0
4   S_10 nord626821.0 2002-09-30T00:00:00+0200 2002-09-30  0.0
5   S_10 nord626821.0 2002-12-05T00:00:00+0100 2002-12-05  0.0
6   S_10 nord626821.1 2008-07-31T00:00:00+0200 2008-07-31  0.1
7 S_1000 nord626496.8 2002-09-30T00:00:00+0200 2002-09-30  0.0
8 S_1000 nord626496.8 2002-12-05T00:00:00+0100 2002-12-05  0.0
9 S_1000 nord626496.9 2009-04-23T00:00:00+0200 2009-04-23  0.1
10S_1000 nord626497.0 2009-11-10T00:00:00+0100 2009-11-10  0.2

HTH,
Dennis

On Tue, Feb 1, 2011 at 1:52 AM, alcesgabbo alcesga...@hotmail.com wrote:


 Hello everybody.

 I have this object

  procedure property sensor_data  sensor_date
 1S_10 nord626821.0 2002-09-30T00:00:00+0200
 2 S_10 nord626821.0 2002-12-05T00:00:00+0100
 3S_10 nord626821.1 2008-07-31T00:00:00+0200
 4  S_1000 nord626496.8 2002-09-30T00:00:00+0200
 5  S_1000 nord626496.8 2002-12-05T00:00:00+0100
 6  S_1000 nord626496.9 2009-04-23T00:00:00+0200
 7  S_1000 nord626497.0 2009-11-10T00:00:00+0100
 8 S_1 nord626485.3 2002-09-30T00:00:00+0200
 9S_1 nord626485.3 2002-12-05T00:00:00+0100
 10S_1 nord626485.3 2003-02-07T00:00:00+0100

 the third colomn (sensor_data) is a distance in meters.
 each distance has a date (sensor_date)
 for each row I would like to find the difference from the first distance
 (with the min date) and the distance.

 I know it's difficult to understand.. I give you an example:

 for the first procedure S_10 I should find the first distance based on the
 date:

 distance:626821.0   with the date: 2002-09-30T00:00:00+0200

 then I should do the difference between the current distance and the first
 distance:

 626821.0 - 626821.0 = 0.0
  626821.0 -  626821.0 = 0.0
 626821.1 - 626821.0 = 0.1

 Then I should do this also for the other procedures.

 I would like a resut like this:

 procedure property sensor_data  sensor_date difference
 1S_10 nord626821.0 2002-09-30T00:00:00+02000.0
 2 S_10 nord626821.0 2002-12-05T00:00:00+0100   0.0
 3S_10 nord626821.1 2008-07-31T00:00:00+0200   0.1
 4  S_1000 nord626496.8 2002-09-30T00:00:00+0200  0.0
 5  S_1000 nord626496.8 2002-12-05T00:00:00+0100   0.0
 6  S_1000 nord626496.9 2009-04-23T00:00:00+02000.1
 7  S_1000 nord626497.0 2009-11-10T00:00:00+0100   0.2
 8 S_1 nord626485.3 2002-09-30T00:00:00+0200 0.0
 9S_1 nord626485.3 2002-12-05T00:00:00+0100  0.0
 10S_1 nord626485.3 2003-02-07T00:00:00+0100 0.0

 How can I do this procedure?


 Thanks

 --
 View this message in context:
 http://r.789695.n4.nabble.com/multi-Operations-on-a-matrix-tp3250807p3250807.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list

Re: [R] multi-level cox ph with time-dependent covariates

2010-11-04 Thread Terry Therneau
Your question has two levels:
   1. What is the right model for this data
   2. Can model __ be fit

Wrt 2 and coxme: For a reliable fit you need to have more events than
random effects.  Thus for patient/tissue I would want to see multiple
events per patient/tissue pair.  This is statistical issue -- when there
are too few events the confidence intervals for the random effects end
up being a mile wide.  (Exception, if the number of events is very
large, 10^5 say as sometimes occurs in economics studies, the estimates
can work.)  
   coxme works fine with start,stop data.

Wrt question 1.  Your models assume that marker1, marker2, ... each have
the same effect across tissue types.  Adding a random effect gave per
subject or per subject/tissue intercepts.  Do you instead want to do
shrinkage of the marker1, .. coefficients?

Terry Therneau

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


Re: [R] Multi-line graph?

2010-10-15 Thread Dieter Menne


barnhillec wrote:
 
 I'm trying to graph some simple music psychology data. Columns are musical
 intervals, rows are the initials of the subjects. Numbers are in beats per
 minute (this is the value at which they hear the melodic interval split
 into two streams). So here's my table:
 
  Tenth Fifth Third
 GG 112152   168
 EC  100120   140
 SQ  160   184NA
 SK   120   100   180
 
 I want a multi-line graph where the intervals are on the X axis, and the y
 axis is the beats per minute, and each subject has a different line. 
 
 
The most difficult part of it (at least that's what my students think) is
getting the data into the right format. If you have the changes to start
with the data in the long format, use it. What you need is:

init interval beats
GC   Tenth112

In this case, reformatting almost works with the default version of the melt
function in package reshape.

It's good that you supplied a data example, but in general it is better if
you could provide it in a copy-and-paste format as shown below. I needed
more time to reformat the data than to write the rest.


Dieter


library(lattice)
library(reshape)
dt = data.frame(
   init  = c(GG,EC, SQ,SK),
   Tenth = c(112,100,160,120),
   Fifth = c(152,120,184,100),
   Third = c(168,140,NA,180))

# The data should look like this
#init interval beats
#GC   Tenth112
#dtlong = melt(dt) # almost does it, but column variable is ugly
dtlong = melt(dt,variable_name=beats) # better
dtlong
   
xyplot(value~variable,groups=init,data=dtlong,type=l, 
auto.key=list(lines=TRUE))





-- 
View this message in context: 
http://r.789695.n4.nabble.com/Multi-line-graph-tp2997402p2997435.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] Multi-line graph?

2010-10-15 Thread William Revelle

?matplot

e.g.,

copy your data to the clipboard then

library(psych)
my.data - read.clipboard()

 my.data

   Tenth Fifth Third
GG   112   152   168
EC   100   120   140
SQ   160   184NA
SK   120   100   180

matplot(t(my.data),type=b)

Bill



At 10:27 AM -0700 10/15/10, barnhillec wrote:

Hi,

I am relatively new to R but not to graphing, which I used to do in Excel
and a few other environments on the job. I'm going back to school for a PhD
and am teaching myself R beforehand. So I hope this question is not
unacceptably ignorant but I have perused every entry level document I can
find and so far I'm out of luck.

I'm trying to graph some simple music psychology data. Columns are musical
intervals, rows are the initials of the subjects. Numbers are in beats per
minute (this is the value at which they hear the melodic interval split into
two streams). So here's my table:

 Tenth Fifth Third
GG 112152   168
EC  100120   140
SQ  160   184NA
SK   120   100   180

I want a multi-line graph where the intervals are on the X axis, and the y
axis is the beats per minute, and each subject has a different line. In
Excel this would be no problem but I am having trouble in R.

The only way I can figure out how to plot this in R is if the columns or
rows are taken as variables. But the variable is beats per minute. Any
suggestions?

I appreciate the help. -Eric
--
View this message in context: 
http://r.789695.n4.nabble.com/Multi-line-graph-tp2997402p2997402.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] multi day R run crashed - is there a log

2010-08-25 Thread Sarah Goslee
Oh dear. No there isn't. I do a lot of very long runs, and have learned to write
out intermediate steps. Depending on what you are doing, saving the RData
file periodically may be appropriate, or writing out a csv file of
results so far,
or even just printing something to the output file (if you are using batch).

There may well be something more elegant, but these solutions have all worked
well for me in various situations.

Sarah

On Wed, Aug 25, 2010 at 3:46 AM, Martin Tomko martin.to...@geo.uzh.ch wrote:
 Dear all,
 I am using an R 2.10 installation on a Windows 203 server that I have no
 control over. After a multi-day run I found that it was terminated/crashed.
 Is there any log kept by R where I could see whether something/what
 happened? The same process has been run beofre on a smaller dataset (also at
 least a day of computing) without problems.

 Thanks
 Martin

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

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


Re: [R] multi day R run crashed - is there a log

2010-08-25 Thread Martin Tomko

Hi Sarah,
thank you very much for your answer. I have been spitting things out on 
screen, but unfortunately I have not run it as a batch log, but in the 
interactive window, so when the GUI crashed I was left without trace... 
I guess I should google how to run it from a batch.


I should also explore using RData, I have ony been using csv files and 
tables so far, it seems that can also bring some added performance.


As the main output of my process is a matrix, I would really need to 
append to a matrix after each iteration. I have identified the 
write.table append parameter-based solution, but that would only append 
rows. Is there a way to slowly grow a matrix in both directions, 
meaning append columns as well (it is a big distance matrix).

Thanks a lot for your help,
Cheers
Martin

On 8/25/2010 1:56 PM, Sarah Goslee wrote:

Oh dear. No there isn't. I do a lot of very long runs, and have learned to write
out intermediate steps. Depending on what you are doing, saving the RData
file periodically may be appropriate, or writing out a csv file of
results so far,
or even just printing something to the output file (if you are using batch).

There may well be something more elegant, but these solutions have all worked
well for me in various situations.

Sarah

On Wed, Aug 25, 2010 at 3:46 AM, Martin Tomkomartin.to...@geo.uzh.ch  wrote:
   

Dear all,
I am using an R 2.10 installation on a Windows 203 server that I have no
control over. After a multi-day run I found that it was terminated/crashed.
Is there any log kept by R where I could see whether something/what
happened? The same process has been run beofre on a smaller dataset (also at
least a day of computing) without problems.

Thanks
Martin
 
   



--
Martin Tomko
Postdoctoral Research Assistant

Geographic Information Systems Division
Department of Geography
University of Zurich - Irchel
Winterthurerstr. 190
CH-8057 Zurich, Switzerland

email:  martin.to...@geo.uzh.ch
site:   http://www.geo.uzh.ch/~mtomko
mob:+41-788 629 558
tel:+41-44-6355256
fax:+41-44-6356848

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


Re: [R] multi day R run crashed - is there a log

2010-08-25 Thread Sarah Goslee
Hi,

On Wed, Aug 25, 2010 at 8:11 AM, Martin Tomko martin.to...@geo.uzh.ch wrote:
 Hi Sarah,
 thank you very much for your answer. I have been spitting things out on
 screen, but unfortunately I have not run it as a batch log, but in the
 interactive window, so when the GUI crashed I was left without trace... I
 guess I should google how to run it from a batch.

I have  no idea how to do that in Windows, but I'm sure it's possible. :)
That way the things written to the screen will be saved in a file instead.

 I should also explore using RData, I have ony been using csv files and
 tables so far, it seems that can also bring some added performance.

If you need to save *everything*, RData is what you get when you use save(),
or when you close a session and choose y to saving the data. It can be
read in using load(). That's one way to be able to pick up where you left
off.

 As the main output of my process is a matrix, I would really need to append
 to a matrix after each iteration. I have identified the write.table append
 parameter-based solution, but that would only append rows. Is there a way to
 slowly grow a matrix in both directions, meaning append columns as well
 (it is a big distance matrix).

AFAIK, you can't append columns that way because of the way text files are
written to disk. You'd need to rewrite the whole thing, or possibly write it out
in lower triangular format with NA values as padding (assuming it's a symmetric
distance).

Or for that matter, you could just write it out as a really long
vector, and turn
it back into a matrix later if you need to read the saved file in after a crash.

I'd recommend saving whatever variables are needed so that you can pick up
exactly where you left off, if possible. Much nicer to pick up 12 hours in than
to start over from the beginning.

Not R, but I just finished a 5-week batch job. You can bet that I put a lot of
thought into incremental save points and how to resume after an unexpected
halt!

Sarah

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

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


Re: [R] multi day R run crashed - is there a log

2010-08-25 Thread Martin Tomko

Hi ,
thanks, the lower.tri idea is I guess the best way. Will try that.
Cheers
Martin

On 8/25/2010 2:21 PM, Sarah Goslee wrote:

Hi,

On Wed, Aug 25, 2010 at 8:11 AM, Martin Tomkomartin.to...@geo.uzh.ch  wrote:
   

Hi Sarah,
thank you very much for your answer. I have been spitting things out on
screen, but unfortunately I have not run it as a batch log, but in the
interactive window, so when the GUI crashed I was left without trace... I
guess I should google how to run it from a batch.
 

I have  no idea how to do that in Windows, but I'm sure it's possible. :)
That way the things written to the screen will be saved in a file instead.

   

I should also explore using RData, I have ony been using csv files and
tables so far, it seems that can also bring some added performance.
 

If you need to save *everything*, RData is what you get when you use save(),
or when you close a session and choose y to saving the data. It can be
read in using load(). That's one way to be able to pick up where you left
off.

   

As the main output of my process is a matrix, I would really need to append
to a matrix after each iteration. I have identified the write.table append
parameter-based solution, but that would only append rows. Is there a way to
slowly grow a matrix in both directions, meaning append columns as well
(it is a big distance matrix).
 

AFAIK, you can't append columns that way because of the way text files are
written to disk. You'd need to rewrite the whole thing, or possibly write it out
in lower triangular format with NA values as padding (assuming it's a symmetric
distance).

Or for that matter, you could just write it out as a really long
vector, and turn
it back into a matrix later if you need to read the saved file in after a crash.

I'd recommend saving whatever variables are needed so that you can pick up
exactly where you left off, if possible. Much nicer to pick up 12 hours in than
to start over from the beginning.

Not R, but I just finished a 5-week batch job. You can bet that I put a lot of
thought into incremental save points and how to resume after an unexpected
halt!

Sarah

   



--
Martin Tomko
Postdoctoral Research Assistant

Geographic Information Systems Division
Department of Geography
University of Zurich - Irchel
Winterthurerstr. 190
CH-8057 Zurich, Switzerland

email:  martin.to...@geo.uzh.ch
site:   http://www.geo.uzh.ch/~mtomko
mob:+41-788 629 558
tel:+41-44-6355256
fax:+41-44-6356848

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


Re: [R] Multi-panel Pie Charts.

2010-03-25 Thread Hrishi Mittal

Hi Jim, what's the tab.title function you are using?

-
Try  http://prettygraph.com Pretty Graph , the easiest way to make R-powered
graphs on the web.
-- 
View this message in context: 
http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1690627.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] Multi-panel Pie Charts.

2010-03-25 Thread Jim Lemon

On 03/26/2010 12:41 AM, Hrishi Mittal wrote:


Hi Jim, what's the tab.title function you are using?


It's in the plotrix package. The panes function will be in the next version.

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] Multi-panel Pie Charts.

2010-03-24 Thread Sharpie


Gurmeet wrote:
 
 Hi All,
 
 I'm trying to find out a way to plot multi-panel pie charts. It may not be
 the best way to present data, but I would still need one.
 

Would paneled bar charts not suffice?

I don't mean to be harsh, but the only situation I can think of where I
would consider a pie chart would be if I wanted to take advantage of the
fact that people are worse at judging differences in area than they are at
judging differences in length in order to hide some trend in my data.

Anyway, the following code uses ggplot2 to produce a paneled bar plot from
your data:

  require( ggplot2 )

  productData - structure(list(variable = structure(c(1L, 1L, 1L, 1L, 2L,
2L, 
2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L), .Label = c(ProdA, 
ProdB, ProdC, ProdD), class = factor), month = structure(c(3L, 
2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L), .Label =
c(Apr, 
Feb, Jan, Mar), class = factor), value = c(25, 30, 25, 
10, 25, 30, 50, 40, 40, 30, 20, 40, 10, 10, 5, 10)), .Names =
c(variable, 
month, value), class = data.frame, row.names = c(NA, -16L))

  productPlot - qplot( variable, value, data = productData, geom = 'bar',
xlab = 'Product', ylab = 'Percentage' ) +
facet_wrap( ~ month ) +
theme_bw()

  print( productPlot ) 


I know it's not what you want, but I personally need a strong argument for
generating pie charts before I would perpetuate their use.



Gurmeet wrote:
 
 
 1. Is anyone aware of some in-built script/function which can do this for
 me. I'm aware of one given in Deepayan's book, but anything apart from
 this?
 
 
 2. I tried using Deepayan's script on following data set but it doesn't
 seem
 to work as expected - labels are getting repeated/overlapping. I'm really
 not sure what could be the problem, can anyone help please. I hope data is
 in the right format, as expected.
 
  Data read into object foo:
 
 variable month value
 ProdA   Jan25
 ProdA   Feb30
 ProdA   Mar25
 ProdA   Apr10
 ProdB   Jan25
 ProdB   Feb30
 ProdB   Mar50
 ProdB   Apr40
 ProdC   Jan40
 ProdC   Feb30
 ProdC   Mar20
 ProdC   Apr40
 ProdD   Jan10
 ProdD   Feb10
 ProdD   Mar 5
 ProdD   Apr10
 
 {SNIP}
 
 Thanks in advance,
 Gurmeet
 

Providing data as a printed table, like you did, is not the most effective
way to transmit example data on this list.  There are two major
disadvantages:

  *  Tabulated data often gets mangled in email

  *  Tabulated data can not be copied and pasted directly into R to
regenerate the example data.frame- it takes me ~4 minutes of mucking around
with Excel to regenerate a .csv file that R can ingest.  This added time
will limit the number of people who will attempt to investigate your
problem.

The best way to transmit the contents of a data frame is to paste the output
of the dput() function.  This function dumps the data frame to an R command
that can be simply copied and pasted into a R session to regenerate the
data.frame.  The results of dput is the structure() command I used in my
example above.


Hope this helps in some way!

-Charlie

-
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689524.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] Multi-panel Pie Charts.

2010-03-24 Thread Gary Miller
Thanks for your reply Sharpie. I completely understand that it may not be
the best to go with muti-panel pie charts, but my group would like to have
this utility along with barplot/dotplot (may be, using it for proportions
data). Thanks,

~Gurmeet

On Wed, Mar 24, 2010 at 3:38 PM, Sharpie ch...@sharpsteen.net wrote:



 Gurmeet wrote:
 
  Hi All,
 
  I'm trying to find out a way to plot multi-panel pie charts. It may not
 be
  the best way to present data, but I would still need one.
 

 Would paneled bar charts not suffice?

 I don't mean to be harsh, but the only situation I can think of where I
 would consider a pie chart would be if I wanted to take advantage of the
 fact that people are worse at judging differences in area than they are at
 judging differences in length in order to hide some trend in my data.

 Anyway, the following code uses ggplot2 to produce a paneled bar plot from
 your data:

  require( ggplot2 )

  productData - structure(list(variable = structure(c(1L, 1L, 1L, 1L, 2L,
 2L,
2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L), .Label = c(ProdA,
ProdB, ProdC, ProdD), class = factor), month = structure(c(3L,
2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L), .Label =
 c(Apr,
Feb, Jan, Mar), class = factor), value = c(25, 30, 25,
10, 25, 30, 50, 40, 40, 30, 20, 40, 10, 10, 5, 10)), .Names =
 c(variable,
month, value), class = data.frame, row.names = c(NA, -16L))

  productPlot - qplot( variable, value, data = productData, geom = 'bar',
xlab = 'Product', ylab = 'Percentage' ) +
facet_wrap( ~ month ) +
theme_bw()

  print( productPlot )


 I know it's not what you want, but I personally need a strong argument for
 generating pie charts before I would perpetuate their use.



 Gurmeet wrote:
 
 
  1. Is anyone aware of some in-built script/function which can do this for
  me. I'm aware of one given in Deepayan's book, but anything apart from
  this?
 
 
  2. I tried using Deepayan's script on following data set but it doesn't
  seem
  to work as expected - labels are getting repeated/overlapping. I'm really
  not sure what could be the problem, can anyone help please. I hope data
 is
  in the right format, as expected.
 
   Data read into object foo:
 
  variable month value
  ProdA   Jan25
  ProdA   Feb30
  ProdA   Mar25
  ProdA   Apr10
  ProdB   Jan25
  ProdB   Feb30
  ProdB   Mar50
  ProdB   Apr40
  ProdC   Jan40
  ProdC   Feb30
  ProdC   Mar20
  ProdC   Apr40
  ProdD   Jan10
  ProdD   Feb10
  ProdD   Mar 5
  ProdD   Apr10
 
  {SNIP}
 
  Thanks in advance,
  Gurmeet
 

 Providing data as a printed table, like you did, is not the most effective
 way to transmit example data on this list.  There are two major
 disadvantages:

  *  Tabulated data often gets mangled in email

  *  Tabulated data can not be copied and pasted directly into R to
 regenerate the example data.frame- it takes me ~4 minutes of mucking around
 with Excel to regenerate a .csv file that R can ingest.  This added time
 will limit the number of people who will attempt to investigate your
 problem.

 The best way to transmit the contents of a data frame is to paste the
 output
 of the dput() function.  This function dumps the data frame to an R command
 that can be simply copied and pasted into a R session to regenerate the
 data.frame.  The results of dput is the structure() command I used in my
 example above.


 Hope this helps in some way!

 -Charlie

 -
 Charlie Sharpsteen
 Undergraduate-- Environmental Resources Engineering
 Humboldt State University
 --
 View this message in context:
 http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689524.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.htmlhttp://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] Multi-panel Pie Charts.

2010-03-24 Thread Gary Miller
Gurmeet and I are looking for such utility. It could be helpful!

On Wed, Mar 24, 2010 at 3:46 PM, Gary Miller mail2garymil...@gmail.comwrote:

 Thanks for your reply Sharpie. I completely understand that it may not be
 the best to go with muti-panel pie charts, but my group would like to have
 this utility along with barplot/dotplot (may be, using it for proportions
 data). Thanks,

 ~Gurmeet

   On Wed, Mar 24, 2010 at 3:38 PM, Sharpie ch...@sharpsteen.net wrote:



 Gurmeet wrote:
 
  Hi All,
 
  I'm trying to find out a way to plot multi-panel pie charts. It may not
 be
  the best way to present data, but I would still need one.
 

 Would paneled bar charts not suffice?

 I don't mean to be harsh, but the only situation I can think of where I
 would consider a pie chart would be if I wanted to take advantage of the
 fact that people are worse at judging differences in area than they are at
 judging differences in length in order to hide some trend in my data.

 Anyway, the following code uses ggplot2 to produce a paneled bar plot from
 your data:

  require( ggplot2 )

  productData - structure(list(variable = structure(c(1L, 1L, 1L, 1L, 2L,
 2L,
2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L), .Label = c(ProdA,
ProdB, ProdC, ProdD), class = factor), month = structure(c(3L,
2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 2L, 4L, 1L), .Label =
 c(Apr,
Feb, Jan, Mar), class = factor), value = c(25, 30, 25,
10, 25, 30, 50, 40, 40, 30, 20, 40, 10, 10, 5, 10)), .Names =
 c(variable,
month, value), class = data.frame, row.names = c(NA, -16L))

  productPlot - qplot( variable, value, data = productData, geom = 'bar',
xlab = 'Product', ylab = 'Percentage' ) +
facet_wrap( ~ month ) +
theme_bw()

  print( productPlot )


 I know it's not what you want, but I personally need a strong argument for
 generating pie charts before I would perpetuate their use.



 Gurmeet wrote:
 
 
  1. Is anyone aware of some in-built script/function which can do this
 for
  me. I'm aware of one given in Deepayan's book, but anything apart from
  this?
 
 
  2. I tried using Deepayan's script on following data set but it doesn't
  seem
  to work as expected - labels are getting repeated/overlapping. I'm
 really
  not sure what could be the problem, can anyone help please. I hope data
 is
  in the right format, as expected.
 
   Data read into object foo:
 
  variable month value
  ProdA   Jan25
  ProdA   Feb30
  ProdA   Mar25
  ProdA   Apr10
  ProdB   Jan25
  ProdB   Feb30
  ProdB   Mar50
  ProdB   Apr40
  ProdC   Jan40
  ProdC   Feb30
  ProdC   Mar20
  ProdC   Apr40
  ProdD   Jan10
  ProdD   Feb10
  ProdD   Mar 5
  ProdD   Apr10
 
  {SNIP}
 
  Thanks in advance,
  Gurmeet
 

 Providing data as a printed table, like you did, is not the most effective
 way to transmit example data on this list.  There are two major
 disadvantages:

  *  Tabulated data often gets mangled in email

  *  Tabulated data can not be copied and pasted directly into R to
 regenerate the example data.frame- it takes me ~4 minutes of mucking
 around
 with Excel to regenerate a .csv file that R can ingest.  This added time
 will limit the number of people who will attempt to investigate your
 problem.

 The best way to transmit the contents of a data frame is to paste the
 output
 of the dput() function.  This function dumps the data frame to an R
 command
 that can be simply copied and pasted into a R session to regenerate the
 data.frame.  The results of dput is the structure() command I used in my
 example above.


 Hope this helps in some way!

 -Charlie

 -
 Charlie Sharpsteen
 Undergraduate-- Environmental Resources Engineering
 Humboldt State University
 --
 View this message in context:
 http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689524.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.htmlhttp://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] Multi-panel Pie Charts.

2010-03-24 Thread Sharpie


Gary Miller wrote:
 
 Thanks for your reply Sharpie. I completely understand that it may not be
 the best to go with muti-panel pie charts, but my group would like to have
 this utility along with barplot/dotplot (may be, using it for proportions
 data). Thanks,
 

Well, if the management trolls *DEMAND* pie, then these sites provide a good
start with ggplot2:

 
http://learnr.wordpress.com/2009/08/20/ggplot2-version-of-figures-in-lattice-multivariate-data-visualization-with-r-part-13-2/

  http://had.co.nz/ggplot2/coord_polar.html

Using the data I posted before, you could apply those approach with:

  productPie - qplot( factor(1), value/100, data = productData,
geom = 'bar', fill = variable,
xlab = '',
ylab = '' ) +
facet_wrap( ~ month, scales = 'free_y' ) +
coord_polar( theta = 'y' ) +
scale_y_continuous( formatter = 'percent' ) +
theme_bw()

  print( productPie )

The beauty of ggplot2 is that that is basically the same chart I posted last
time, the bars have just been bent into a pie through the use of
coord_polar().  It probably needs some fine-tuning, but I'll leave that up
to you.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689591.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] Multi-panel Pie Charts.

2010-03-24 Thread Jim Lemon

On 03/25/2010 06:00 AM, Gurmeet wrote:

Hi All,

I'm trying to find out a way to plot multi-panel pie charts. It may not be
the best way to present data, but I would still need one.


Hi Gurmeet,
Your message prompted me to finish a little function that I had almost 
forgotten.


panes-function(nrow=2,ncol=2,mar=c(0,0,1.6,0),oma=c(2,1,1,1)) {
 oldpar-par(mar,mfrow,oma)
 par(mfrow=c(nrow,ncol),mar=mar,oma=oma)
 return(oldpar)
}
oldpar-panes()
pie(foo$value[foo$month==Jan],labels=foo$variable[foo$month==Jan],
 radius=0.7)
tab.title(January sales,tab.col=#66)
box()
pie(foo$value[foo$month==Feb],labels=foo$variable[foo$month==Feb],
 radius=0.7)
tab.title(February sales,tab.col=#66)
box()
pie(foo$value[foo$month==Mar],labels=foo$variable[foo$month==Mar],
 radius=0.7)
tab.title(March sales,tab.col=#66)
box()
pie(foo$value[foo$month==Apr],labels=foo$variable[foo$month==Apr],
 radius=0.7)
tab.title(April sales,tab.col=#66)
box()
par(xpd=TRUE)
mtext(First quarter sales,at=-1.2,line=0.8,side=1,cex=1.5)
par(xpd=FALSE)
par(oldpar)

Is this what you wanted?

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] Multi-panel Pie Charts.

2010-03-24 Thread Gurmeet
Hi Jim, exactly what we are expecting. Thanks a lot for your efforts... it
should be really helpful!

On Wed, Mar 24, 2010 at 10:50 PM, Jim Lemon j...@bitwrit.com.au wrote:

 On 03/25/2010 06:00 AM, Gurmeet wrote:

 Hi All,

 I'm trying to find out a way to plot multi-panel pie charts. It may not be
 the best way to present data, but I would still need one.

 Hi Gurmeet,
 Your message prompted me to finish a little function that I had almost
 forgotten.

 panes-function(nrow=2,ncol=2,mar=c(0,0,1.6,0),oma=c(2,1,1,1)) {
  oldpar-par(mar,mfrow,oma)
  par(mfrow=c(nrow,ncol),mar=mar,oma=oma)
  return(oldpar)
 }
 oldpar-panes()
 pie(foo$value[foo$month==Jan],labels=foo$variable[foo$month==Jan],
  radius=0.7)
 tab.title(January sales,tab.col=#66)
 box()
 pie(foo$value[foo$month==Feb],labels=foo$variable[foo$month==Feb],
  radius=0.7)
 tab.title(February sales,tab.col=#66)
 box()
 pie(foo$value[foo$month==Mar],labels=foo$variable[foo$month==Mar],
  radius=0.7)
 tab.title(March sales,tab.col=#66)
 box()
 pie(foo$value[foo$month==Apr],labels=foo$variable[foo$month==Apr],
  radius=0.7)
 tab.title(April sales,tab.col=#66)
 box()
 par(xpd=TRUE)
 mtext(First quarter sales,at=-1.2,line=0.8,side=1,cex=1.5)
 par(xpd=FALSE)
 par(oldpar)

 Is this what you wanted?

 Jim



[[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] Multi-panel Pie Charts.

2010-03-24 Thread Gurmeet
Thanks Charlie... I think its worth exploring ggplot2 functionality.

On Wed, Mar 24, 2010 at 4:06 PM, Sharpie ch...@sharpsteen.net wrote:


  Thanks for your reply Sharpie. I completely understand that it may not be
  the best to go with muti-panel pie charts, but my group would like to
 have
  this utility along with barplot/dotplot (may be, using it for proportions
  data). Thanks,
 

 Well, if the management trolls *DEMAND* pie, then these sites provide a
 good
 start with ggplot2:



 http://learnr.wordpress.com/2009/08/20/ggplot2-version-of-figures-in-lattice-multivariate-data-visualization-with-r-part-13-2/

  http://had.co.nz/ggplot2/coord_polar.html

 Using the data I posted before, you could apply those approach with:

  productPie - qplot( factor(1), value/100, data = productData,
geom = 'bar', fill = variable,
xlab = '',
ylab = '' ) +
facet_wrap( ~ month, scales = 'free_y' ) +
coord_polar( theta = 'y' ) +
scale_y_continuous( formatter = 'percent' ) +
theme_bw()

  print( productPie )

 The beauty of ggplot2 is that that is basically the same chart I posted
 last
 time, the bars have just been bent into a pie through the use of
 coord_polar().  It probably needs some fine-tuning, but I'll leave that up
 to you.

 Good luck!

 -Charlie

 -
 Charlie Sharpsteen
 Undergraduate-- Environmental Resources Engineering
 Humboldt State University
 --
 View this message in context:
 http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689591.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.htmlhttp://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] multi-argument returns

2010-02-19 Thread Randall Wrong
Thanks to Patrick Burns, Bert Gunter, Steve Lianoglou, and Professor Brian
Ripley.


2010/2/17 Prof Brian Ripley rip...@stats.ox.ac.uk

 On Wed, 17 Feb 2010, Randall Wrong wrote:

 Dear R users,

 I have multi-argument returns in a function and I am warned by the program
 they are deprecated.


 Defunct as from the next R release.


 I have found this in the R-help archives :


 in 2001!


 http://tolstoy.newcastle.edu.au/R/help/01c/0319.html
 http://tolstoy.newcastle.edu.au/R/help/01c/0356.html

 Since I am not too good at programming, the list solution seems the better
 one for me. It is also the one advocated by Kevin Murphy.

 So rather than writing return(x,y,z), I should write at the end of my
 function :


 return(list(x=x,y=y,z=z)) is the preferred replacement.
 (As the help page for return() has long said.)


 g=function() {

   #...

   result=list(x,y,z)
   return(result)
 }

 Is that correct ?

 Then shoud l use g[1] or g[[1]] ?


 No change is needed (I think you mean g()$x etc) as return(x,y,z) and
 return(list(x=x,y=y,z=z)) are identical in their effects.


 Thank you for you help.

 Randall


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


[[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] multi-argument returns

2010-02-17 Thread Steve Lianoglou
Hi,

On Wed, Feb 17, 2010 at 4:09 PM, Randall Wrong randall.wr...@gmail.com wrote:
 Dear R users,

 I have multi-argument returns in a function and I am warned by the program
 they are deprecated.

 I have found this in the R-help archives :

 http://tolstoy.newcastle.edu.au/R/help/01c/0319.html
 http://tolstoy.newcastle.edu.au/R/help/01c/0356.html

 Since I am not too good at programming, the list solution seems the better
 one for me. It is also the one advocated by Kevin Murphy.

 So rather than writing return(x,y,z), I should write at the end of my
 function :

 g=function() {

    #...

    result=list(x,y,z)
    return(result)
 }

 Is that correct ?

FYI, in R the last line of a function is its return value, so you
could simply do:

g - function() {
  list(x=x, y=y, z=z)
}

 Then shoud l use g[1] or g[[1]] ?

Just to avoid a mistake or ambiguity here, I wouldn't use g as a
variable because you are using that as your function name.

So after defining the function `g`, you could do:

myvalue - g()

Then you would use: myvalue[[1]]

myvalue[1] would return you a list that has one element in it (the
first one), where as using myvalue[[1]] just gives you the first
element of the list.

Using named arguments when constructing your list as I did (eg.
list(x=x, ...)), you can then also do:

myvalue$x

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

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


Re: [R] multi-argument returns

2010-02-17 Thread Prof Brian Ripley

On Wed, 17 Feb 2010, Randall Wrong wrote:


Dear R users,

I have multi-argument returns in a function and I am warned by the program
they are deprecated.


Defunct as from the next R release.


I have found this in the R-help archives :


in 2001!


http://tolstoy.newcastle.edu.au/R/help/01c/0319.html
http://tolstoy.newcastle.edu.au/R/help/01c/0356.html

Since I am not too good at programming, the list solution seems the better
one for me. It is also the one advocated by Kevin Murphy.

So rather than writing return(x,y,z), I should write at the end of my
function :


return(list(x=x,y=y,z=z)) is the preferred replacement.
(As the help page for return() has long said.)


g=function() {

   #...

   result=list(x,y,z)
   return(result)
}

Is that correct ?

Then shoud l use g[1] or g[[1]] ?


No change is needed (I think you mean g()$x etc) as return(x,y,z) and 
return(list(x=x,y=y,z=z)) are identical in their effects.



Thank you for you help.

Randall


--
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] multi-dimensional array with different number of dimensions?

2009-12-12 Thread David Winsemius


On Dec 12, 2009, at 5:36 PM, parkbomee wrote:



Hi,

Is it possible to assign to an array with different dimensions?
That is to say, supposing a three dimensional array,
the third dimension of the array has matrices of different sizes?


Use a list. Or populate with NA's




array

, , 1
 [1] [2] [3]
[1]  111


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

[1]  111

[2]  111

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


[1]  111


[2]  111


[3]  111


something like this??


Thanks,
B

_


[[alternative HTML version deleted]]

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] multi variate plot with string data

2009-11-26 Thread frenchcr

is there something wrong with the way i asked the question


frenchcr wrote:
 
 
 Ive got two columns in data_set that are strings
 
 the first column is called character and has levels:
 good, bad, ugly
 
 the second column is called abusive and has levels:
 aggressive, moderately aggressive, mildly aggressive
 
 
 I want to do a stacked boxplot that has this sort of structure: 
 
 %aggressive %aggressive
 %aggressive
 %moderately aggressive %moderately aggressive  %moderately
 aggressive
 %mildly aggressive %mildly aggressive %mildly
 aggressive
 %not agressive %not agressive  %not
 agressive
 
bad  good  
 ugly
 
 
 ...with legend at the size showing which colour each of the abusive
 levels takes.
 
 
 How is it done?
 

-- 
View this message in context: 
http://old.nabble.com/multi-variate-plot-with-string-data-tp26517211p26525342.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] multi variate plot with string data

2009-11-26 Thread frenchcr


Thanks!!


this works perfectly

dat = data.frame(Aggressive = data_set$var1 , Behaviour=data_set$var2)
plot(table(dat))


...its better than a stacked boxplot as it gives also different width of
columns on the diagram...an extra layer of information.









frenchcr wrote:
 
 
 Ive got two columns in data_set that are strings
 
 the first column is called character and has levels:
 good, bad, ugly
 
 the second column is called abusive and has levels:
 aggressive, moderately aggressive, mildly aggressive
 
 
 I want to do a stacked boxplot that has this sort of structure: 
 
 %aggressive %aggressive
 %aggressive
 %moderately aggressive %moderately aggressive  %moderately
 aggressive
 %mildly aggressive %mildly aggressive %mildly
 aggressive
 %not agressive %not agressive  %not
 agressive
 
bad  good  
 ugly
 
 
 ...with legend at the size showing which colour each of the abusive
 levels takes.
 
 
 How is it done?
 

-- 
View this message in context: 
http://old.nabble.com/multi-variate-plot-with-string-data-tp26517211p26534782.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] Multi-line comments?

2009-07-22 Thread Gabor Grothendieck
Try
if (FALSE) { ... }

On Wed, Jul 22, 2009 at 10:30 AM, Mark Knechtmarkkne...@gmail.com wrote:
 Hi,
   I looked in the language definition and was surprised. Is there
 really no multi-line/block comment defined in R?

   I wanted to comment out 20 lines that I'm moving to a function but
 didn't want to delete them. Is there no defined way to get around
 using a # on each of the 20 lines?

 Thanks,
 Mark

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

2009-07-22 Thread Paul Hiemstra

Mark Knecht wrote:

Hi,
   I looked in the language definition and was surprised. Is there
really no multi-line/block comment defined in R?

   I wanted to comment out 20 lines that I'm moving to a function but
didn't want to delete them. Is there no defined way to get around
using a # on each of the 20 lines?

Thanks,
Mark

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 issue has come up before, and as far as I know there is no 
multiline comment. However, there are a few ways of commenting out 
larges pieces of code.


- Use a good text editor, Kate (KDE) allows you to select the 20 lines 
and press Ctrl-D to comment them all at once.

- Use a setup like:
if(FALSE) {
line1
...
line20
}

And set FALSE to TRUE if you want to let the code be executed.

These are probably not the only ones, but this is what I could think of 
right now.


cheers and good luck,
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] Multi-line comments?

2009-07-22 Thread Michael Knudsen
On Wed, Jul 22, 2009 at 4:30 PM, Mark Knechtmarkkne...@gmail.com wrote:

   I wanted to comment out 20 lines that I'm moving to a function but
 didn't want to delete them. Is there no defined way to get around
 using a # on each of the 20 lines?

Just like you, I have been longing for that myself. It seems that the
answer is negative, so I have ended up using

if (1==0)
{
   # code goes here
}

although is not really nice to look at.

-- 
Michael Knudsen
micknud...@gmail.com
http://lifeofknudsen.blogspot.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] Multi-line comments?

2009-07-22 Thread Barry Rowlingson
On Wed, Jul 22, 2009 at 3:30 PM, Mark Knechtmarkkne...@gmail.com wrote:
 Hi,
   I looked in the language definition and was surprised. Is there
 really no multi-line/block comment defined in R?

   I wanted to comment out 20 lines that I'm moving to a function but
 didn't want to delete them. Is there no defined way to get around
 using a # on each of the 20 lines?

 Hmmm I think this might be a FAQ... Usual suggestions are:

 1. use an editor that can do un/commenting of regions.

 2. Stick it in an if(FALSE){ ... } block, but that's only good if
it's syntactically correct.

 I prefer:

 3. Manage your code under a decent SCM and don't fear the delete.

Barry

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


Re: [R] Multi-line comments?

2009-07-22 Thread Jonathan Baron
On 07/22/09 07:30, Mark Knecht wrote:
 Hi,
I looked in the language definition and was surprised. Is there
 really no multi-line/block comment defined in R?
 
I wanted to comment out 20 lines that I'm moving to a function but
 didn't want to delete them. Is there no defined way to get around
 using a # on each of the 20 lines?

This topic has come up before and the answer seems to be no, although
you can do tricky things like defining a function containing the
comment as a quoted string (beginning and ending with quote marks), or
putting a quoted string after an if() for a condition that isn't met.
It helps that line breaks are allowed in quoted strings.

However

With (x)emacs and ESS, you can say
M-x comment-region
after defining a region with point and mark.

I got tired of typing this, so I defined the following in my
.xemacs/init.el and .emacs files:

(global-set-key \M-r 'comment-region)

So now I do it with alt-R.  That key may have had some other
purpose, but not one I ever used.

I think the alt key is something else on a Mac.  And I have no idea
whether this will work on Windows.

Jon
-- 
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron

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


Re: [R] Multi-line comments?

2009-07-22 Thread Erik Iverson
What editor are you all using to write R code?  Many will have ways of doing 
what you want, e.g., comment-region (bound  by default to M-; through 
comment-dwim) in Emacs. 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Michael Knudsen
Sent: Wednesday, July 22, 2009 9:55 AM
To: Mark Knecht
Cc: r-help
Subject: Re: [R] Multi-line comments?

On Wed, Jul 22, 2009 at 4:30 PM, Mark Knechtmarkkne...@gmail.com wrote:

   I wanted to comment out 20 lines that I'm moving to a function but
 didn't want to delete them. Is there no defined way to get around
 using a # on each of the 20 lines?

Just like you, I have been longing for that myself. It seems that the
answer is negative, so I have ended up using

if (1==0)
{
   # code goes here
}

although is not really nice to look at.

-- 
Michael Knudsen
micknud...@gmail.com
http://lifeofknudsen.blogspot.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] Multi-line comments?

2009-07-22 Thread Michael Knudsen
On Wed, Jul 22, 2009 at 5:27 PM, Erik Iversoneiver...@nmdp.org wrote:

 What editor are you all using to write R code?  Many will have ways of doing 
 what you want, e.g., comment-region (bound  by default to M-; through 
 comment-dwim) in Emacs.

Cool! I'm using Xcode, and I have just realized that cmd+/ will make a
block comment. By default it adds '//' instead of '#', but I guess
that it can be fixed somehow.

-- 
Michael Knudsen
micknud...@gmail.com
http://lifeofknudsen.blogspot.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] Multi-line comments?

2009-07-22 Thread Mark Knecht
Thanks Gabor and EVERYONE else who answered so quickly.

On Wed, Jul 22, 2009 at 7:50 AM, Gabor
Grothendieckggrothendi...@gmail.com wrote:
 Try
 if (FALSE) { ... }

 On Wed, Jul 22, 2009 at 10:30 AM, Mark Knechtmarkkne...@gmail.com wrote:
 Hi,
   I looked in the language definition and was surprised. Is there
 really no multi-line/block comment defined in R?

   I wanted to comment out 20 lines that I'm moving to a function but
 didn't want to delete them. Is there no defined way to get around
 using a # on each of the 20 lines?

 Thanks,
 Mark

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

2009-07-22 Thread Paul Hiemstra

Erik Iverson schreef:
What editor are you all using to write R code?  Many will have ways of doing what you want, e.g., comment-region (bound  by default to M-; through comment-dwim) in Emacs. 
  

I use Kate, the advanced text editor in KDE.
Paul

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Michael Knudsen
Sent: Wednesday, July 22, 2009 9:55 AM
To: Mark Knecht
Cc: r-help
Subject: Re: [R] Multi-line comments?

On Wed, Jul 22, 2009 at 4:30 PM, Mark Knechtmarkkne...@gmail.com wrote:

  

  I wanted to comment out 20 lines that I'm moving to a function but
didn't want to delete them. Is there no defined way to get around
using a # on each of the 20 lines?



Just like you, I have been longing for that myself. It seems that the
answer is negative, so I have ended up using

if (1==0)
{
   # code goes here
}

although is not really nice to look at.




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


Re: [R] Multi-line plots - max Y?

2009-07-03 Thread Mark Knecht
On Fri, Jul 3, 2009 at 1:38 PM, Dylan
Beaudettedylan.beaude...@gmail.com wrote:
 Hi,

 how about something like this:

 a - 1:10
 b - cumsum(a)
 c - cumsum(b)
 d - cumsum(c)

 X- data.frame(a,b,c,d)


 plot(b ~ a, data=X, type=l, col=blue, ylim=c(0,max(X)))
 lines(c ~ a, data=X, col=green)
 lines(d ~ a, data=X, col=red)
 legend('topleft', legend=c('a', 'b', 'c'), col=c('blue', 'green', 'red'), 
 lty=1)


Darn you make it look easy! Thanks!

- Mark

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


Re: [R] Multi-line plots - max Y?

2009-07-03 Thread Dylan Beaudette
Hi,

how about something like this:

a - 1:10
b - cumsum(a)
c - cumsum(b)
d - cumsum(c)

X- data.frame(a,b,c,d)


plot(b ~ a, data=X, type=l, col=blue, ylim=c(0,max(X)))
lines(c ~ a, data=X, col=green)
lines(d ~ a, data=X, col=red)
legend('topleft', legend=c('a', 'b', 'c'), col=c('blue', 'green', 'red'), lty=1)



On Fri, Jul 3, 2009 at 1:13 PM, Mark Knechtmarkkne...@gmail.com wrote:
 Hi all,
   OK, I'm struggling a bit with getting good basic plots so I put
 together this little example. It works - sort of - but it seems a bit
 hokey to me. Can someone suggest how a pro would do it?

   The goal is to take data from 4 columns of a data.frame (data read
 in by read.csv) and generate a plot with the borders and text in black
 and three lines in different colors. The code below generates that but
 loses data because the second and third lines have values greater than
 the first which set the Y axis max. I can use something like max(X$d)
 to get the max size required but I don't see how to set the Y
 dimension it in the first plot command. How do I do that? I looked in
 ?par but didn't spot it.

   Last, how would I add a legend to explain the 3 lines? I haven't
 studied it yet but maybe someone can point me at the right stuff.

   So, how could this little example be made to have all the data on
 the plot and how could I code it better? I don't think those
 'as.vector' coercions are really the right way.

 Thanks,
 Mark


 X- data.frame(a=1:10, b=cumsum(X$a), c=cumsum(X$b), d=cumsum(X$c))
 X

 plot(X$b ~ X$a, type=l, col=blue)
 lines(as.vector(X$a),as.vector(X$c), col=green)
 lines(as.vector(X$a),as.vector(X$d), col=red)

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


  1   2   >