[R] what is wrong with for and if cycle in R

2013-12-19 Thread Jie Tang
hi
 I used a two nested cycle by if and for by such code

for(ity in 1:4)
{
if (ity==1£©
{
print(ity)
}
}

when I run the code it failed and R tell me that
"error: unrespected '}' in "}""

and when I reduce a }

for(ity in 1:4)
{
if (ity==2£©
{
print(ity)
}

R will print 4 but not 2 as what I repect

Could anyone tell me what is the matter with R and how to modify it?

thank you .
-- 
TANG Jie

[[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] what is wrong with for and if cycle in R

2013-12-19 Thread Ingmar Visser
I get this error below, there seems to be hidden character in your
input instead of a parenthesis:

> for(ity in 1:4)
+ {
+ if (ity==1)
Error: unexpected input in:
"{
if (ity==1Ô"
> {
+ print(ity)
+ }
Error in print(ity) : object 'ity' not found
> }
Error: unexpected '}' in "}"
>

hth, Ingmar


On Thu, Dec 19, 2013 at 10:07 AM, Jie Tang  wrote:
> hi
>  I used a two nested cycle by if and for by such code
>
> for(ity in 1:4)
> {
> if (ity==1)
> {
> print(ity)
> }
> }
>
> when I run the code it failed and R tell me that
> "error: unrespected '}' in "}""
>
> and when I reduce a }
>
> for(ity in 1:4)
> {
> if (ity==2)
> {
> print(ity)
> }
>
> R will print 4 but not 2 as what I repect
>
> Could anyone tell me what is the matter with R and how to modify it?
>
> thank you .
> --
> TANG Jie
>
> [[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] what is wrong with for and if cycle in R

2013-12-19 Thread Pascal Oettli
Hi,

It seems the right prenthesis ")" in the "if" statement is in
different encoding.

>From your script:
> charToRaw('if (ity==1)')[11:13]
[1] ef bc 89

> charToRaw(')')
[1] 29

 By changing the right parenthesis, it works fine.

HTH,
Pascal

On 19 December 2013 18:07, Jie Tang  wrote:
> hi
>  I used a two nested cycle by if and for by such code
>
> for(ity in 1:4)
> {
> if (ity==1)
> {
> print(ity)
> }
> }
>
> when I run the code it failed and R tell me that
> "error: unrespected '}' in "}""
>
> and when I reduce a }
>
> for(ity in 1:4)
> {
> if (ity==2)
> {
> print(ity)
> }
>
> R will print 4 but not 2 as what I repect
>
> Could anyone tell me what is the matter with R and how to modify it?
>
> thank you .
> --
> TANG Jie
>
> [[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] GLMM parameter estimates giving opposite trends

2013-12-19 Thread Ben Bolker
Diana Virkki  griffith.edu.au> writes:

> 
> I apologize if this is a simple question.
> 
> I am running GLMM's using glmmML and model averaging with
>  MuMIn. One of the
> parameter estimates for a parameter (firefreq) in the
>  best model is giving
> a positive number, where in reality I know this to be a negative
> correlation.
> I have checked and double checked the data that has
> gone in and this is not
> the issue. This is occurring for numerous variables in my models.
> 
> As far as I was aware the parameter estimate is 
> indicative of the direction
> of the relationship? Is there any reason why this model would give me
> opposite trends?

  It's a little hard to guess without a reproducible example (see
http://tinyurl.com/reproducible-000), but one guess is that you have
one or more confounding variables
 in your multivariate model;
that is, the _marginal_ effect of fire frequency is to decrease the
mean response, but the effect _conditional_ on all of the other
variables in the model is to increase it.  This phenomenon is most
common when the predictors are strongly correlated.

  Do you get a sensible sign when you fit a model with just the
focal parameter?

  Ben Bolker

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


Re: [R] plot different groups as factors

2013-12-19 Thread Duncan Mackay
Hi Luigi

A quick guess with lattice

library(lattice)

structure(list(time = c(18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 
18, 18, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
12, 12, 12, 12, 12, 12, 12, 12), clas = c("medium", "medium", 
"medium", "medium", "medium", "medium", "medium", "medium", "medium", 
"medium", "medium", "medium", "medium", "medium", "high", "high", 
"high", "high", "high", "high", "high", "low", "low", "low", 
"low", "low", "low", "low", "medium", "medium", "medium", "medium", 
"medium", "medium", "medium", "medium", "medium", "medium", "medium", 
"medium", "medium", "medium", "medium", "medium", "medium", "medium", 
"high", "high", "high", "high", "high", "high", "high", "high", 
"high", "high", "low", "low", "low", "low", "low", "low", "low", 
"low", "low", "low"), value = c(2.92, 0.01, 0.36, 3.16, 0.99, 
0.38, 0.01, 5.1, 0.04, 0.01, 1.33, 4.13, 0.15, 0.15, 14.18, 4290.14, 
26.8, 5.33, 17.58, 14.29, 248.5, 0.01, 0, 0, 0, 0, 0, 0, 0.151395382, 
5.327863403, 5.10096383, 1.32567787, 4.352404124, 0.458606982, 
2.915908912, 0.011996374, 0.364710382, 0.033016026, 3.161701212, 
0.381564497, 0.010971385, 0.035646472, 0.014781805, 4.129708296, 
0.153094117, 0.018497847, 15.09178491, 17.58393041, 14.17643928, 
4290.143561, 26.79730719, 294.6367065, 14.2888441, 248.495231, 
209.3131795, 2014.506722, 0.010751273, 0.002325138, 0.000637473, 
0.003984336, 0.006018154, 0.003620907, 7.45936e-05, 0.000142311, 
0.002460417, 0.001280189)), .Names = c("time", "clas", "value"
), row.names = c(NA, -66L), class = "data.frame")

bwplot(value~factor(time)|factor(dat$clas, levels =
c("low","medium","high")),dat, hor=F, layout = c(3,1),scales = list(relation
= "free") )

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Luigi Marongiu
Sent: Thursday, 19 December 2013 10:19
To: r-help@r-project.org
Subject: [R] plot different groups as factors

dear all,
i would like to plot the value of different response groups. when i simply
use  plot(y ~ x) i obtain a series of boxplots. i would rather use dots. i
also tried with stripchart(y ~ x), which gives better results but does not
place properly the labels since place them alphabetically.
in addition i actually have 6 response groups: 3 classes (low, medium,
high) and 2 sampling time (12 and 18 months).
how can i generate these individual groups and plot them in the correct
order (low, medium, high and 12, 18)? i believe is something to do with the
factors but i don't know how to implement them.
what i am looking for is to generate a figure such as the one i sketched in
the attached file. i also attached a dataframe version of my data. the
vectors containing the same data are:
time <-c(  18,18,18,18,18,18,18,18,18,
18,18,18,18,18,18,18,18,18,18,
18,18,18,18,18,18,18,18,18,12,
12,12,12,12,12,12,12,12,12,12,
12,12,12,12,12,12,12,12,12,12,
12,12,12,12,12,12,12,12,12,12,
12,12,12,12,12,12,12)
class <-c(medium,medium,medium,medium,medium,
medium,medium,medium,medium,medium,medium,
medium,medium,medium,high,high,high,high,
high,high,high,low,low,low,low,low,low,
low,medium,medium,medium,medium,medium,medium,
medium,medium,medium,medium,medium,medium,
medium,medium,medium,medium,medium,medium,high,
high,high,high,high,high,high,high,high,
high,low,low,low,low,low,low,low,low,
low,low)
value <-c(2.92,0.01,0.36,3.16,0.99,0.38,
0.01,5.1,0.04,0.01,1.33,4.13,0.15,0.15,
14.18,4290.14,26.8,5.33,17.58,14.29,248.5,
0.01,0,0,0,0,0,0,0.151395382,
5.327863403,5.10096383,1.32567787,4.352404124,
0.458606982,2.915908912,0.011996374,0.364710382,
0.033016026,3.161701212,0.381564497,0.010971385,
0.035646472,0.014781805,4.129708296,0.153094117,
0.018497847,15.09178491,17.58393041,14.17643928,
4290.143561,26.79730719,294.6367065,14.2888441,
248.495231,209.3131795,2014.506722,0.010751273,
0.002325138,0.000637473,0.003984336,0.006018154,
0.003620907,0.745936,0.000142311,0.002460417,
0.001280189)

Thank you very much for any help you could provide!
regards
Luigi

___

Re: [R] 3D Surface Plot

2013-12-19 Thread Adams, Jean
Check out the wireframe() function in the R package lattice ...

library(lattice)
?wireframe

Jean


On Wed, Dec 18, 2013 at 9:30 AM, Simon Delay-Fortier <
simon.delay-fort...@mail.mcgill.ca> wrote:

> Hi everyone,I am a very new user of r. I am now mandated to draw a 3-d
> surface (and possibly rotating) of a mine pit hole. I have all the location
> points (around 5000 points) of the pit in a CSV file under 3 column X, Y &
> Z. The fllowing gives a 3d scatter but i would like to have a surface.
>
> attach(EASTPITCREST)
> par(bg="grey6", col.lab="white", col.axis="white", col.main="white",
> col.sub="white")
> scatterplot3d(X, Y, Z, color = "red", pch=19, main="Mine and Drilling Map")
>
> I noted is that most of the time X and Y  have to be in ascending order
> but the data I have are not (since they are finite points of the pit, if X
> gets  in ascending order, Y and Z are not). Also with the data, sometimes 2
> rows fallowing each ohter have the same X and Y value with a different Z.
>
> Hope you can help.
> Sincerly,
>
> Simon Delay-Fortier
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] cure fraction model

2013-12-19 Thread L... L...
Dear all, is there an R function to simulate random observations from a cure 
fraction model (random observations with long-term survivos). 
Some references how can I do this will be welcome.

Best Regards
ML
[[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] Ternary plot and filled contour

2013-12-19 Thread Nicholas Hamilton
Dear Francesco, 

I wanted to mention that I have just published on CRAN, a package for R, 
for the plotting of ternary diagrams. 

It is based off ggplot2, which is highly regarded, and, my website can be 
viewed at www.ggtern.com, including many examples, specifically including a 
case study at the following address: 

http://ggtern.com/case-study-zirconia-alumina-silica/ 

Hope you find it of value. 

Best Regards, 

Nicholas Hamilton 
School of Materials Science and Engineering 
Univesity of New South Wales 
Sydney Australia 
-- 
www.ggtern.com 

On Monday, June 4, 2012 10:52:10 PM UTC+10, Francesco Nutini wrote:
>
>
> Dear R-Users, I'd like to have some tips for a ternaryplot ("vcd"). 
> I have this dataframe: 
> a<- c (0.1, 0.5, 0.5, 0.6, 0.2,0, 0, 0.00417, 0.45) 
> b<- c (0.75,0.5,0,0.1,0.2,0.951612903,0.918103448,0.7875,0.45)c<- c 
> (0.15,0,0.5,0.3,0.6,0.048387097,0.081896552,0.20833,0.1) d<- c 
> (500,2324.90,2551.44,1244.50, 551.22,-644.20,-377.17,-100, 2493.04) 
> df<- data.frame (a, b, c, d) 
> and I'm building a ternary plot: 
> ternaryplot(df[,1:3], df$d) 
> How can I map the continue variable "d", obtaining a result similar to 
> this one? [see the link] 
> > 
> http://www.pmel.noaa.gov/maillists/tmap/ferret_users/fu_2007/jpgCqrZqdDwYG.jpg
>  
> Many thanks! 
>
> 
> [[alternative HTML version deleted]] 
>
> __ 
> r-h...@r-project.org  mailing list 
> https://stat.ethz.ch/mailman/listinfo/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] Ternary plot and filled contour

2013-12-19 Thread Francesco Nutini
Nice job Nicholas!thanks for the e-mail.
Regards,
Francesco
---
Francesco Nutini
CNR-IREA
 Institute for Electromagnetic Sensing of the Environment
 Via Bassini 15, 20133 Milano (Italy) 
 Tel: +39-02 23699 297  
 www.irea.cnr.it 
 nutin...@irea.cnr.it
Skype: ui...@hotmail.it
Faculty of Agriculture of the University of Milan (UniMI)
 Di.Pro.Ve. - Department of Plant Production
 Univ. mail: 
francesco.nut...@unimi.it---

Date: Thu, 19 Dec 2013 06:45:04 -0800
From: nicholasehamil...@gmail.com
To: r-help-arch...@googlegroups.com
CC: r-help@r-project.org; nutini.france...@gmail.com
Subject: Re: [R] Ternary plot and filled contour

Dear Francesco, 

I wanted to mention that I have just published on CRAN, a package for R, for 
the plotting of ternary diagrams. 

It is based off ggplot2, which is highly regarded, and, my website can be 
viewed at www.ggtern.com, including many examples, specifically including a 
case study at the following address: 

http://ggtern.com/case-study-zirconia-alumina-silica/ 

Hope you find it of value. 

Best Regards, 

Nicholas Hamilton 
School of Materials Science and Engineering 
Univesity of New South Wales 
Sydney Australia 
-- 
www.ggtern.com 

On Monday, June 4, 2012 10:52:10 PM UTC+10, Francesco Nutini wrote:

Dear R-Users, I'd like to have some tips for a ternaryplot ("vcd").

I have this dataframe:

a<- c (0.1, 0.5, 0.5, 0.6, 0.2,0, 0, 0.00417, 0.45) b<- c 
(0.75,0.5,0,0.1,0.2,0.951612903,0.918103448,0.7875,0.45)c<- c 
(0.15,0,0.5,0.3,0.6,0.048387097,0.081896552,0.20833,0.1) d<- c 
(500,2324.90,2551.44,1244.50, 551.22,-644.20,-377.17,-100, 2493.04) df<- 
data.frame (a, b, c, d)

and I'm building a ternary plot:

ternaryplot(df[,1:3], df$d)

How can I map the continue variable "d", obtaining a result similar to this 
one? [see the link]

> http://www.pmel.noaa.gov/maillists/tmap/ferret_users/fu_2007/jpgCqrZqdDwYG.jpg

Many thanks!



   

[[alternative HTML version deleted]]



__

r-h...@r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/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] ternary contour plot

2013-12-19 Thread Nicholas Hamilton
Dear Walmes, 

I wanted to mention that I have just published on CRAN, a package for R, 
for the plotting of ternary diagrams. 

It is based off ggplot2, which is highly regarded, and, my website can be 
viewed at www.ggtern.com, including many examples, specifically including a 
case study at the following address: 

http://ggtern.com/case-study-zirconia-alumina-silica/ 

Hope you find it of value. 

Best Regards, 

Nicholas Hamilton 
School of Materials Science and Engineering 
Univesity of New South Wales 
Sydney Australia 
-- 
www.ggtern.com 

On Wednesday, February 16, 2011 2:42:43 AM UTC+11, Walmes Marques Zeviani 
wrote:
>
>
> Colin,
>
> If your propose is to create a ternary plot with points and vectors, I 
> think easier do this with graphics based plots instead of trellis based 
> plots. Although, with little work you can do with trellis too. I gave you a 
> reproducible code to put an arrow in a ternary plot. I use the function 
> locator() to extract coordinates. The code is the following
>
>
> #--
> # package and related documentaion
>
> require(plotrix)
> help.search("triax")
> help(triax.plot, html=TRUE)
>
>
> #--
> # toy data
>
> data(soils)
> str(soils)
>
>
> #--
> # creating a ternary plot
>
> triax.plot(soils[1:10,], main="DEFAULT")
>
>
> #--
> # extracting coodinates by mouse click on the plot (cartesian coordinates, 
> x  and y axis)
>
> id <- locator(n=2) # click on the plot to extract 2 coodinates
>
>
> #--
> # draw an arrow with the coordinates extracted
>
> arrows(id$x[1], id$y[1], id$x[2], id$y[2])
>
>
> #--
>
> At your disposal.
> Walmes.
>
> 
>
>
> Walmes Marques Zeviani
>
>
> LEG (Laboratório de Estatística e Geoinformação)
>
>
> Departamento de Estatística - Universidade Federal do Paraná
>
>
> fone: (+55) 41 3361 3573
>
>
> VoIP: (3361 3600) 1053 1173
>
>
> e-mail: wal...@ufpr.br  / @walmeszeviani
>
>
> homepage: http://www.leg.ufpr.br/~walmes
>
>
> 
>
>
> > Date: Mon, 14 Feb 2011 20:05:54 +
> > From: colin...@bristol.ac.uk 
> > To: walmes...@hotmail.com 
> > Subject: ternary contour plot
> > 
> > Dear Walmes,
> > 
> > Firstly, thank you for distributing your ternary contour plot code.
> > 
> > could I ask you a question about it, hopefully you will be able to 
> > answer it quite simply and so save me some time trying to work out what 
> > it is that the function is actually doing.
> > 
> > Essentially I wish to overlay points and vectors onto the ternary 
> > contour plot. Now can I do this by:
> > 
> > a): extracting the adjusted x y coordinates and using it with triax.fill
> > 
> > or
> > 
> > b) can I plot my vectors (arrows) and points onto the grid that is 
> > created by levelplot.ternary
> > 
> > if either or both are true do you know how I would go about a) 
> > extracting or b) inputing the relevent data?
> > 
> > I would be grateful for your advice,
> > 
> > best regards,
> > 
> > colin
> > 
> > -- 
> > 
> **
> > 
> **
> > 
> > Dr Colin Bleay
> > Station d'Ecologie Experimentale du CNRS,
> > 09200 Moulis,
> > France.
> > 
> > Tel: +33 5 61 04 03 61
> > Fax: +33 5 61 96 08 51
> > email: colin...@ecoex-moulis.cnrs.fr 
> > Webpage: http://www.ecoex-moulis.cnrs.fr/Staffpages/ColinBleay.htm
> > 
>
> [[alternative HTML version deleted]]
>
>__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ternary contour plot

2013-12-19 Thread Cleber N.Borges
hello,
i make here my suggeestion of a Ternary Plot as a RSM.
cleber




trimage <- function(f){
[[elided Yahoo spam]]
t1 = length(x)
im = aux = numeric(0)
for( i in seq( 1, t1, by = 2 ) ){
 #idx = seq( t1**2, i*t1, by = -t1 ) - ((t1 - i):0)
 idx = seq( i*t1, t1**2, by = t1 ) - (i-1)
 im = c(im, aux, idx, aux )
 aux = c(aux, NA)
 }
z =  outer(X=x, Y=y, FUN=f)
return( matrix(z[im],nr=t1) )
}
##

# dataset of mail: Francesco --- june,4

a <- c(0.1, 0.5, 0.5, 0.6, 0.2,0, 0, 0.00417, 0.45)
b <- c(0.75,0.5,0,0.1,0.2,0.951612903,0.918103448,0.7875,0.45)
c <- c(0.15,0,0.5,0.3,0.6,0.048387097,0.081896552,0.20833,0.1)
d <- c(500,2324.90,2551.44,1244.50, 551.22,-644.20,-377.17,-100, 2493.04)
df<- data.frame (a, b, c, d)

reg <- lm( d ~ -1 + a*b*c )
mod <- gsub(":","*", paste( coef(reg), '*', names(coef(reg)), collapse=' 
+ '))

spf <- function( a,b,c ){eval(parse(text=mod))}
f1 <- function(a,b){ c=1-a-b; return( spf(a,b,c) ) }
zmat <- trimage(f1)

windows(w=4.5, h=4.5)
par(mar=c(0,0,0,0), pty='s', xaxt='n', yaxt='n', bty='n' )
image(zmat)










Em 19/12/2013 13:38, Nicholas Hamilton escreveu:
> Dear Walmes,
>
> I wanted to mention that I have just published on CRAN, a package for R,
> for the plotting of ternary diagrams.
>
> It is based off ggplot2, which is highly regarded, and, my website can be
> viewed at www.ggtern.com, including many examples, specifically including a
> case study at the following address:
>
> http://ggtern.com/case-study-zirconia-alumina-silica/
>
> Hope you find it of value.
>
> Best Regards,
>
> Nicholas Hamilton
> School of Materials Science and Engineering
> Univesity of New South Wales
> Sydney Australia
>
>


[[alternative HTML version deleted]]

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


Re: [R] read ".slk" file

2013-12-19 Thread David Winsemius

On Dec 16, 2013, at 3:10 PM, Santosh wrote:

> Dear Rxperts..
> 
> I recently received a data file with the extension ".slk". If I save the
> file as MS Excel file, I am able to read in R without issues.  Is it
> possible to read this ".slk" file without converting into another
> R-readable data format?

Reading this I wondered if you could use sep=";" with read.* functions.
http://en.wikipedia.org/wiki/SYmbolic_LinK_%28SYLK%29

That is NOT going to give you a neat dataframe, but you didn't make your goals 
very clear so it seems possible that you might get what you needed from some 
selected input lines.

-- 
David Winsemius
Alameda, CA, USA

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


Re: [R] cure fraction model

2013-12-19 Thread David Winsemius

On Dec 19, 2013, at 5:32 AM, L... L... wrote:

> Dear all, is there an R function to simulate random observations from a cure 
> fraction model (random observations with long-term survivos). 
> Some references how can I do this will be welcome.
> 
Shouldn't be too hard to set up a mixture of weibull distributed event times 
with one component having a parameter less than "exponential" (to represent the 
cured fraction with survival typical of an average human population) and 
another with a hazard like an "exponential" or worse to represent the non-cured 
fraction. Watch out about how the shape parameters are defined. The survival 
package uses different parameterization than the rweibull definitions.

library(survival)
?survreg
?rweibull

-- 

David Winsemius
Alameda, CA, USA

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


[R] creating list of variables description

2013-12-19 Thread C Lin
Dear R-users,

Can someone suggest a good way to keep a list of variables description in R? 
Something to provide more detailed information on the variables that I have.
Kind of like this list: 
http://www.thearda.com/pals/researchers/VARIABLE_DESCRIPT_LIST%20-%20public.pdfI'd
 like to be able to output the variable list in a nice format.Thank you.



  
[[alternative HTML version deleted]]

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


Re: [R] Using assign with mapply

2013-12-19 Thread Julio Sergio Santana
Greg Snow <538280  gmail.com> writes:

> 
> The take home message that you should be learning from your struggles
> is to "Not Use The 'assign' Function!" and "Do Not Use Global
> Variables Like This".
> 
> R has lists (and environments) that make working with objects that are
> associated with each other much simpler and fits better with the
> functional programming style of R.
> 

Thanks, Greg!

Yours is a very smart solution to the problem I posed. 

By the way, what I'm trying to do is reading from a file a set of user given 
parameters, in two paired columns: parameter-name, value; and then, managing 
these parameters inside my R program. Now I do understand a bit more about 
lists. What about environments? Are they similar to lists, and when, and how 
are they created?

Best regrards,

  -Sergio.

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


Re: [R] creating list of variables description

2013-12-19 Thread C Lin
Sorry the link should be this 
one:http://www.thearda.com/pals/researchers/VARIABLE_DESCRIPT_LIST%20-%20public.pdf

> From: bac...@hotmail.com
> To: r-help@r-project.org
> Date: Thu, 19 Dec 2013 13:20:54 -0500
> Subject: [R] creating list of variables description
> 
> Dear R-users,
> 
> Can someone suggest a good way to keep a list of variables description in R? 
> Something to provide more detailed information on the variables that I have.
> Kind of like this list: 
> http://www.thearda.com/pals/researchers/VARIABLE_DESCRIPT_LIST%20-%20public.pdfI'd
>  like to be able to output the variable list in a nice format.Thank you.
> 
> 
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
  
[[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] Inconsistent computation of an integral

2013-12-19 Thread Aurélien Philippot
Dear R experts,
I computed the same integral in two different ways, and find different
values in R.
The difference is due to the max function that is part of the integrand. In
the first case, I keep it as such, in the second case, I split it in two
depending on the values of the variable of integration.

1) First computation

# Function g
g<-
function(x){1/(x*0.20*sqrt(10)*sqrt(2*pi))*exp(-0.5*((log(x/50)-0.1*10)/(0.20*sqrt(10)))^2)}

### Function f1
f1<- function(x) {1/(500+10*x+1*max(x-50,0))}

integrand1<- function(x) {
  out<- f1(x)*g(x)
  return(out)
}

i2<- integrate(integrand1, lower=0, upper=Inf )$value

It gives me: i2=  3.819418e-08

2) Second computation
I break the max function in two, depending on the values of the variable of
integration x (and I use the same density g as before):

f11<- function(x) {1/(500+10*x)}
f12<- function(x) {1/(500+10*x+1*(x-50))}


integrand11<- function(x) {
  out<- f11(x)*g(x)
  return(out)
}

integrand12<- function(x) {
  out<- f12(x)*g(x)
  return(out)
}


i21<- integrate(integrand11, lower=0, upper=50 )$value
+integrate(integrand12, lower=50, upper=Inf)$value

I get i21=5.239735e-08

The difference makes a huge difference for the computations I do. Does
anyone know where it comes from?
Thanks in advance!

[[alternative HTML version deleted]]

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


Re: [R] Help using mapply to run multiple models

2013-12-19 Thread Simon Kiss
Hello Bill, that is fantastic and it's quite a bit above what I could write. Is 
there a way to make the model type an argument to the function so that you can 
specify whether one is running glm, lm and such? 
I tried to modify it by inserting an argument modelType below, but that doesn't 
work.
Yours, simon Kiss
>  f <- function (modelType, responseName, predictorNames, data, ..., envir = 
> parent.frame())
>{
>call <- match.call()
>call$formula <- formula(envir = envir, paste(responseName, sep = " ~ ",
>paste0("`", predictorNames, "`", collapse = " + ")))
>call[[1]] <- quote(modelType) # '
>call$responseName <- NULL # omit responseName=
>call$predictorNames <- NULL # omit 'predictorNames='
>eval(call, envir = envir)
>}
On 2013-12-18, at 3:07 PM, William Dunlap  wrote:

>  f <- function (responseName, predictorNames, data, ..., envir = 
> parent.frame())
>{
>call <- match.call()
>call$formula <- formula(envir = envir, paste(responseName, sep = " ~ ",
>paste0("`", predictorNames, "`", collapse = " + ")))
>call[[1]] <- quote(glm) # 'f' -> 'glm'
>call$responseName <- NULL # omit responseName=
>call$predictorNames <- NULL # omit 'predictorNames='
>eval(call, envir = envir)
>}
> as in
>z <- lapply(list(c("hp","drat"), c("cyl"), c("am","gear")), 
> FUN=function(preds)f("carb", preds, data=mtcars, family=poisson))
>lapply(z, summary)

*
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9
Cell: +1 905 746 7606

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


Re: [R] creating list of variables description

2013-12-19 Thread David Winsemius

On Dec 19, 2013, at 10:20 AM, C Lin wrote:

> Dear R-users,
> 
> Can someone suggest a good way to keep a list of variables description in R? 
> Something to provide more detailed information on the variables that I have.
> Kind of like this list: 
> http://www.thearda.com/pals/researchers/VARIABLE_DESCRIPT_LIST%20-%20public.pdfI'd
>  like to be able to output the variable list in a nice format.Thank you.

Do an RSiteSearch on "codebook" (Or use:

sos::findFn("codebook")

...  and look at the Hmisc package that does record variable descriptions from 
external datasets with some of its methods that import from SAS or SPSS files 
when they contain such information. 

help(package="Hmisc")

# especially
sas.codes   Convert a SAS Dataset to an S Data Frame
sas.get Convert a SAS Dataset to an S Data Frame
sasdsLabels Enhanced Importing of SAS Transport Files using read.xport
sasxport.getEnhanced Importing of SAS Transport Files using read.xport

spss.getEnhanced Importing of SPSS Files

> 
>   [[alternative HTML version deleted]]
And do learn to post in plain text:


David Winsemius
Alameda, CA, USA

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


[R] A function which is a sum of other functions...

2013-12-19 Thread Onur Uncu

Dear R Users

I have a list of functions. Each function in the list is a function of single 
variable. I would like to create a function (of one variable) which represents 
the sum of all the functions in the list. So, if the functions in my list are 
f1(x),..,f5(x) then I would like a new function f(x)=f1(x)+f2(x)+...f5(x)

Appreciate any suggestions on how to do this. 

I need the above f(x) function because I would like to minimise it with respect 
to x using the nlm function.

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] Inconsistent computation of an integral

2013-12-19 Thread William Dunlap
I think you want to use pmax(x-50, 0), which returns a vector
the length of x, instead of max(x-50,0), which returns a scalar.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of Aurélien Philippot
> Sent: Thursday, December 19, 2013 10:38 AM
> To: R-help@r-project.org
> Subject: [R] Inconsistent computation of an integral
> 
> Dear R experts,
> I computed the same integral in two different ways, and find different
> values in R.
> The difference is due to the max function that is part of the integrand. In
> the first case, I keep it as such, in the second case, I split it in two
> depending on the values of the variable of integration.
> 
> 1) First computation
> 
> # Function g
> g<-
> function(x){1/(x*0.20*sqrt(10)*sqrt(2*pi))*exp(-0.5*((log(x/50)-
> 0.1*10)/(0.20*sqrt(10)))^2)}
> 
> ### Function f1
> f1<- function(x) {1/(500+10*x+1*max(x-50,0))}
> 
> integrand1<- function(x) {
>   out<- f1(x)*g(x)
>   return(out)
> }
> 
> i2<- integrate(integrand1, lower=0, upper=Inf )$value
> 
> It gives me: i2=  3.819418e-08
> 
> 2) Second computation
> I break the max function in two, depending on the values of the variable of
> integration x (and I use the same density g as before):
> 
> f11<- function(x) {1/(500+10*x)}
> f12<- function(x) {1/(500+10*x+1*(x-50))}
> 
> 
> integrand11<- function(x) {
>   out<- f11(x)*g(x)
>   return(out)
> }
> 
> integrand12<- function(x) {
>   out<- f12(x)*g(x)
>   return(out)
> }
> 
> 
> i21<- integrate(integrand11, lower=0, upper=50 )$value
> +integrate(integrand12, lower=50, upper=Inf)$value
> 
> I get i21=5.239735e-08
> 
> The difference makes a huge difference for the computations I do. Does
> anyone know where it comes from?
> Thanks in advance!
> 
>   [[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] Help using mapply to run multiple models

2013-12-19 Thread William Dunlap
> >call[[1]] <- quote(modelType) # '

makes call[[1]] the same as as.name("modelType").  You want
as.name(modelType).

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: Simon Kiss [mailto:sjk...@gmail.com]
> Sent: Thursday, December 19, 2013 10:56 AM
> To: William Dunlap
> Cc: Dennis Murphy; r-help@r-project.org
> Subject: Re: [R] Help using mapply to run multiple models
> 
> Hello Bill, that is fantastic and it's quite a bit above what I could write. 
> Is there a way to
> make the model type an argument to the function so that you can specify 
> whether one is
> running glm, lm and such?
> I tried to modify it by inserting an argument modelType below, but that 
> doesn't work.
> Yours, simon Kiss
> >  f <- function (modelType, responseName, predictorNames, data, ..., envir =
> parent.frame())
> >{
> >call <- match.call()
> >call$formula <- formula(envir = envir, paste(responseName, sep = " ~ 
> > ",
> >paste0("`", predictorNames, "`", collapse = " + ")))
> >call[[1]] <- quote(modelType) # '
> >call$responseName <- NULL # omit responseName=
> >call$predictorNames <- NULL # omit 'predictorNames='
> >eval(call, envir = envir)
> >}
> On 2013-12-18, at 3:07 PM, William Dunlap  wrote:
> 
> >  f <- function (responseName, predictorNames, data, ..., envir = 
> > parent.frame())
> >{
> >call <- match.call()
> >call$formula <- formula(envir = envir, paste(responseName, sep = " ~ 
> > ",
> >paste0("`", predictorNames, "`", collapse = " + ")))
> >call[[1]] <- quote(glm) # 'f' -> 'glm'
> >call$responseName <- NULL # omit responseName=
> >call$predictorNames <- NULL # omit 'predictorNames='
> >eval(call, envir = envir)
> >}
> > as in
> >z <- lapply(list(c("hp","drat"), c("cyl"), c("am","gear")), 
> > FUN=function(preds)f("carb",
> preds, data=mtcars, family=poisson))
> >lapply(z, summary)
> 
> *
> Simon J. Kiss, PhD
> Assistant Professor, Wilfrid Laurier University
> 73 George Street
> Brantford, Ontario, Canada
> N3T 2C9
> Cell: +1 905 746 7606
> 
> 

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


Re: [R] Help using mapply to run multiple models

2013-12-19 Thread David Winsemius

On Dec 19, 2013, at 11:10 AM, William Dunlap wrote:

>>>   call[[1]] <- quote(modelType) # '
> 
> makes call[[1]] the same as as.name("modelType").  You want
> as.name(modelType).

Just so I can see if I understand ... that is because `as.name` will evaluate 
`modelType` whereas as.name("modelType") would look for the function 
`modelType` and not find such a name in the namespace? So modelType needs to be 
a language-object and `f` needs to be called with:

f(glm, ) rather than f("glm", ...)


> 
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
> 
> 
>> -Original Message-
>> From: Simon Kiss [mailto:sjk...@gmail.com]
>> Sent: Thursday, December 19, 2013 10:56 AM
>> To: William Dunlap
>> Cc: Dennis Murphy; r-help@r-project.org
>> Subject: Re: [R] Help using mapply to run multiple models
>> 
>> Hello Bill, that is fantastic and it's quite a bit above what I could write. 
>> Is there a way to
>> make the model type an argument to the function so that you can specify 
>> whether one is
>> running glm, lm and such?
>> I tried to modify it by inserting an argument modelType below, but that 
>> doesn't work.
>> Yours, simon Kiss
>>> f <- function (modelType, responseName, predictorNames, data, ..., envir =
>> parent.frame())
>>>   {
>>>   call <- match.call()
>>>   call$formula <- formula(envir = envir, paste(responseName, sep = " ~ 
>>> ",
>>>   paste0("`", predictorNames, "`", collapse = " + ")))
>>>   call[[1]] <- quote(modelType) # '
>>>   call$responseName <- NULL # omit responseName=
>>>   call$predictorNames <- NULL # omit 'predictorNames='
>>>   eval(call, envir = envir)
>>>   }
>> On 2013-12-18, at 3:07 PM, William Dunlap  wrote:
>> 
>>> f <- function (responseName, predictorNames, data, ..., envir = 
>>> parent.frame())
>>>   {
>>>   call <- match.call()
>>>   call$formula <- formula(envir = envir, paste(responseName, sep = " ~ 
>>> ",
>>>   paste0("`", predictorNames, "`", collapse = " + ")))
>>>   call[[1]] <- quote(glm) # 'f' -> 'glm'
>>>   call$responseName <- NULL # omit responseName=
>>>   call$predictorNames <- NULL # omit 'predictorNames='
>>>   eval(call, envir = envir)
>>>   }
>>> as in
>>>   z <- lapply(list(c("hp","drat"), c("cyl"), c("am","gear")), 
>>> FUN=function(preds)f("carb",
>> preds, data=mtcars, family=poisson))
>>>   lapply(z, summary)
>> 
>> *
>> Simon J. Kiss, PhD
>> Assistant Professor, Wilfrid Laurier University
>> 73 George Street
>> Brantford, Ontario, Canada
>> N3T 2C9
>> Cell: +1 905 746 7606
>> 
>> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
Alameda, CA, USA

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


Re: [R] A function which is a sum of other functions...

2013-12-19 Thread David Winsemius

On Dec 19, 2013, at 11:05 AM, Onur Uncu wrote:

> 
> Dear R Users
> 
> I have a list of functions. Each function in the list is a function of single 
> variable. I would like to create a function (of one variable) which 
> represents the sum of all the functions in the list. So, if the functions in 
> my list are f1(x),..,f5(x) then I would like a new function 
> f(x)=f1(x)+f2(x)+...f5(x)
> 
> Appreciate any suggestions on how to do this. 
> 
> I need the above f(x) function because I would like to minimise it with 
> respect to x using the nlm function.

> fbig <- function(x, f1=I, f2=I, f3=I, f4=I, f5=I){
  f1(x)+f2(x)+f3(x)+f4(x)+f5(x)}
> fbig(2)
[1] 10
> fbig(2, exp)
[1] 15.38906

> fbig(2, exp, log)
[1] 14.0822

Since "+" is vectorized this should not need to be wrapped in sapply as long as 
each function is itself vectorized.


David Winsemius
Alameda, CA, USA

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


Re: [R] A function which is a sum of other functions...

2013-12-19 Thread William Dunlap
> List <- list(abs, function(x)x*10, function(x)x*100)
> f <- function(x)Reduce(`+`, lapply(List, function(func)func(x)))
> f(-1:2)
[1] -1090  111  222

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of Onur Uncu
> Sent: Thursday, December 19, 2013 11:05 AM
> To: r-help@r-project.org
> Subject: [R] A function which is a sum of other functions...
> 
> 
> Dear R Users
> 
> I have a list of functions. Each function in the list is a function of single 
> variable. I would
> like to create a function (of one variable) which represents the sum of all 
> the functions in
> the list. So, if the functions in my list are f1(x),..,f5(x) then I would 
> like a new function
> f(x)=f1(x)+f2(x)+...f5(x)
> 
> Appreciate any suggestions on how to do this.
> 
> I need the above f(x) function because I would like to minimise it with 
> respect to x using
> the nlm function.
> 
> Thanks.
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Help using mapply to run multiple models

2013-12-19 Thread David Winsemius

On Dec 19, 2013, at 11:30 AM, David Winsemius wrote:

> 
> On Dec 19, 2013, at 11:10 AM, William Dunlap wrote:
> 
  call[[1]] <- quote(modelType) # '
>> 
>> makes call[[1]] the same as as.name("modelType").  You want
>> as.name(modelType).
> 
> Just so I can see if I understand ... that is because `as.name` will evaluate 
> `modelType` whereas as.name("modelType") would look for the function 
> `modelType` and not find such a name in the namespace? So modelType needs to 
> be a language-object and `f` needs to be called with:
> 
> f(glm, ) rather than f("glm", ...)

Reading `?as.name` (again) I've decided that must be wrong. either one should 
return the same value if teh argument is first converted to a character value.

-- 
David.
> 
> 
>> 
>> Bill Dunlap
>> Spotfire, TIBCO Software
>> wdunlap tibco.com
>> 
>> 
>>> -Original Message-
>>> From: Simon Kiss [mailto:sjk...@gmail.com]
>>> Sent: Thursday, December 19, 2013 10:56 AM
>>> To: William Dunlap
>>> Cc: Dennis Murphy; r-help@r-project.org
>>> Subject: Re: [R] Help using mapply to run multiple models
>>> 
>>> Hello Bill, that is fantastic and it's quite a bit above what I could 
>>> write. Is there a way to
>>> make the model type an argument to the function so that you can specify 
>>> whether one is
>>> running glm, lm and such?
>>> I tried to modify it by inserting an argument modelType below, but that 
>>> doesn't work.
>>> Yours, simon Kiss
 f <- function (modelType, responseName, predictorNames, data, ..., envir =
>>> parent.frame())
  {
  call <- match.call()
  call$formula <- formula(envir = envir, paste(responseName, sep = " ~ 
 ",
  paste0("`", predictorNames, "`", collapse = " + ")))
  call[[1]] <- quote(modelType) # '
  call$responseName <- NULL # omit responseName=
  call$predictorNames <- NULL # omit 'predictorNames='
  eval(call, envir = envir)
  }
>>> On 2013-12-18, at 3:07 PM, William Dunlap  wrote:
>>> 
 f <- function (responseName, predictorNames, data, ..., envir = 
 parent.frame())
  {
  call <- match.call()
  call$formula <- formula(envir = envir, paste(responseName, sep = " ~ 
 ",
  paste0("`", predictorNames, "`", collapse = " + ")))
  call[[1]] <- quote(glm) # 'f' -> 'glm'
  call$responseName <- NULL # omit responseName=
  call$predictorNames <- NULL # omit 'predictorNames='
  eval(call, envir = envir)
  }
 as in
  z <- lapply(list(c("hp","drat"), c("cyl"), c("am","gear")), 
 FUN=function(preds)f("carb",
>>> preds, data=mtcars, family=poisson))
  lapply(z, summary)
>>> 

David Winsemius
Alameda, CA, USA

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


Re: [R] Help using mapply to run multiple models

2013-12-19 Thread William Dunlap
> Just so I can see if I understand ... that is because `as.name` will evaluate 
> `modelType`
> whereas as.name("modelType") would look for the function `modelType` and not 
> find
> such a name in the namespace? 

Almost.  as.name(modelType) will evaluate modelType so modelType could be a
character string or a name.   as.name itself does not do any lookups - that is 
eval's job.
When eval() is given a name object it looks it up.

> So modelType needs to be a language-object and `f`
> needs to be called with:
> 
> f(glm, ) rather than f("glm", ...)

If you use as.name(modelType) then you could call f("glm",...).

f(glm, ...) does not pass a name into the function f, it passes in the object
named "glm" (usually the function in package:stats by that name).
as.name(glm) returns garbage.  If you wanted to be able to call
   f(glm, predictors, response)
you could just use
   call[[1]] <- modelType
in f().  I didn't recommend that because then the call attributes of glm's 
output
does not look nice.  You can write code so that both f("glm",...) and 
f(glm,...) work
but I usually prefer not to load up functions with so much heuristic argument
processing (e.g., how should it deal with 'func<-"glm" ; f(func,...)' and the 
like).

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: David Winsemius [mailto:dwinsem...@comcast.net]
> Sent: Thursday, December 19, 2013 11:31 AM
> To: William Dunlap
> Cc: Simon Kiss; r-help@r-project.org
> Subject: Re: [R] Help using mapply to run multiple models
> 
> 
> On Dec 19, 2013, at 11:10 AM, William Dunlap wrote:
> 
> >>>   call[[1]] <- quote(modelType) # '
> >
> > makes call[[1]] the same as as.name("modelType").  You want
> > as.name(modelType).
> 
> Just so I can see if I understand ... that is because `as.name` will evaluate 
> `modelType`
> whereas as.name("modelType") would look for the function `modelType` and not 
> find
> such a name in the namespace? So modelType needs to be a language-object and 
> `f`
> needs to be called with:
> 
> f(glm, ) rather than f("glm", ...)
> 
> 
> >
> > Bill Dunlap
> > Spotfire, TIBCO Software
> > wdunlap tibco.com
> >
> >
> >> -Original Message-
> >> From: Simon Kiss [mailto:sjk...@gmail.com]
> >> Sent: Thursday, December 19, 2013 10:56 AM
> >> To: William Dunlap
> >> Cc: Dennis Murphy; r-help@r-project.org
> >> Subject: Re: [R] Help using mapply to run multiple models
> >>
> >> Hello Bill, that is fantastic and it's quite a bit above what I could 
> >> write. Is there a way
> to
> >> make the model type an argument to the function so that you can specify 
> >> whether
> one is
> >> running glm, lm and such?
> >> I tried to modify it by inserting an argument modelType below, but that 
> >> doesn't work.
> >> Yours, simon Kiss
> >>> f <- function (modelType, responseName, predictorNames, data, ..., envir =
> >> parent.frame())
> >>>   {
> >>>   call <- match.call()
> >>>   call$formula <- formula(envir = envir, paste(responseName, sep = " 
> >>> ~ ",
> >>>   paste0("`", predictorNames, "`", collapse = " + ")))
> >>>   call[[1]] <- quote(modelType) # '
> >>>   call$responseName <- NULL # omit responseName=
> >>>   call$predictorNames <- NULL # omit 'predictorNames='
> >>>   eval(call, envir = envir)
> >>>   }
> >> On 2013-12-18, at 3:07 PM, William Dunlap  wrote:
> >>
> >>> f <- function (responseName, predictorNames, data, ..., envir = 
> >>> parent.frame())
> >>>   {
> >>>   call <- match.call()
> >>>   call$formula <- formula(envir = envir, paste(responseName, sep = " 
> >>> ~ ",
> >>>   paste0("`", predictorNames, "`", collapse = " + ")))
> >>>   call[[1]] <- quote(glm) # 'f' -> 'glm'
> >>>   call$responseName <- NULL # omit responseName=
> >>>   call$predictorNames <- NULL # omit 'predictorNames='
> >>>   eval(call, envir = envir)
> >>>   }
> >>> as in
> >>>   z <- lapply(list(c("hp","drat"), c("cyl"), c("am","gear")), 
> >>> FUN=function(preds)f("carb",
> >> preds, data=mtcars, family=poisson))
> >>>   lapply(z, summary)
> >>
> >> *
> >> Simon J. Kiss, PhD
> >> Assistant Professor, Wilfrid Laurier University
> >> 73 George Street
> >> Brantford, Ontario, Canada
> >> N3T 2C9
> >> Cell: +1 905 746 7606
> >>
> >>
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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
> Alameda, CA, USA

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


Re: [R] A function which is a sum of other functions...

2013-12-19 Thread William Dunlap
> >> List <- list(abs, function(x)x*10, function(x)x*100)
> >> f <- function(x)Reduce(`+`, lapply(List, function(func)func(x)))
> >> f(-1:2)
> > [1] -1090  111  222

In that formulation lapply() applies each function in List to x, returning a 
list of vectors
containing the results (run it outside of Reduce to see this).  Reduce then 
adds those vectors together.

You can have Reduce evaluate the functions in List and sum the results without 
using
lapply.  This saves the memory it would take to have all the result vectors in 
memory
at once, but I find the syntax hard to remember.  
   > g <- function(x)Reduce(function(runningSum, func)runningSum + func(x), 
List[-1], init=List[[1]](x))
   > g(-1:2)
   [1] -1090  111  222

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: Onur Uncu [mailto:onuru...@gmail.com]
> Sent: Thursday, December 19, 2013 11:43 AM
> To: William Dunlap
> Subject: Re: [R] A function which is a sum of other functions...
> 
> Thanks William. May I please ask why we needed to use lapply inside Reduce? 
> It sounds
> like we took a list of functions and recreated the same list using lapply. So 
> I couldnt
> follow why we did that...
> 
> Sent from my iPhone
> 
> On 19 Dec 2013, at 19:23, William Dunlap  wrote:
> 
> >> List <- list(abs, function(x)x*10, function(x)x*100)
> >> f <- function(x)Reduce(`+`, lapply(List, function(func)func(x)))
> >> f(-1:2)
> > [1] -1090  111  222
> >
> > Bill Dunlap
> > Spotfire, TIBCO Software
> > wdunlap tibco.com
> >
> >
> >> -Original Message-
> >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> >> Of Onur Uncu
> >> Sent: Thursday, December 19, 2013 11:05 AM
> >> To: r-help@r-project.org
> >> Subject: [R] A function which is a sum of other functions...
> >>
> >>
> >> Dear R Users
> >>
> >> I have a list of functions. Each function in the list is a function of 
> >> single variable. I
> would
> >> like to create a function (of one variable) which represents the sum of 
> >> all the functions
> in
> >> the list. So, if the functions in my list are f1(x),..,f5(x) then I would 
> >> like a new function
> >> f(x)=f1(x)+f2(x)+...f5(x)
> >>
> >> Appreciate any suggestions on how to do this.
> >>
> >> I need the above f(x) function because I would like to minimise it with 
> >> respect to x
> using
> >> the nlm function.
> >>
> >> Thanks.
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide 
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Help using mapply to run multiple models

2013-12-19 Thread David Winsemius

On Dec 19, 2013, at 11:45 AM, William Dunlap wrote:

>> Just so I can see if I understand ... that is because `as.name` will 
>> evaluate `modelType`
>> whereas as.name("modelType") would look for the function `modelType` and not 
>> find
>> such a name in the namespace? 
> 
> Almost.  as.name(modelType) will evaluate modelType so modelType could be a
> character string or a name.   as.name itself does not do any lookups - that 
> is eval's job.
> When eval() is given a name object it looks it up.
> 
>> So modelType needs to be a language-object and `f`
>> needs to be called with:
>> 
>> f(glm, ) rather than f("glm", ...)
> 
> If you use as.name(modelType) then you could call f("glm",...).
> 
> f(glm, ...) does not pass a name into the function f, it passes in the object
> named "glm" (usually the function in package:stats by that name).
> as.name(glm) returns garbage.  If you wanted to be able to call
>   f(glm, predictors, response)
> you could just use
>   call[[1]] <- modelType
> in f().  I didn't recommend that because then the call attributes of glm's 
> output
> does not look nice.  You can write code so that both f("glm",...) and 
> f(glm,...) work
> but I usually prefer not to load up functions with so much heuristic argument
> processing (e.g., how should it deal with 'func<-"glm" ; f(func,...)' and the 
> like).

So by the time the function `f` "saw" its arguments from a call:  `f(glm, ...) 
`, the name of the function would already have been removed and you would just 
be getting the argument list attached to the function body and as.name() would 
make a hash of it  as we saw in the original portion of this question.


> 
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
> 
> 
>> -Original Message-
>> From: David Winsemius [mailto:dwinsem...@comcast.net]
>> Sent: Thursday, December 19, 2013 11:31 AM
>> To: William Dunlap
>> Cc: Simon Kiss; r-help@r-project.org
>> Subject: Re: [R] Help using mapply to run multiple models
>> 
>> 
>> On Dec 19, 2013, at 11:10 AM, William Dunlap wrote:
>> 
>  call[[1]] <- quote(modelType) # '
>>> 
>>> makes call[[1]] the same as as.name("modelType").  You want
>>> as.name(modelType).
>> 
>> Just so I can see if I understand ... that is because `as.name` will 
>> evaluate `modelType`
>> whereas as.name("modelType") would look for the function `modelType` and not 
>> find
>> such a name in the namespace? So modelType needs to be a language-object and 
>> `f`
>> needs to be called with:
>> 
>> f(glm, ) rather than f("glm", ...)
>> 
>> 
>>> 
>>> Bill Dunlap
>>> Spotfire, TIBCO Software
>>> wdunlap tibco.com
>>> 
>>> 
 -Original Message-
 From: Simon Kiss [mailto:sjk...@gmail.com]
 Sent: Thursday, December 19, 2013 10:56 AM
 To: William Dunlap
 Cc: Dennis Murphy; r-help@r-project.org
 Subject: Re: [R] Help using mapply to run multiple models
 
 Hello Bill, that is fantastic and it's quite a bit above what I could 
 write. Is there a way
>> to
 make the model type an argument to the function so that you can specify 
 whether
>> one is
 running glm, lm and such?
 I tried to modify it by inserting an argument modelType below, but that 
 doesn't work.
 Yours, simon Kiss
> f <- function (modelType, responseName, predictorNames, data, ..., envir =
 parent.frame())
>  {
>  call <- match.call()
>  call$formula <- formula(envir = envir, paste(responseName, sep = " ~ 
> ",
>  paste0("`", predictorNames, "`", collapse = " + ")))
>  call[[1]] <- quote(modelType) # '
>  call$responseName <- NULL # omit responseName=
>  call$predictorNames <- NULL # omit 'predictorNames='
>  eval(call, envir = envir)
>  }
 On 2013-12-18, at 3:07 PM, William Dunlap  wrote:
 
> f <- function (responseName, predictorNames, data, ..., envir = 
> parent.frame())
>  {
>  call <- match.call()
>  call$formula <- formula(envir = envir, paste(responseName, sep = " ~ 
> ",
>  paste0("`", predictorNames, "`", collapse = " + ")))
>  call[[1]] <- quote(glm) # 'f' -> 'glm'
>  call$responseName <- NULL # omit responseName=
>  call$predictorNames <- NULL # omit 'predictorNames='
>  eval(call, envir = envir)
>  }
> as in
>  z <- lapply(list(c("hp","drat"), c("cyl"), c("am","gear")), 
> FUN=function(preds)f("carb",
 preds, data=mtcars, family=poisson))
>  lapply(z, summary)
 
 *
 Simon J. Kiss, PhD
 Assistant Professor, Wilfrid Laurier University
 73 George Street
 Brantford, Ontario, Canada
 N3T 2C9
 Cell: +1 905 746 7606
 
 
>>> 
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-pr

[R] pixel based percentile among rasters

2013-12-19 Thread Parks, Sean -FS
Hi,

Say I have 1000 rasters, or a raster stack composed of 1000 rasters.

I am interested in knowing the percentile for each pixel among these 1000 
rasters.

The result would be 1000 rasters, each depicting the percentile value of each 
pixel among the 1000 original rasters.

Can anyone please offer suggestions on how to accomplish this task?

Thanks for your help,
Sean






This electronic message contains information generated by the USDA solely for 
the intended recipients. Any unauthorized interception of this message or the 
use or disclosure of the information it contains may violate the law and 
subject the violator to civil or criminal penalties. If you believe you have 
received this message in error, please notify the sender and delete the email 
immediately.

[[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] multicore and mclapply problem in calculation server

2013-12-19 Thread p_connolly

On Wed, 18-Dec-2013 at 09:28AM +0100, Juan Antonio Balbuena wrote:

|>
|>Hello
|>I am using package multicore for parallel computing in a Altix 
UltraViolet
|>1000 server with 64 CPUs and 960 GB of RAM memory. Access is 
managed by
|>means of a SGE queue system. This is the first time I am using 
parallel
|>computing and my experience with supercomputers is quite limited. 
So any

|>help will be much, much appreciated.
|>My experiment consists of a number of runs (N.runs) each involving 
a number
|>of permutations (N. perms). (An excerpt of the code is included 
below.) The
|>permutations are very time consuming and I am using mclapply to 
distribute
|>the job among a given number of cpus (usually 12 to 24). The 
problem is that
|>the system administrators notice that threads keep increasing as 
the program
|>is executed to the point that they compromise the functioning of 
the whole

|>system and have to abort the job.

So, does that mean you get nothing written to 1MH_30.tre?  I'd be
surprised if you did get anything.  Though there's lots of stuff
happening I know nothing about, I'm pretty sure there's an issue with
your wrapper() function.

[...]

|>  wrapper <- function (x) {   # THIS FUCNTION IS SUPPOSED 
TO BE

|>PARALLELIZED (SEE BELOW)
|>treeH <- read.tree(text=linH[x])
|>treeP <- read.tree(text=linP[x])
|>mrcaL <- MRCALink.simul (treeH, treeP, HP)
|>stat.matrix[x,] <- three.stat(mrcaL)
|>}

Nothing is being returned, so your calls to rbind will have nothing to
put together.  So what they end up trying to do, I've no idea.  That
function probably needs a final line 'stat.matrix' before the '}'

One thing I discovered with mclapply is that to use the browser()
function, it's necessary to make what is x in your example of length 1
(and probably mc.cores to 1 also) before it's possible to examine
what's happening at various parts of the function being debugged.
Judicious use of cat() and Sys.time() to display what's happening at
various stages is also helpful.

HTH

--
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
   ___Patrick Connolly
 {~._.~} Great minds discuss ideas
 _( Y )_Middle minds discuss events
(:_~*~_:)Small minds discuss people
 (_)-(_)   . Anon

~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] hist() : is there a way to change the border width?

2013-12-19 Thread capricy gao
I have played around with it and found that the only color could be changed. 
But I really would like to change the width...

Thanks a lot :)

[[alternative HTML version deleted]]

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


Re: [R] Help using mapply to run multiple models

2013-12-19 Thread Simon Kiss
Hi there: Just to tie this altogether.

Here is the final function

f<- function (modelType, responseName, predictorNames, data, ..., envir = 
parent.frame())
{
  call <- match.call()
  call$formula <- formula(envir = envir, paste(responseName, sep = " ~ ",
   paste0("`", predictorNames, "`", 
collapse = " + ")))
  call[[1]] <- as.name(modelType)
  call$responseName <- NULL # omit responseName=
  call$predictorNames <- NULL # omit 'predictorNames='
  eval(call, envir = envir)
}
  
Here I call the function to a list of predictor variables and one dependent 
variable. Note "glm" and not glm.
z <- lapply(list(c("hp","drat"), c("cyl"), c("am","gear")), 
FUN=function(preds)f("glm", "carb", preds, data=mtcars, family='binomial'))

I do get this error:
Error in glm.control(modelType = "glm") : 
  unused argument(s) (modelType = "glm")

But 
lapply(z, summary)

does seem to return a list of model summaries. It looks like it worked.

I also tried. 
z <- lapply(list(c("hp","drat"), c("cyl"), c("am","gear")), 
FUN=function(preds)f("lm", "mpg", preds, data=mtcars))

Here, I get:
1: In lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
  extra argument ‘modelType’ is disregarded.
2: In lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
  extra argument ‘modelType’ is disregarded.
3: In lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
  extra argument ‘modelType’ is disregarded.

But again, it actually looks like it worked.
So, thank you very much!
Yours, Simon Kiss

On 2013-12-19, at 1:55 PM, Simon Kiss  wrote:

> Hello Bill, that is fantastic and it's quite a bit above what I could write. 
> Is there a way to make the model type an argument to the function so that you 
> can specify whether one is running glm, lm and such? 
> I tried to modify it by inserting an argument modelType below, but that 
> doesn't work.
> Yours, simon Kiss
>> f <- function (modelType, responseName, predictorNames, data, ..., envir = 
>> parent.frame())
>>   {
>>   call <- match.call()
>>   call$formula <- formula(envir = envir, paste(responseName, sep = " ~ ",
>>   paste0("`", predictorNames, "`", collapse = " + ")))
>>   call[[1]] <- quote(modelType) # '
>>   call$responseName <- NULL # omit responseName=
>>   call$predictorNames <- NULL # omit 'predictorNames='
>>   eval(call, envir = envir)
>>   }
> On 2013-12-18, at 3:07 PM, William Dunlap  wrote:
> 
>> f <- function (responseName, predictorNames, data, ..., envir = 
>> parent.frame())
>>   {
>>   call <- match.call()
>>   call$formula <- formula(envir = envir, paste(responseName, sep = " ~ ",
>>   paste0("`", predictorNames, "`", collapse = " + ")))
>>   call[[1]] <- quote(glm) # 'f' -> 'glm'
>>   call$responseName <- NULL # omit responseName=
>>   call$predictorNames <- NULL # omit 'predictorNames='
>>   eval(call, envir = envir)
>>   }
>> as in
>>   z <- lapply(list(c("hp","drat"), c("cyl"), c("am","gear")), 
>> FUN=function(preds)f("carb", preds, data=mtcars, family=poisson))
>>   lapply(z, summary)
> 
> *
> Simon J. Kiss, PhD
> Assistant Professor, Wilfrid Laurier University
> 73 George Street
> Brantford, Ontario, Canada
> N3T 2C9
> Cell: +1 905 746 7606
> 
> 
> 

*
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9
Cell: +1 905 746 7606

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


Re: [R] Help using mapply to run multiple models

2013-12-19 Thread William Dunlap
> I do get this error:
> Error in glm.control(modelType = "glm") :
>   unused argument(s) (modelType = "glm")

Add the line
   call$modelType <- NULL # omit modelType argument
to your function.  Otherwise
   f("glm", ...)
makes the call
   glm(modelType="glm", ...)
where you want it to make the call
   glm(...)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: Simon Kiss [mailto:sjk...@gmail.com]
> Sent: Thursday, December 19, 2013 1:49 PM
> To: William Dunlap
> Cc: Dennis Murphy; r-help@r-project.org
> Subject: Re: [R] Help using mapply to run multiple models
> 
> Hi there: Just to tie this altogether.
> 
> Here is the final function
> 
> f<- function (modelType, responseName, predictorNames, data, ..., envir =
> parent.frame())
> {
>   call <- match.call()
>   call$formula <- formula(envir = envir, paste(responseName, sep = " ~ ",
>paste0("`", predictorNames, 
> "`", collapse = " + ")))
>   call[[1]] <- as.name(modelType)
>   call$responseName <- NULL # omit responseName=
>   call$predictorNames <- NULL # omit 'predictorNames='
>   eval(call, envir = envir)
> }
> 
> Here I call the function to a list of predictor variables and one dependent 
> variable. Note
> "glm" and not glm.
> z <- lapply(list(c("hp","drat"), c("cyl"), c("am","gear")), 
> FUN=function(preds)f("glm",
> "carb", preds, data=mtcars, family='binomial'))
> 
> I do get this error:
> Error in glm.control(modelType = "glm") :
>   unused argument(s) (modelType = "glm")
> 
> But
> lapply(z, summary)
> 
> does seem to return a list of model summaries. It looks like it worked.
> 
> I also tried.
> z <- lapply(list(c("hp","drat"), c("cyl"), c("am","gear")), 
> FUN=function(preds)f("lm", "mpg",
> preds, data=mtcars))
> 
> Here, I get:
> 1: In lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
>   extra argument 'modelType' is disregarded.
> 2: In lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
>   extra argument 'modelType' is disregarded.
> 3: In lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
>   extra argument 'modelType' is disregarded.
> 
> But again, it actually looks like it worked.
> So, thank you very much!
> Yours, Simon Kiss
> 
> On 2013-12-19, at 1:55 PM, Simon Kiss  wrote:
> 
> > Hello Bill, that is fantastic and it's quite a bit above what I could 
> > write. Is there a way to
> make the model type an argument to the function so that you can specify 
> whether one is
> running glm, lm and such?
> > I tried to modify it by inserting an argument modelType below, but that 
> > doesn't work.
> > Yours, simon Kiss
> >> f <- function (modelType, responseName, predictorNames, data, ..., envir =
> parent.frame())
> >>   {
> >>   call <- match.call()
> >>   call$formula <- formula(envir = envir, paste(responseName, sep = " ~ 
> >> ",
> >>   paste0("`", predictorNames, "`", collapse = " + ")))
> >>   call[[1]] <- quote(modelType) # '
> >>   call$responseName <- NULL # omit responseName=
> >>   call$predictorNames <- NULL # omit 'predictorNames='
> >>   eval(call, envir = envir)
> >>   }
> > On 2013-12-18, at 3:07 PM, William Dunlap  wrote:
> >
> >> f <- function (responseName, predictorNames, data, ..., envir = 
> >> parent.frame())
> >>   {
> >>   call <- match.call()
> >>   call$formula <- formula(envir = envir, paste(responseName, sep = " ~ 
> >> ",
> >>   paste0("`", predictorNames, "`", collapse = " + ")))
> >>   call[[1]] <- quote(glm) # 'f' -> 'glm'
> >>   call$responseName <- NULL # omit responseName=
> >>   call$predictorNames <- NULL # omit 'predictorNames='
> >>   eval(call, envir = envir)
> >>   }
> >> as in
> >>   z <- lapply(list(c("hp","drat"), c("cyl"), c("am","gear")), 
> >> FUN=function(preds)f("carb",
> preds, data=mtcars, family=poisson))
> >>   lapply(z, summary)
> >
> > *
> > Simon J. Kiss, PhD
> > Assistant Professor, Wilfrid Laurier University
> > 73 George Street
> > Brantford, Ontario, Canada
> > N3T 2C9
> > Cell: +1 905 746 7606
> >
> >
> >
> 
> *
> Simon J. Kiss, PhD
> Assistant Professor, Wilfrid Laurier University
> 73 George Street
> Brantford, Ontario, Canada
> N3T 2C9
> Cell: +1 905 746 7606
> 
> 

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


Re: [R] read ".slk" file

2013-12-19 Thread Santosh
Dear Rxperts..
Thanks for your response... Will keep you posted.

Santosh


On Thu, Dec 19, 2013 at 10:06 AM, David Winsemius wrote:

>
> On Dec 16, 2013, at 3:10 PM, Santosh wrote:
>
> > Dear Rxperts..
> >
> > I recently received a data file with the extension ".slk". If I save the
> > file as MS Excel file, I am able to read in R without issues.  Is it
> > possible to read this ".slk" file without converting into another
> > R-readable data format?
>
> Reading this I wondered if you could use sep=";" with read.* functions.
> http://en.wikipedia.org/wiki/SYmbolic_LinK_%28SYLK%29
>
> That is NOT going to give you a neat dataframe, but you didn't make your
> goals very clear so it seems possible that you might get what you needed
> from some selected input lines.
>
> --
> David Winsemius
> Alameda, CA, USA
>
>

[[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] spending most of my time in assignments?

2013-12-19 Thread Ross Boylan
My code seems to be spending most of its time in assignment statements,
in some cases simple assignment of a model frame or model matrix.

Can anyone provide any insights into what's going on, or how to speed
things up?

For starters, is it possible that the reports are not accurate, or that
I am misreading them.  In R 3.0.1 (running under ESS):
 > Rprof(line.profiling=TRUE)
 > system.time(r <- totalEffect(dodata[[1]], dodata[[2]], 1:3, 4))
user  system elapsed
  21.629   0.756  22.469
!> Rprof(NULL)  


   
 > summaryRprof(lines="both")
 $by.self
self.time self.pct total.time total.pct
 box.R#158   6.7429.56  13.06 57.28 


   
 simulator.multinomial.R#64  2.9212.81   2.96 12.98 


   
 simulator.multinomial.R#63  2.7612.11   2.76 12.11 


   
 box.R#171   2.5411.14   5.08 22.28 


   
 simulator.d1.R#70   0.98 4.30   0.98  4.30 


   
 simulator.d1.R#71   0.98 4.30   0.98  4.30 


   
 densMap.R#420.72 3.16   0.86  3.77 


   
 "standardGeneric"   0.52 2.28  11.30 49.56
..

Here's some of the code, with comments at the line numbers
box.R:
sp <- merge(sexpartner, data, by="studyidx")


   
sp$y <- numFactor(sp$pEthnic)  #I think y is not used but must 
be present  


data(sims.c1[[k]]) <- sp###< line 158   



sp0 <- sp   


   
sp <- sim(sims.c1[[k]], i)  


   
ctable[[k]] <- update.c1(ctable[[k]], sp)   


   
if (is.null(i.c1.in)) { 


   
i.c1.in <- match("pEthnic", colnames(sp0))  
   

[R] Searching the help archives - 404 error?

2013-12-19 Thread Simon Kiss
I'm using Mac OS 10.8.5, Chrome 31 and Safari 6.1. 
Recently, when entering anything into the search box here:
http://tolstoy.newcastle.edu.au/R/
I get this response when searching using either Chrome or Safari:

404. That’s an error.

The requested URL /u/newcastlemaths?q=rprofile&sa=Google+Search was not found 
on this server. That’s all we know.

Has the search engine for the help archives moved?
Yours, Simon Kiss
*
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9

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

2013-12-19 Thread bradford
I use ggplot2 a lot and am wondering why I can't just color with a
function?  For example, if value < 0 then use red else use green.

How would you guys suggest to color these bar graphs so that positive is
green and negative is red?

ggplot(melt(df,measure.vars=c("data1", "data2", "data3", "data4")),
aes(x=Month,y=value)) + geom_bar(stat = "identity") + facet_wrap(~variable,
ncol=1, scales = "free_y") + scale_y_continuous(labels=comma)

Thanks,
Bradford

[[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] Searching the help archives - 404 error?

2013-12-19 Thread Jeff Newmiller
There is no "the help archives"... there are numerous archives, some of which 
are not of the same quality as others. You might have better luck following the 
link included in the footer of every email from this list:

https://stat.ethz.ch/mailman/listinfo/r-help

---
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
--- 
Sent from my phone. Please excuse my brevity.

Simon Kiss  wrote:
>I'm using Mac OS 10.8.5, Chrome 31 and Safari 6.1. 
>Recently, when entering anything into the search box here:
>http://tolstoy.newcastle.edu.au/R/
>I get this response when searching using either Chrome or Safari:
>
>404. That’s an error.
>
>The requested URL /u/newcastlemaths?q=rprofile&sa=Google+Search was not
>found on this server. That’s all we know.
>
>Has the search engine for the help archives moved?
>Yours, Simon Kiss
>*
>Simon J. Kiss, PhD
>Assistant Professor, Wilfrid Laurier University
>73 George Street
>Brantford, Ontario, Canada
>N3T 2C9
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/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] spending most of my time in assignments?

2013-12-19 Thread Duncan Murdoch

On 13-12-19 6:37 PM, Ross Boylan wrote:

My code seems to be spending most of its time in assignment statements,
in some cases simple assignment of a model frame or model matrix.

Can anyone provide any insights into what's going on, or how to speed
things up?


You are seeing a lot of time being spent on complex assignments.  For 
example, line 158 is


data(sims.c1[[k]]) <- sp

That makes a function call to `data<-` to do the assignment, and that 
could be slow.  Since it's an S4 method there's a bunch of machinery 
involved in dispatching it; most of that would not have line number 
information, so it'll be charged to that line.


I can't really suggest how to speed it up.

Duncan Murdoch



For starters, is it possible that the reports are not accurate, or that
I am misreading them.  In R 3.0.1 (running under ESS):
  > Rprof(line.profiling=TRUE)
  > system.time(r <- totalEffect(dodata[[1]], dodata[[2]], 1:3, 4))
 user  system elapsed
   21.629   0.756  22.469
!> Rprof(NULL)
  > summaryRprof(lines="both")
  $by.self
 self.time self.pct total.time total.pct
  box.R#158   6.7429.56  13.06 57.28
  simulator.multinomial.R#64  2.9212.81   2.96 12.98
  simulator.multinomial.R#63  2.7612.11   2.76 12.11
  box.R#171   2.5411.14   5.08 22.28
  simulator.d1.R#70   0.98 4.30   0.98  4.30
  simulator.d1.R#71   0.98 4.30   0.98  4.30
  densMap.R#420.72 3.16   0.86  3.77
  "standardGeneric"   0.52 2.28  11.30 49.56
..

Here's some of the code, with comments at the line numbers
box.R:
 sp <- merge(sexpartner, data, by="studyidx")
 sp$y <- numFactor(sp$pEthnic)  #I think y is not used but must 
be present
 data(sims.c1[[k]]) <- sp###< line 158
 sp0 <- sp
 sp <- sim(sims.c1[[k]], i)
 ctable[[k]] <- update.c1(ctable[[k]], sp)
 if (is.null(i.c1.in)) {
 i.c1.in <- match("pEthnic", colnames(sp0))
 i.c1.out <- match(c("studyidx", "n", "pEthnic"), 
colnames(sp))
 }
 sp0 <- merge(sp0[,-i.c1.in], sp[,i.c1.out], by=c("studyidx", 
"n"))
 # d1
 sp0 <- sp0[sp0$pIsMale == 1,]
 # avoid lots of conversion warnings
 sp0$pEthnic <- factor(sp0$pEthnic, levels=partRaceLevels)
 data(sims.d1[[k]]) <- sp0###< line 171
 sp <- sim(sims.d1[[k]], i)
 dtable[[k]] <- update.d1(dtable[[k]], sp)
 rngstate[[k]] <- .Random.seed
The timing seems odd since it doesn't appear there's anything to do at
the 2 lines except invoke data<-, but if that's slow I would expect the
time to go to the data<- function (in a different file) and not to the
call.

In fact the other big time items are inside the data<- functions.
simulator.multinomial.R:

setMethod("data<-", c("simulator.multinomial", "data.frame"),
   function(obj, value) {
 mf <- model.frame(obj@dataFormula, data=value)
 mf$iCluster <- fromOrig(obj@idmap, as.character(mf$studyidx))
 if (any(is.na(mf$iCluster)))
 stop("New studyidx--need to draw from meta distn")
 mm <- model.matrix(obj@modelFormula, data=mf)
 obj@data <- mf  ##<<< line 63
 obj@mm <- mm##<<< line 64
 return(obj)
})

The mm and data slots have type restrictions, but no other validation
tests.
setClass("simulator.multinomial",
  representation(fit="stanfit", idmap="sIDMap",
 modelFormula="formula",
 categories="ANY",  # could be factor or character
 # categories should be in the order of 
their numeric codes in y
 # cached results
 coef="list",
 data="data.frame",
 dataFormula="formula",
 mm="matrix"))
Does it matter that, e.g., a model frame is more than a vanilla data frame?

I thought assignment, given R's lazy copying behavior, was essentially
resetting a pointer, and so should be fast.

Or maybe the time is going to garbage collecting the previous contents
of the slots?

Ross Boylan

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

2013-12-19 Thread Jeff Newmiller

Design questions ("why...") should go to the package maintainer.

You need to learn to ask complete questions [1] and post in plain text 
rather than HTML on this list.


I think that normal practice is to add a factor column that reflects the 
coloring you want, and then reference it. E.g.:


library(reshape2)
library(ggplot2)
set.seed(42)
df <- data.frame( matrix( rnorm(12*4,1,1), ncol=4 ) )
df$Month <- factor( 1:12 )
names( df ) <- c( paste0( "data", 1:4 ), "Month" )
dfm <- melt(df,measure.vars=c("data1", "data2", "data3", "data4" ) )
dfm$col <- "Nonnegative"
dfm$col[ dfm$value < 0 ] <- "Negative"
dfm$col <- as.factor( dfm$col )
ggplot(dfm, aes(x=Month,y=value,fill=col)) +
geom_bar(stat = "identity",position="dodge") +
facet_wrap(~variable,ncol=1, scales = "free_y") +
scale_fill_manual( name="Sign", values=c( "red", "green" ) )

P.S.: Note that "df" is the name of a function provided in base R. In the 
long run you are better off using some other shorthand (I use "DF") 
variable name.


[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example


On Thu, 19 Dec 2013, bradford wrote:


I use ggplot2 a lot and am wondering why I can't just color with a
function?  For example, if value < 0 then use red else use green.

How would you guys suggest to color these bar graphs so that positive is
green and negative is red?

ggplot(melt(df,measure.vars=c("data1", "data2", "data3", "data4")),
aes(x=Month,y=value)) + geom_bar(stat = "identity") + facet_wrap(~variable,
ncol=1, scales = "free_y") + scale_y_continuous(labels=comma)

Thanks,
Bradford

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



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

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


[R] Fitting particle size analysis data

2013-12-19 Thread Zorig Davaanyam
Hi all,

How do you fit a sieve analysis data to a statistical function?
I have many sieve analysis data of crushed rocks and I'd like to find out
which statistical distributions describe the particular particle size
distributions (PSD) the best. So basically I need to find fitted parameters
to statistical distributions (mostly weibull and truncated lognormal).
Here is an example of particle size (in microns) versus percent weight
retained.
Sieve size   Wt%  Cumulative passing%
+250   0.1 99.9
-250+1802.9 97
-180+1259.5  87.5
-125+90  21.266.3
-90+6329.436.9
-63+45 26  10.9
-45   10.9

PSD<-data.frame(size=c(250,180,125,90,63,45,0),retained=c(0.1,2.9,9.5,21.2,29.4,26,10.9),cumulative=c(99.9,97,87.5,66.3,36.9,10.9,0))

The above example is truncated to 350micron and I can't have particles
with minus dimension. Any help will be greatly appreciated.

Thank you,

Zorig

[[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] hist() : is there a way to change the border width?

2013-12-19 Thread Jim Lemon

On 12/20/2013 08:19 AM, capricy gao wrote:

I have played around with it and found that the only color could be changed. 
But I really would like to change the width...


Hi Capricy,
Try this on the first example for hist:

hist(islands)
par(lwd=3)
hist(islands)

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] Color With a Function

2013-12-19 Thread Jim Lemon

On 12/20/2013 10:38 AM, bradford wrote:

I use ggplot2 a lot and am wondering why I can't just color with a
function?  For example, if value<  0 then use red else use green.

How would you guys suggest to color these bar graphs so that positive is
green and negative is red?

ggplot(melt(df,measure.vars=c("data1", "data2", "data3", "data4")),
aes(x=Month,y=value)) + geom_bar(stat = "identity") + facet_wrap(~variable,
ncol=1, scales = "free_y") + scale_y_continuous(labels=comma)


Hi Bradford,
If you are using numerically designated colors it is fairly easy. Using 
your example above:


col<-(value >= 0) + 2

As "red" is equivalent to "2" and "green" to "3" in the default palette, 
col will be a vector of 2s and 3s depending upon the sign of "value. 
This can be passed to whatever color argument you are using.


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.


[R] Strange subvector output --> x[n] != x[1:n][n]

2013-12-19 Thread Gewart
Hi, Can anyone explain what is going on...!?   For a vector
"x=seq(min,max,0.01)", when generating sub-vector "a" based on a starting
value "st", things go as expected as long as "st" is not too close to the
beginning of "x".  For example, if x starts at -5 and increments by 0.01,
whenever I try to generate the sub-vector "a" (as below) with a starting
value of 0.49 or less it does not generate the expected output: The initial
value of "a" is wrong.
 
Thanks in advance for any clarity you can shed.
Gary

...(please see two versions of code below) 

#THIS WORKS...(st > -4.9)

min = -5; max = 1;  x=seq(min,max,0.01)

st= -4.8 ; end= 0

a=x[((st-min)/0.01+1):((end-min)/0.01+1)] 

n=(st-min)/0.01+1
#compare
a[1:10]; c(x[n:(n+9)])

#test...
n
x[1:n]; x[n]   ### x[n]== x[1:n][n] ; As expected
##
#  BUT THIS IS WEIRD!!...(st <= -4.9)

st= -4.90 ; end= 0 ### -> BUG in generation of a!!

a=x[((st-min)/0.01+1):((end-min)/0.01+1)]; 

n=(st-min)/0.01+1
#compare
a[1:10]; c(x[n:(n+9)])
#test
n
x[1:n]; x[n]  ### NOW x[n] != x[1:n][n]   !!?? What is going on!?





--
View this message in context: 
http://r.789695.n4.nabble.com/Strange-subvector-output-x-n-x-1-n-n-tp4682526.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] Strange subvector output --> x[n] != x[1:n][n]

2013-12-19 Thread Jeff Newmiller
Sigh. Google couldn't help you?

Try FAQ 7.31 and then use non-fractions to generate sequences... scale as 
desired. This is not unique to R.
---
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
--- 
Sent from my phone. Please excuse my brevity.

Gewart  wrote:
>Hi, Can anyone explain what is going on...!?   For a vector
>"x=seq(min,max,0.01)", when generating sub-vector "a" based on a
>starting
>value "st", things go as expected as long as "st" is not too close to
>the
>beginning of "x".  For example, if x starts at -5 and increments by
>0.01,
>whenever I try to generate the sub-vector "a" (as below) with a
>starting
>value of 0.49 or less it does not generate the expected output: The
>initial
>value of "a" is wrong.
> 
>Thanks in advance for any clarity you can shed.
>Gary
>
>...(please see two versions of code below) 
>
>#THIS WORKS...(st > -4.9)
>
>   min = -5; max = 1;  x=seq(min,max,0.01)
>
>   st= -4.8 ; end= 0
>
>   a=x[((st-min)/0.01+1):((end-min)/0.01+1)] 
>   
>   n=(st-min)/0.01+1
>#compare   
>   a[1:10]; c(x[n:(n+9)])
>
>#test...
>   n
>   x[1:n]; x[n]   ### x[n]== x[1:n][n] ; As expected
>##
>#  BUT THIS IS WEIRD!!...(st <= -4.9)
>   
>   st= -4.90 ; end= 0 ### -> BUG in generation of a!!
>
>   a=x[((st-min)/0.01+1):((end-min)/0.01+1)]; 
>   
>   n=(st-min)/0.01+1
>#compare   
>   a[1:10]; c(x[n:(n+9)])
>#test
>   n
>   x[1:n]; x[n]  ### NOW x[n] != x[1:n][n]   !!?? What is going on!?
>
>
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Strange-subvector-output-x-n-x-1-n-n-tp4682526.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.