Re: [R] passing arguments to simple plotting program.

2017-05-09 Thread Gerard Smits
Seems so simple when you explain it.  Thanks very much.  Gerard


> On May 9, 2017, at 9:40 AM, Ulrik Stervbo <ulrik.ster...@gmail.com> wrote:
> 
> Hi Gerard,
> Quotation marks are used for strings. In you function body you try to use the 
> strings "indata" and "fig_descrip" (the latter will work but is not what you 
> want).
> 
> In your current function call you pass the variable Figure as the value to 
> the argument fig_descrip, followed by a lot of other stuff your function 
> doesn't know what to do with.
> 
> Remove the quotation marks around indata and fig_descrip in the function 
> body, call your function with:
> 
> plot_f1(indata=v5, n1=114, n2=119, n3=116, fig_descrip="Figure 2a\nChange in 
> Composite Score at Visit 5 (Day 31)\nPer Protocol Population")
> 
> and you should be fine.
> 
> HTH
> 
> Ulrik
> 
> Gerard Smits <smits.gerar...@gmail.com <mailto:smits.gerar...@gmail.com>> 
> schrieb am Di., 9. Mai 2017, 18:27:
> Hi Ulrik,
> 
> If I can trouble you with one more question.
> 
> Now trying to send a string to the main= .  I was able to pass the data name 
> in data=in_data, but same logic is not working in passion the main string.
> 
> 
> plot_f1 <-function(indata,n1,n2,n3,fig_descrip) {
>   par(oma=c(2,2,2,2))
>   boxplot(formula = d_comp ~ rx_grp,
>   data="indata”,# <- worked fine here.
>   main="fig_descrip",
>   ylim=c(-10,5),
>   names=c(paste0("Placebo(N=", n1,  ")"),
> paste0("Low Dose(N=", n2, ")"),
> paste0("High Dose(N=", n3,")")),
>   ylab='Change from Baseline')
>   abline(h=c(0), col="lightgray")
> }
> 
> plot_f1(indata=v5, n1=114, n2=119, n3=116, fig_descrip=Figure 2a\nChange in 
> Composite Score at Visit 5 (Day 31)\nPer Protocol Population)
> 
> Error Message: Error: unexpected numeric constant in "plot_f1(indata=v5, 
> n1=114, n2=119, n3=116, fig_descrip=Figure 2”
> 
> Even this call gives the same error:  plot_f1(indata=v5, n1=114, n2=119, 
> n3=116, fig_descrip=Figure)
> 
> 
> Thanks, 
> 
> Gerard
> 
> 
> 
> 
> 
> 
>> On May 8, 2017, at 11:40 PM, Ulrik Stervbo <ulrik.ster...@gmail.com 
>> <mailto:ulrik.ster...@gmail.com>> wrote:
>> 
> 
>> HI Gerard,
>> 
>> You get the literals because the variables are not implicitly expanded - 
>> 'Placebo(N=n1)  ' is just a string indicating the N = n1. 
>> 
>> What you want is to use paste() or paste0(): 
>> c(paste0("Placebo(N=", n1, ")"), paste0("Low Dose (N=", n2, ")"), 
>> paste0("High Dose (N=", n3, ")"))
>> should do it.
>> 
>> I was taught a long ago that attach() should be avoided to avoid name 
>> conflicts. Also, it makes it difficult to figure out which data is actually 
>> being used.
>> 
>> HTH
>> Ulrik
>> 
>> On Tue, 9 May 2017 at 06:44 Gerard Smits <smits.gerar...@gmail.com 
>> <mailto:smits.gerar...@gmail.com>> wrote:
>> Hi All,
>> 
>> I thought I’d try to get a function working instead of block copying code 
>> and editing. My backorund is more SAS, so using a SAS Macro would be easy, 
>> but not so lucky with R functions.
>> 
>> 
>> R being used on Mac Sierra 10.12.4:
>> 
>> R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
>> Copyright (C) 2016 The R Foundation for Statistical Computing
>> Platform: x86_64-apple-darwin13.4.0 (64-bit)
>> 
>> 
>> resp<-read.csv("//users//gerard//gs//r_work//xyz.csv", header = TRUE)
>> 
>> v5  <-subset(resp, subset=visit==5 & pp==1)
>> 
>> plot_f1 <-function(n1,n2,n3) {
>>   attach(v8)
>>   par(oma=c(2,2,2,2))
>>   boxplot(formula = d_comp ~ rx_grp,
>>   main="Figure 2\nChange in Composite Score at Visit 5 (Day 31)\nPer 
>> Protocol Population",
>>   ylim=c(-10,5),
>>   names=c('Placebo(N=n1)  ',
>>   'Low Dose(N=n2) ',
>>   'High Dose(N=n3)'),
>>   ylab='Change from Baseline')
>>   abline(h=c(0), col="lightgray")
>> }
>> 
>> plot_f1(n1=114, n2=119, n3=116)
>> 
>> The above is a simplified example where I am trying to pass 3 arguments, 
>> n1-n3, to be shown in the x-axis tables,  Instead of the numbers, I get the 
>> literal n1, n2, n3.
>> 
>> Any help appreciated.
>> 
>> Thanks,
>&g

Re: [R] passing arguments to simple plotting program.

2017-05-09 Thread Gerard Smits
Hi Ulrik,

If I can trouble you with one more question.

Now trying to send a string to the main= .  I was able to pass the data name in 
data=in_data, but same logic is not working in passion the main string.


plot_f1 <-function(indata,n1,n2,n3,fig_descrip) {
  par(oma=c(2,2,2,2))
  boxplot(formula = d_comp ~ rx_grp,
  data="indata”,# <- worked fine here.
  main="fig_descrip",
  ylim=c(-10,5),
  names=c(paste0("Placebo(N=", n1,  ")"),
  paste0("Low Dose(N=", n2, ")"),
  paste0("High Dose(N=", n3,")")),
  ylab='Change from Baseline')
  abline(h=c(0), col="lightgray")
}

plot_f1(indata=v5, n1=114, n2=119, n3=116, fig_descrip=Figure 2a\nChange in 
Composite Score at Visit 5 (Day 31)\nPer Protocol Population)

Error Message: Error: unexpected numeric constant in "plot_f1(indata=v5, 
n1=114, n2=119, n3=116, fig_descrip=Figure 2”

Even this call gives the same error:  plot_f1(indata=v5, n1=114, n2=119, 
n3=116, fig_descrip=Figure)


Thanks, 

Gerard






> On May 8, 2017, at 11:40 PM, Ulrik Stervbo <ulrik.ster...@gmail.com> wrote:
> 
> HI Gerard,
> 
> You get the literals because the variables are not implicitly expanded - 
> 'Placebo(N=n1)  ' is just a string indicating the N = n1. 
> 
> What you want is to use paste() or paste0(): 
> c(paste0("Placebo(N=", n1, ")"), paste0("Low Dose (N=", n2, ")"), 
> paste0("High Dose (N=", n3, ")"))
> should do it.
> 
> I was taught a long ago that attach() should be avoided to avoid name 
> conflicts. Also, it makes it difficult to figure out which data is actually 
> being used.
> 
> HTH
> Ulrik
> 
> On Tue, 9 May 2017 at 06:44 Gerard Smits <smits.gerar...@gmail.com 
> <mailto:smits.gerar...@gmail.com>> wrote:
> Hi All,
> 
> I thought I’d try to get a function working instead of block copying code and 
> editing. My backorund is more SAS, so using a SAS Macro would be easy, but 
> not so lucky with R functions.
> 
> 
> R being used on Mac Sierra 10.12.4:
> 
> R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
> Copyright (C) 2016 The R Foundation for Statistical Computing
> Platform: x86_64-apple-darwin13.4.0 (64-bit)
> 
> 
> resp<-read.csv("//users//gerard//gs//r_work//xyz.csv", header = TRUE)
> 
> v5  <-subset(resp, subset=visit==5 & pp==1)
> 
> plot_f1 <-function(n1,n2,n3) {
>   attach(v8)
>   par(oma=c(2,2,2,2))
>   boxplot(formula = d_comp ~ rx_grp,
>   main="Figure 2\nChange in Composite Score at Visit 5 (Day 31)\nPer 
> Protocol Population",
>   ylim=c(-10,5),
>   names=c('Placebo(N=n1)  ',
>   'Low Dose(N=n2) ',
>   'High Dose(N=n3)'),
>   ylab='Change from Baseline')
>   abline(h=c(0), col="lightgray")
> }
> 
> plot_f1(n1=114, n2=119, n3=116)
> 
> The above is a simplified example where I am trying to pass 3 arguments, 
> n1-n3, to be shown in the x-axis tables,  Instead of the numbers, I get the 
> literal n1, n2, n3.
> 
> Any help appreciated.
> 
> Thanks,
> 
> Gerard
> 
> 
> 
> 
> [[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 
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
> <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] passing arguments to simple plotting program.

2017-05-09 Thread Gerard Smits
Hi Ulrik,

That worked perfectly.  Thanks for your help. Much appreciated.

Gerard


> On May 8, 2017, at 11:40 PM, Ulrik Stervbo <ulrik.ster...@gmail.com> wrote:
> 
> HI Gerard,
> 
> You get the literals because the variables are not implicitly expanded - 
> 'Placebo(N=n1)  ' is just a string indicating the N = n1. 
> 
> What you want is to use paste() or paste0(): 
> c(paste0("Placebo(N=", n1, ")"), paste0("Low Dose (N=", n2, ")"), 
> paste0("High Dose (N=", n3, ")"))
> should do it.
> 
> I was taught a long ago that attach() should be avoided to avoid name 
> conflicts. Also, it makes it difficult to figure out which data is actually 
> being used.
> 
> HTH
> Ulrik
> 
> On Tue, 9 May 2017 at 06:44 Gerard Smits <smits.gerar...@gmail.com 
> <mailto:smits.gerar...@gmail.com>> wrote:
> Hi All,
> 
> I thought I’d try to get a function working instead of block copying code and 
> editing. My backorund is more SAS, so using a SAS Macro would be easy, but 
> not so lucky with R functions.
> 
> 
> R being used on Mac Sierra 10.12.4:
> 
> R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
> Copyright (C) 2016 The R Foundation for Statistical Computing
> Platform: x86_64-apple-darwin13.4.0 (64-bit)
> 
> 
> resp<-read.csv("//users//gerard//gs//r_work//xyz.csv", header = TRUE)
> 
> v5  <-subset(resp, subset=visit==5 & pp==1)
> 
> plot_f1 <-function(n1,n2,n3) {
>   attach(v8)
>   par(oma=c(2,2,2,2))
>   boxplot(formula = d_comp ~ rx_grp,
>   main="Figure 2\nChange in Composite Score at Visit 5 (Day 31)\nPer 
> Protocol Population",
>   ylim=c(-10,5),
>   names=c('Placebo(N=n1)  ',
>   'Low Dose(N=n2) ',
>   'High Dose(N=n3)'),
>   ylab='Change from Baseline')
>   abline(h=c(0), col="lightgray")
> }
> 
> plot_f1(n1=114, n2=119, n3=116)
> 
> The above is a simplified example where I am trying to pass 3 arguments, 
> n1-n3, to be shown in the x-axis tables,  Instead of the numbers, I get the 
> literal n1, n2, n3.
> 
> Any help appreciated.
> 
> Thanks,
> 
> Gerard
> 
> 
> 
> 
> [[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 
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
> <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.

[R] passing arguments to simple plotting program.

2017-05-08 Thread Gerard Smits
Hi All,

I thought I’d try to get a function working instead of block copying code and 
editing. My backorund is more SAS, so using a SAS Macro would be easy, but not 
so lucky with R functions.


R being used on Mac Sierra 10.12.4:

R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)


resp<-read.csv("//users//gerard//gs//r_work//xyz.csv", header = TRUE)

v5  <-subset(resp, subset=visit==5 & pp==1)

plot_f1 <-function(n1,n2,n3) {
  attach(v8)
  par(oma=c(2,2,2,2))
  boxplot(formula = d_comp ~ rx_grp, 
  main="Figure 2\nChange in Composite Score at Visit 5 (Day 31)\nPer 
Protocol Population",
  ylim=c(-10,5),
  names=c('Placebo(N=n1)  ',
  'Low Dose(N=n2) ',
  'High Dose(N=n3)'),
  ylab='Change from Baseline')
  abline(h=c(0), col="lightgray")
}

plot_f1(n1=114, n2=119, n3=116)

The above is a simplified example where I am trying to pass 3 arguments, n1-n3, 
to be shown in the x-axis tables,  Instead of the numbers, I get the literal 
n1, n2, n3.

Any help appreciated.

Thanks,

Gerard




[[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] changing font size in Forest plot code.

2014-01-19 Thread Gerard Smits
Hi All,

I have pulled the following function (fplot) from the internet, and 
unfortunately I do not see an author to whom I can give credit.  It used grid 
graphics and relies mostly on package rmeta by Thomas Lumley.  I am trying to 
make the font smaller in my labeltext, but don’t see any references to font 
size in the code.  Digitize changes the number size on the x-axis, but don’t 
see a corresponding way of making the labeling size smaller.

Using R 3.0.2

Any suggestions appreciated.

Gerard Smits

fplot=function (labeltext, mean, lower, upper, align = NULL, is.summary = 
FALSE, 
clip = c(-Inf, Inf), xlab = , zero = 1, graphwidth = unit(3,inches),
col = meta.colors(), xlog = FALSE, xticks = NULL,
xlow=0, xhigh, digitsize, boxsize, 
...) 

{
require(grid)  || stop(`grid' package not found)
require(rmeta) || stop(`rmeta' package not found)


drawNormalCI - function(LL, OR, UL, size) 
{

size = 0.75 * size
clipupper - convertX(unit(UL, native), npc, valueOnly = TRUE)  1
cliplower - convertX(unit(LL, native), npc, valueOnly = TRUE)  0
box - convertX(unit(OR, native), npc, valueOnly = TRUE)
clipbox - box  0 || box  1

if (clipupper || cliplower) 
{
ends - both
lims - unit(c(0, 1), c(npc, npc))
if (!clipupper) {
ends - first
lims - unit(c(0, UL), c(npc, native))
}
if (!cliplower) {
ends - last
lims - unit(c(LL, 1), c(native, npc))
}
grid.lines(x = lims, y = 0.5, arrow = arrow(ends = ends, 
length = unit(0.05, inches)), gp = gpar(col = col$lines))

if (!clipbox) 
grid.rect(x = unit(OR, native), width = unit(size, 
  snpc), height = unit(size, snpc), gp = gpar(fill = 
col$box, 
  col = col$box))
}
else {
grid.lines(x = unit(c(LL, UL), native), y = 0.5, 
gp = gpar(col = col$lines))
grid.rect(x = unit(OR, native), width = unit(size, 
snpc), height = unit(size, snpc), gp = gpar(fill = col$box, 
col = col$box))
if ((convertX(unit(OR, native) + unit(0.5 * size, 
lines), native, valueOnly = TRUE)  UL)  
(convertX(unit(OR, native) - unit(0.5 * size, 
  lines), native, valueOnly = TRUE)  LL)) 
grid.lines(x = unit(c(LL, UL), native), y = 0.5, 
  gp = gpar(col = col$lines))
}

}

drawSummaryCI - function(LL, OR, UL, size) {
grid.polygon(x = unit(c(LL, OR, UL, OR), native), y = unit(0.5 + 
c(0, 0.5 * size, 0, -0.5 * size), npc), gp = gpar(fill = 
col$summary, 
col = col$summary))
}

plot.new()
widthcolumn - !apply(is.na(labeltext), 1, any)
nc - NCOL(labeltext)
labels - vector(list, nc)
if (is.null(align)) 
align - c(l, rep(r, nc - 1))
else align - rep(align, length = nc)
nr - NROW(labeltext)
is.summary - rep(is.summary, length = nr)
for (j in 1:nc) {
labels[[j]] - vector(list, nr)
for (i in 1:nr) {
if (is.na(labeltext[i, j])) 
next
x - switch(align[j], l = 0, r = 1, c = 0.5)
just - switch(align[j], l = left, r = right, c = center)
labels[[j]][[i]] - textGrob(labeltext[i, j], x = x, 
just = just, gp = gpar(fontface = if (is.summary[i]) bold
else plain, col = rep(col$text, length = nr)[i]))
}
}
colgap - unit(3, mm)
colwidths - unit.c(max(unit(rep(1, sum(widthcolumn)), grobwidth, 
labels[[1]][widthcolumn])), colgap)
if (nc  1) {
for (i in 2:nc) colwidths - unit.c(colwidths, max(unit(rep(1, 
sum(widthcolumn)), grobwidth, labels[[i]][widthcolumn])), 
colgap)
}
colwidths - unit.c(colwidths, graphwidth)
pushViewport(viewport(layout = grid.layout(nr + 1, nc * 2 + 
1, widths = colwidths, heights = unit(c(rep(1, nr), 0.5), 
lines
cwidth - (upper - lower)

#xrange - c(max(min(lower, na.rm = TRUE), clip[1]), min(max(upper, na.rm = 
TRUE), clip[2]))
xrange - c(xlow,xhigh)

info - 1/cwidth
info - info/max(info[!is.summary], na.rm = TRUE)
info[is.summary] - 1

if (!is.null(boxsize))
 info - rep(boxsize, length = length(info))

for (j in 1:nc) {
for (i in 1:nr) {
if (!is.null(labels[[j]][[i]])) {
pushViewport(viewport(layout.pos.row = i, layout.pos.col = 2 * 
  j - 1))
grid.draw(labels[[j]][[i]])
popViewport()
}
}
}

pushViewport(viewport(layout.pos.col = 2 * nc + 1, xscale = xrange))
grid.lines(x = unit(zero, native), y = 0:1, gp = gpar(col = col$zero))
if (xlog) {
if (is.null(xticks

Re: [R] changing font size in Forest plot code.

2014-01-19 Thread Gerard Smits
Hi David,

That worked perfectly.  I had tried something like that, but obviously messed 
up the change.

Thanks for your help. Much appreciated.

Gerard


On Jan 19, 2014, at 2:16 PM, David Winsemius dwinsem...@comcast.net wrote:

 
 On Jan 19, 2014, at 1:13 PM, Gerard Smits wrote:
 
 Hi All,
 
 I have pulled the following function (fplot) from the internet, and 
 unfortunately I do not see an author to whom I can give credit.  It used 
 grid graphics and relies mostly on package rmeta by Thomas Lumley.  I am 
 trying to make the font smaller in my labeltext, but don‚t see any 
 references to font size in the code.  Digitize changes the number size on 
 the x-axis, but don‚t see a corresponding way of making the labeling size 
 smaller.
 
 
 Wouldn't it just be needed to specify grid parameters (as exemplified several 
 other places in that code)  in the code where 'labels' are created?
 
 ...
 labels[[j]][[i]] - textGrob(labeltext[i, j], x = x, 
just = just, gp = gpar(fontsize=8, fontface = if 
 (is.summary[i]) bold
else plain, col = rep(col$text, length = nr)[i]))
 ...
 
 Seems to succeed (once the errant and quite strange double comma character 
 '„' is removed and replaced with a proper double quote.) If you are doing 
 this on a word processor, then you should convert to a programming text 
 editor.
 
 -- 
 David.
 
 Using R 3.0.2
 
 Any suggestions appreciated.
 
 Gerard Smits
 
 fplot=function (labeltext, mean, lower, upper, align = NULL, is.summary = 
 FALSE, 
   clip = c(-Inf, Inf), xlab = , zero = 1, graphwidth = unit(3,inches),
   col = meta.colors(), xlog = FALSE, xticks = NULL,
   xlow=0, xhigh, digitsize, boxsize, 
   ...) 
 
 {
   require(grid)  || stop(`grid' package not found)
   require(rmeta) || stop(`rmeta' package not found)
 
 
   drawNormalCI - function(LL, OR, UL, size) 
   {
 
   size = 0.75 * size
   clipupper - convertX(unit(UL, native), npc, valueOnly = TRUE)  1
   cliplower - convertX(unit(LL, native), npc, valueOnly = TRUE)  0
   box - convertX(unit(OR, native), npc, valueOnly = TRUE)
   clipbox - box  0 || box  1
 
   if (clipupper || cliplower) 
   {
   ends - both
   lims - unit(c(0, 1), c(npc, npc))
   if (!clipupper) {
   ends - first
   lims - unit(c(0, UL), c(npc, native))
   }
   if (!cliplower) {
   ends - last
   lims - unit(c(LL, 1), c(native, npc))
   }
   grid.lines(x = lims, y = 0.5, arrow = arrow(ends = ends, 
   length = unit(0.05, inches)), gp = gpar(col = col$lines))
 
   if (!clipbox) 
   grid.rect(x = unit(OR, native), width = unit(size, 
 snpc), height = unit(size, snpc), gp = gpar(fill = 
 col$box, 
 col = col$box))
   }
   else {
   grid.lines(x = unit(c(LL, UL), native), y = 0.5, 
   gp = gpar(col = col$lines))
   grid.rect(x = unit(OR, native), width = unit(size, 
   snpc), height = unit(size, snpc), gp = gpar(fill = 
 col$box, 
   col = col$box))
   if ((convertX(unit(OR, native) + unit(0.5 * size, 
   lines), native, valueOnly = TRUE)  UL)  
   (convertX(unit(OR, native) - unit(0.5 * size, 
 lines), native, valueOnly = TRUE)  LL)) 
   grid.lines(x = unit(c(LL, UL), native), y = 0.5, 
 gp = gpar(col = col$lines))
   }
 
   }
 
   drawSummaryCI - function(LL, OR, UL, size) {
   grid.polygon(x = unit(c(LL, OR, UL, OR), native), y = unit(0.5 + 
   c(0, 0.5 * size, 0, -0.5 * size), npc), gp = gpar(fill = 
 col$summary, 
   col = col$summary))
   }
 
   plot.new()
   widthcolumn - !apply(is.na(labeltext), 1, any)
   nc - NCOL(labeltext)
   labels - vector(list, nc)
   if (is.null(align)) 
   align - c(l, rep(r, nc - 1))
   else align - rep(align, length = nc)
   nr - NROW(labeltext)
   is.summary - rep(is.summary, length = nr)
   for (j in 1:nc) {
   labels[[j]] - vector(list, nr)
   for (i in 1:nr) {
   if (is.na(labeltext[i, j])) 
   next
   x - switch(align[j], l = 0, r = 1, c = 0.5)
   just - switch(align[j], l = left, r = right, c = center)
   labels[[j]][[i]] - textGrob(labeltext[i, j], x = x, 
   just = just, gp = gpar(fontface = if (is.summary[i]) bold
   else plain, col = rep(col$text, length = nr)[i]))
   }
   }
   colgap - unit(3, mm)
   colwidths - unit.c(max(unit(rep(1, sum(widthcolumn)), grobwidth, 
   labels[[1]][widthcolumn])), colgap)
   if (nc  1) {
   for (i in 2:nc) colwidths - unit.c(colwidths, max(unit(rep(1, 
   sum(widthcolumn)), grobwidth, labels[[i]][widthcolumn])), 
   colgap)
   }
   colwidths - unit.c(colwidths, graphwidth)
   pushViewport(viewport(layout = grid.layout(nr + 1, nc * 2 + 
   1, widths = colwidths, heights = unit(c(rep(1

[R] problem with newline using bquote(paste())

2013-08-30 Thread Gerard Smits
Hi All,

This is a variant of a problem I posted yesterday (see below) where I found I 
had a large gap between my N= and he number I had evaluated using .(x).  I seem 
to have trouble with newlines in a main title.  I find now that all works as 
expected (no unsightly gap between my N= and the value, if all of the title is 
put on the same line.  Whenever I try the newline, I run into problems.

Below, I have one example that gives me no syntax errors, but simply does not 
print the information after the \n (the N= xxx) part.

Any help appreciated.

Thanks,

Gerard

PS using R 3.0.0


ss-n(m18_das28*b_dascore)
par(oma=c(2,2,2,2))
scatterplot(m18_das28~b_score,
 jitter=list(x=1, y=1),
 grid=F,
 smooth=F,
 las=1,
 pch=c(1),
 col='blue',
 main=as.expression(bquote(paste(Baseline xyz with Month 18 DAS28\n)), 
bquote(paste((N=,.(ss),,
 xlab=Baseline xyz, 
 ylab=Month 18 DAS28,
 legend.plot=F)




Prior, related post:

On Aug 29, 2013, at 2:00 PM, Gerard Smits g_sm...@verizon.net wrote:

 Hi All,
 
 I'm using R 3.0.0.  I'm trying to add the sample size of the paired data 
 (calculated by a function n(), which returns a value of 70, correctly).
 
 My main title works fine except that the '70' appears far to the right on the 
 line as in:
 
  at Month 18 (N=   70)
 
 Is there a way of left justifying the result of .(ss)?  or some other way of 
 removing with whitespace between n= and 70?.
 
 Thanks for any suggestions.
 
 Gerard
 
 
 
 
 library (car)
 data-read.csv(//users//smits//r_work//data.csv, header = TRUE)
 attach(data);
 
 ##
 ss-n(m18_das28*b_score)
 
 scatterplot(m18_das28~b_score,
 jitter=list(x=1, y=1),
 grid=F,
 smooth=F,
 las=1,
 pch=c(1),
 col='blue',
 main=bquote(paste(Hypothesis 9.4.1\nBaseline XYZ with Disease Activity 
 (DAS28)\nat Month 18 (N=,.(ss),))),
 xlab=Baseline XYZ, 
 ylab=Month 18 DAS28,
 legend.plot=F)
 

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


Re: [R] problem with newline using bquote(paste())

2013-08-30 Thread Gerard Smits
That explains it.  Thanks for the info.  Gerard


On Aug 30, 2013, at 8:42 AM, Marc Schwartz marc_schwa...@me.com wrote:

 
 On Aug 30, 2013, at 10:26 AM, Gerard Smits g_sm...@verizon.net wrote:
 
 Hi All,
 
 This is a variant of a problem I posted yesterday (see below) where I found 
 I had a large gap between my N= and he number I had evaluated using .(x).  I 
 seem to have trouble with newlines in a main title.  I find now that all 
 works as expected (no unsightly gap between my N= and the value, if all of 
 the title is put on the same line.  Whenever I try the newline, I run into 
 problems.
 
 Below, I have one example that gives me no syntax errors, but simply does 
 not print the information after the \n (the N= xxx) part.
 
 Any help appreciated.
 
 Thanks,
 
 Gerard
 
 PS using R 3.0.0
 
 
 ss-n(m18_das28*b_dascore)
 par(oma=c(2,2,2,2))
 scatterplot(m18_das28~b_score,
jitter=list(x=1, y=1),
grid=F,
smooth=F,
las=1,
pch=c(1),
col='blue',
main=as.expression(bquote(paste(Baseline xyz with Month 18 DAS28\n)), 
 bquote(paste((N=,.(ss),,
xlab=Baseline xyz, 
ylab=Month 18 DAS28,
legend.plot=F)
 
 
 
 
 Prior, related post:
 
 On Aug 29, 2013, at 2:00 PM, Gerard Smits g_sm...@verizon.net wrote:
 
 Hi All,
 
 I'm using R 3.0.0.  I'm trying to add the sample size of the paired data 
 (calculated by a function n(), which returns a value of 70, correctly).
 
 My main title works fine except that the '70' appears far to the right on 
 the line as in:
 
 at Month 18 (N=   70)
 
 Is there a way of left justifying the result of .(ss)?  or some other way 
 of removing with whitespace between n= and 70?.
 
 Thanks for any suggestions.
 
 Gerard
 
 
 
 
 library (car)
 data-read.csv(//users//smits//r_work//data.csv, header = TRUE)
 attach(data);
 
 ##
 ss-n(m18_das28*b_score)
 
 scatterplot(m18_das28~b_score,
   jitter=list(x=1, y=1),
   grid=F,
   smooth=F,
   las=1,
   pch=c(1),
   col='blue',
   main=bquote(paste(Hypothesis 9.4.1\nBaseline XYZ with Disease Activity 
 (DAS28)\nat Month 18 (N=,.(ss),))),
   xlab=Baseline XYZ, 
   ylab=Month 18 DAS28,
   legend.plot=F)
 
 
 
 
 You cannot use newlines in plotmath expressions. You will need to create each 
 line of the plot title text separately using ?mtext instead of specifying 
 'main' in the plot call.
 
 Regards,
 
 Marc Schwartz
 

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


[R] spacing problem in main title using car package scatterplot

2013-08-29 Thread Gerard Smits
Hi All,

I'm using R 3.0.0.  I'm trying to add the sample size of the paired data 
(calculated by a function n(), which returns a value of 70, correctly).

My main title works fine except that the '70' appears far to the right on the 
line as in:

  at Month 18 (N=   70)

Is there a way of left justifying the result of .(ss)?  or some other way of 
removing with whitespace between n= and 70?.

Thanks for any suggestions.

Gerard




library (car)
data-read.csv(//users//smits//r_work//data.csv, header = TRUE)
attach(data);

##
ss-n(m18_das28*b_score)

scatterplot(m18_das28~b_score,
 jitter=list(x=1, y=1),
 grid=F,
 smooth=F,
 las=1,
 pch=c(1),
 col='blue',
 main=bquote(paste(Hypothesis 9.4.1\nBaseline XYZ with Disease Activity 
(DAS28)\nat Month 18 (N=,.(ss),))),
 xlab=Baseline XYZ, 
 ylab=Month 18 DAS28,
 legend.plot=F)

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


[R] Problem using a function to produce multiple scatterplots (cars package)

2013-08-15 Thread Gerard Smits
Hi All,

I have a number of plots to run and was hoping to use a function instead of 
bock copying my code and retyping my parameters.

I am using R 3.0.0 on a mac.

My code is as follows:

library (car)
cres-read.csv(//users//smits//r_work//cres.csv, header = TRUE)
attach(cres);

run_plots - functon()
{
  scatterplot(y~x|z,
jitter=list(x=1, y=1),
grid=F,
smooth=F,
las=1,
pch=c(1,2),
col=c('red','blue'),
main=Baseline Clinical CRP by RAMRIS Synovitis at Day 113,
xlab=Baseline CRP, 
ylab=Day 113 Synovitis,
legend.plot=F)
  legend(bottomright,
 box.lty=0, # line type to surround the legend box (0 for none)
 legend=c(Active+MTX,Placebo+MTX),
 col=c('red','blue'),
 pch=c(1,2),
 pt.cex=c(1,1,1,1))
}


then I was hoping to execute the function by passing 3 parameters:  
run_plots(b_crp, t_synos113, treatment)

This approach follows the way I usually do it with a SAS macro, were I can 
repeat the innovation over and over using different variables, etc.

Right off the  bat, you can see that I have a problem finding the function 
function.  Then it does not recognize the first parameter it comes across.

Any help appreciated.

Thanks,

Gerard


 
 cres-read.csv(//users//smits//r_work//cres.csv, header = TRUE)
 attach(cres);
 
 run_plots - functon()
Error: could not find function functon
 {
+   scatterplot(y~x|z,
+ jitter=list(x=1, y=1),
+ grid=F,
+ smooth=F,
+ las=1,
+ pch=c(1,2),
+ col=c('red','blue'),
+ main=Baseline Clinical CRP by RAMRIS Synovitis at Day 113,
+ xlab=Baseline CRP, 
+ ylab=Day 113 Synovitis,
+ legend.plot=F)
+   legend(bottomright,
+  box.lty=0, # line type to surround the legend box (0 for none)
+  legend=c(Active+MTX,Placebo+MTX),
+  col=c('red','blue'),
+  pch=c(1,2),
+  pt.cex=c(1,1,1,1))
+ }
Error in eval(expr, envir, enclos) : object 'y' not found
 

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


Re: [R] Problem using a function to produce multiple scatterplots (cars package)

2013-08-15 Thread Gerard Smits
Dumb error.  Thanks for letting me know.  Gerard


On Aug 15, 2013, at 11:38 AM, Richard M. Heiberger r...@temple.edu wrote:

 typo
 
 run_plots - functon()
 
 
 On Thu, Aug 15, 2013 at 1:10 PM, Gerard Smits g_sm...@verizon.net wrote:
 Hi All,
 
 I have a number of plots to run and was hoping to use a function instead of 
 bock copying my code and retyping my parameters.
 
 I am using R 3.0.0 on a mac.
 
 My code is as follows:
 
 library (car)
 cres-read.csv(//users//smits//r_work//cres.csv, header = TRUE)
 attach(cres);
 
 run_plots - functon()
 {
   scatterplot(y~x|z,
 jitter=list(x=1, y=1),
 grid=F,
 smooth=F,
 las=1,
 pch=c(1,2),
 col=c('red','blue'),
 main=Baseline Clinical CRP by RAMRIS Synovitis at Day 113,
 xlab=Baseline CRP,
 ylab=Day 113 Synovitis,
 legend.plot=F)
   legend(bottomright,
  box.lty=0, # line type to surround the legend box (0 for none)
  legend=c(Active+MTX,Placebo+MTX),
  col=c('red','blue'),
  pch=c(1,2),
  pt.cex=c(1,1,1,1))
 }
 
 
 then I was hoping to execute the function by passing 3 parameters:  
 run_plots(b_crp, t_synos113, treatment)
 
 This approach follows the way I usually do it with a SAS macro, were I can 
 repeat the innovation over and over using different variables, etc.
 
 Right off the  bat, you can see that I have a problem finding the function 
 function.  Then it does not recognize the first parameter it comes across.
 
 Any help appreciated.
 
 Thanks,
 
 Gerard
 
 
 
  cres-read.csv(//users//smits//r_work//cres.csv, header = TRUE)
  attach(cres);
 
  run_plots - functon()
 Error: could not find function functon
  {
 +   scatterplot(y~x|z,
 + jitter=list(x=1, y=1),
 + grid=F,
 + smooth=F,
 + las=1,
 + pch=c(1,2),
 + col=c('red','blue'),
 + main=Baseline Clinical CRP by RAMRIS Synovitis at Day 113,
 + xlab=Baseline CRP,
 + ylab=Day 113 Synovitis,
 + legend.plot=F)
 +   legend(bottomright,
 +  box.lty=0, # line type to surround the legend box (0 for none)
 +  legend=c(Active+MTX,Placebo+MTX),
 +  col=c('red','blue'),
 +  pch=c(1,2),
 +  pt.cex=c(1,1,1,1))
 + }
 Error in eval(expr, envir, enclos) : object 'y' not found
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


[[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] question on axis labels

2012-02-20 Thread Gerard Smits
Hi All,

I'm trying to label my plot axis with times (HH:MM) that correspond to a 
numeric index (values 0:6) for my time variable.  I'd like to plot 08:00, 
12:00,  and so on, instead of 0 through 6.

I have used the following line of code: 

axis(1, 0:6, labels=c(08:00, 12:00, 16:00, 20:00, 24:00, 04:00, 
08:00), cex=0.8)

[I've used both the 0:6 and at=c(0:6), with no effect.]

My labels come out with a 0 - 6, location dependent, superimposed over my colon 
in my HH:MM string.  So 08:00 looks like 08000, 12:00 looks like 12100.

Any way of suppressing the at locations?

I'm using version 2.14.0 on a mac

My program pulls in the following packages (not sure relevant):

require (Hmisc)
require (lattice)
require (gplots)


Thanks for any suggestions,

Gerard

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


Re: [R] question on axis labels

2012-02-20 Thread Gerard Smits
Worked like a charm!  Thanks for your help.  Gerard


On Feb 20, 2012, at 3:52 PM, Sarah Goslee wrote:

 This works for me:
 
 plot(0:6, runif(7), xaxt=n)
 axis(1, at=0:6, labels=c(08:00, 12:00, 16:00, 20:00, 24:00, 
 04:00, 08:00), cex=0.8)
 
 
 You need the xaxt=n in the plot statement, and the correct form is at=0:6
 
 Sarah
 
 On Mon, Feb 20, 2012 at 6:39 PM, Gerard Smits g_sm...@verizon.net wrote:
 Hi All,
 
 I'm trying to label my plot axis with times (HH:MM) that correspond to a 
 numeric index (values 0:6) for my time variable.  I'd like to plot 08:00, 
 12:00,  and so on, instead of 0 through 6.
 
 I have used the following line of code:
 
 axis(1, 0:6, labels=c(08:00, 12:00, 16:00, 20:00, 24:00, 04:00, 
 08:00), cex=0.8)
 
 [I've used both the 0:6 and at=c(0:6), with no effect.]
 
 My labels come out with a 0 - 6, location dependent, superimposed over my 
 colon in my HH:MM string.  So 08:00 looks like 08000, 12:00 looks like 12100.
 
 Any way of suppressing the at locations?
 
 I'm using version 2.14.0 on a mac
 
 My program pulls in the following packages (not sure relevant):
 
 require (Hmisc)
 require (lattice)
 require (gplots)
 
 
 Thanks for any suggestions,
 
 Gerard
 
 
 -- 
 Sarah Goslee
 http://www.functionaldiversity.org

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


[R] question of elimination drawn lines on competing risk graph

2011-02-18 Thread Gerard Smits
Hi All,

I am using the package, cmprisk, to plot competing risks.  In my case, I have 
four lines showing risk of going on dialysis (by a lab test [fgf-23] in 
quartiles), where the 4 lower lines are for the competing risk of death.

I am trying to edit the function to just plot the upper curves (and not show 
the lower (competing) risk death curves.   I am not especially facile in 
editing this code, so would appreciate any help as to where I should be making 
changes.

Hope OK to include the function code.

Thanks.

Gerard



require(cmprsk)

#
#   #
# CUMULATIVE INCIDENCE CURVES IN R  #
#   #
# Written by Luca Scrucca   #
#   #
# Reference:#
# Scrucca L., Santucci A., Aversa F. (2007) Competing risks analysis using  #
#   R: an easy guide for clinicians. Bone Marrow Transplantation, 40,   #
#   381--387.   #
#
# ver. 1.1 Feb 2008
#  - allow group to be missing
#  - if t is provided both computation and plots use t as time points
#  - allow col, lwd to be used for curves with confidence bands
#  - fix some bugs in the legend
#  - added help on source code
# ver. 1.0 May 2007
#  - Version appearing in the BMT paper
#
#
# Usage:
# 
#   CumIncidence(ftime, fstatus, group, t, strata, rho = 0, cencode = 0,
#subset, na.action = na.omit, level, 
#xlab = Time, ylab = Probability, 
#col, lty, lwd, digits = 4)
# 
# Arguments:
# 
# ftime   = failure time variable.
# fstatus = variable with distinct codes for different causes of 
#   failure and also a distinct code for censored observations.
# group   = estimates will be calculated within groups given by distinct
#   values of this variable. Tests will compare these groups. If 
#   missing then treated as all one group (no test statistics).
# t =   a vector of time points where the cumulative incidence function 
#   should be evaluated.
# strata =  stratification variable. Has no effect on estimates. Tests 
#   will be stratified on this variable. (all data in 1 stratum,
#   if missing).
# rho = power of the weight function used in the tests. By default is
#   set to 0.
# cencode = value of fstatus variable which indicates the failure time
#   is censored.
# subset =  a logical vector specifying a subset of cases to include in 
#   the analysis.
# na.action=a function specifying the action to take for any cases 
#   missing any of ftime, fstatus, group, strata, or subset. 
#   By default missing cases are omitted.
# level =   a value in the range [0,1] specifying the level for pointwise
#   confidence bands.
# xlab =text for the x-axis label.
# ylab =text for the y-axis label.
# col = color(s) used for plotting curves (see plot.default).
# lty = line type(s) used for plotting curves (see plot.default).
# lwd = line width(s) used for plotting curves (see plot.default).
# digits =  number of significant digits used for printing values. By 
#   default set at 4.
# 
#

CumIncidence - function(ftime, fstatus, group, t, strata, rho = 0, 
 cencode = 0, subset, na.action = na.omit, 
level,
 xlab = Time, ylab = Probability, 
 col, lty, lwd, digits = 4)
{
  # check for the required package
  if(!require(cmprsk))
{ stop(Package `cmprsk' is required and must be installed.\n 
   See help(install.packages) or write the following command at prompt
   and then follow the instructions:\n
install.packages(\cmprsk\)) } 
  # collect data
  mf  - match.call(expand.dots = FALSE)
  mf[[1]] - as.name(list)
  mf$t - mf$digits - mf$col - mf$lty - mf$lwd - mf$level - 
  mf$xlab - mf$ylab - NULL
  mf - eval(mf, parent.frame())
  g - max(1, length(unique(mf$group)))
  s - length(unique(mf$fstatus))
  if(missing(t)) 
{ time - pretty(c(0, max(mf$ftime)), 6)
  ttime - time - time[time  max(mf$ftime)] }
  else { ttime - time - t }
  # fit model and estimates at time points
  fit   - do.call(cuminc, mf)
  tfit - timepoints(fit, time)
  # print result
  cat(\n+, paste(rep(-, 67), collapse=), +, sep =)
  cat(\n| 

[R] problem with abline

2010-10-06 Thread Gerard Smits
Hi All,

I am running a scatter plot and trying to add a best fit line.  I use an abline 
function, but get no line drawn over the points.  I also get no error.  I arm 
using V 2.10.0 on Windows 7.

Here is my code, including the SAS transport file import:

require (foreign)
require (chron)
require (Hmisc)
require (lattice)

clin  - sasxport.get(y:\\temp\\subset.xpt)
attach(clin)


plot.new()
xyplot(jitter(b.lvef)~jitter(log.fgf), 
   main=Scatter Plot of Baseline Ejection Fraction\nby Log10 FGF-23,
   ylim=c(10,90),
   ylab=Ejection Fraction, xlab=Log10 FGF-23)

abline(lm(b.lvef~log.fgf))

Any suggestions appreciated.

Thanks,

Gerard



[[alternative HTML version deleted]]

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


Re: [R] problem with abline

2010-10-06 Thread Gerard Smits
Hi David,

Just changed to the standard plot from xyplot and it worked fine.  I'll check 
out panel.lmline.

Thanks for your help.

Gerard


On Oct 6, 2010, at 3:27 PM, David Winsemius wrote:

 
 On Oct 6, 2010, at 5:56 PM, Gerard Smits wrote:
 
 Hi All,
 
 I am running a scatter plot and trying to add a best fit line.  I use an 
 abline function, but get no line drawn over the points.
 
 xyplot is Lattice
 abline is base graphics
 
 I also get no error.  I arm using V 2.10.0 on Windows 7.
 
 Here is my code, including the SAS transport file import:
 
 Nope. Read the Posting Guide about attachments to the list. Nice try, though.
 
 
 require (foreign)
 require (chron)
 require (Hmisc)
 require (lattice)
 
 clin  - sasxport.get(y:\\temp\\subset.xpt)
 attach(clin)
 
 
 plot.new()
 xyplot(jitter(b.lvef)~jitter(log.fgf),
  main=Scatter Plot of Baseline Ejection Fraction\nby Log10 FGF-23,
  ylim=c(10,90),
  ylab=Ejection Fraction, xlab=Log10 FGF-23)
 
 Instead consider:
 ?panel.lmline
 
 Perhaps (untested in absence of data):
 
 plot.new()
 xyplot(jitter(b.lvef)~jitter(log.fgf), panel = function(x, y) {
  panel.xyplot(x, y)
   panel.lmline(x,y)
   },
  main=Scatter Plot of Baseline Ejection Fraction\nby Log10 FGF-23,
  ylim=c(10,90),
  ylab=Ejection Fraction, xlab=Log10 FGF-23)
 
 
 
 abline(lm(b.lvef~log.fgf))
 
 Any suggestions appreciated.
 
 Thanks,
 
 Gerard
  [[alternative HTML version deleted]]
 
 
 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] special symbols into a text string

2010-03-14 Thread Gerard Smits
All,

I am trying to put a few special symbols into a string to place on a graph 
(e.g., = and superscript 2).  

This clearly works, but does not look good:   text-c(x2, A=B)

I tried pasting in the = symbol, but just comes out as an =.

I have tried expression() with no luck:  text-c(x2, expression(x^2))

Any help appreciated.

Thanks,

Gerard
[[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] Forestplot () box size question

2009-03-22 Thread Gerard Smits
Yes, my R is a few versions old.  I did not realize that the package 
version was dependent on the R version.  Thanks.  Gerard

PS was able to apply the code suggested by David W. to the 2.14 
version and got it to work.

At 12:32 AM 3/22/2009, Thomas Lumley wrote:
On Sat, 21 Mar 2009, Gerard Smits wrote:

I have tried several sites (2 in Ca and also Australia) and find only
version 2.14.

Which site did you pull 2.15 from?

I have checked half a dozen sites in various countries, and they all 
have 2.15 (even in the Southern Hemisphere -- it's not that updates 
flow the wrong way south of the equator). The CRAN mirror status 
page says that no mirrors are more than a couple of days out of date.

Mostly likely you have an old version of R. CRAN binaries are built 
only for the current version of R.

  -thomas

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



[[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] Forestplot () box size question

2009-03-21 Thread Gerard Smits
Hi All,

I have been able to modify the x-axis to start at zero by adding xlow 
and xhigh parameters; that was pretty simple.  I have been unable to 
find the location of the code that would turn off the information 
weighting of the box size (I have smaller randomized trials getting 
less weight than a much larger non-randomized trial).  The function 
is forestplot() from rmeta.

Thanks for any help.

Gerard

Slightly modified working function with data and a call follows:


fplot=function (labeltext, mean, lower, upper, align = NULL, 
is.summary = FALSE,
 clip = c(-Inf, Inf), xlab = , zero = 1, graphwidth = unit(3,inches),
 col = meta.colors(), xlog = FALSE, xticks = NULL,
 xlow=0, xhigh, digitsize,
 ...)
{
 require(grid)  || stop(`grid' package not found)
 require(rmeta) || stop(`rmeta' package not found)

 drawNormalCI - function(LL, OR, UL, size)
 {

 size = 0.75 * size
 clipupper - convertX(unit(UL, native), npc, valueOnly = TRUE)  1
 cliplower - convertX(unit(LL, native), npc, valueOnly = TRUE)  0
 box - convertX(unit(OR, native), npc, valueOnly = TRUE)
 clipbox - box  0 || box  1

 if (clipupper || cliplower)
 {
 ends - both
 lims - unit(c(0, 1), c(npc, npc))
 if (!clipupper) {
 ends - first
 lims - unit(c(0, UL), c(npc, native))
 }
 if (!cliplower) {
 ends - last
 lims - unit(c(LL, 1), c(native, npc))
 }
 grid.lines(x = lims, y = 0.5, arrow = arrow(ends = ends,
 length = unit(0.05, inches)), gp = gpar(col = col$lines))

 if (!clipbox)
 grid.rect(x = unit(OR, native), width = unit(size,
   snpc), height = unit(size, snpc), gp = 
gpar(fill = col$box,
   col = col$box))
 }
 else {
 grid.lines(x = unit(c(LL, UL), native), y = 0.5,
 gp = gpar(col = col$lines))
 grid.rect(x = unit(OR, native), width = unit(size,
 snpc), height = unit(size, snpc), gp = gpar(fill 
= col$box,
 col = col$box))
 if ((convertX(unit(OR, native) + unit(0.5 * size,
 lines), native, valueOnly = TRUE)  UL) 
 (convertX(unit(OR, native) - unit(0.5 * size,
   lines), native, valueOnly = TRUE)  LL))
 grid.lines(x = unit(c(LL, UL), native), y = 0.5,
   gp = gpar(col = col$lines))
 }

 }

 drawSummaryCI - function(LL, OR, UL, size) {
 grid.polygon(x = unit(c(LL, OR, UL, OR), native), y = unit(0.5 +
 c(0, 0.5 * size, 0, -0.5 * size), npc), gp = gpar(fill 
= col$summary,
 col = col$summary))
 }

 plot.new()
 widthcolumn - !apply(is.na(labeltext), 1, any)
 nc - NCOL(labeltext)
 labels - vector(list, nc)
 if (is.null(align))
 align - c(l, rep(r, nc - 1))
 else align - rep(align, length = nc)
 nr - NROW(labeltext)
 is.summary - rep(is.summary, length = nr)
 for (j in 1:nc) {
 labels[[j]] - vector(list, nr)
 for (i in 1:nr) {
 if (is.na(labeltext[i, j]))
 next
 x - switch(align[j], l = 0, r = 1, c = 0.5)
 just - switch(align[j], l = left, r = right, c = center)
 labels[[j]][[i]] - textGrob(labeltext[i, j], x = x,
 just = just, gp = gpar(fontface = if (is.summary[i]) bold
 else plain, col = rep(col$text, length = nr)[i]))
 }
 }
 colgap - unit(3, mm)
 colwidths - unit.c(max(unit(rep(1, sum(widthcolumn)), grobwidth,
 labels[[1]][widthcolumn])), colgap)
 if (nc  1) {
 for (i in 2:nc) colwidths - unit.c(colwidths, max(unit(rep(1,
 sum(widthcolumn)), grobwidth, labels[[i]][widthcolumn])),
 colgap)
 }
 colwidths - unit.c(colwidths, graphwidth)
 pushViewport(viewport(layout = grid.layout(nr + 1, nc * 2 +
 1, widths = colwidths, heights = unit(c(rep(1, nr), 0.5),
 lines
 cwidth - (upper - lower)

 #xrange - c(max(min(lower, na.rm = TRUE), clip[1]), 
min(max(upper, na.rm = TRUE), clip[2]))
 xrange - c(xlow,xhigh)

 info - 1/cwidth
 info - info/max(info[!is.summary], na.rm = TRUE)
 info[is.summary] - 1

 for (j in 1:nc) {
 for (i in 1:nr) {
 if (!is.null(labels[[j]][[i]])) {
 pushViewport(viewport(layout.pos.row = i, 
layout.pos.col = 2 *
   j - 1))
 grid.draw(labels[[j]][[i]])
 popViewport()
 }
 }
 }

 pushViewport(viewport(layout.pos.col = 2 * nc + 1, xscale = xrange))
 grid.lines(x = unit(zero, native), y = 0:1, gp = gpar(col = col$zero))
 if (xlog) {
 if (is.null(xticks)) {
 ticks - pretty(exp(xrange))
 

Re: [R] Forestplot () box size question

2009-03-21 Thread Gerard Smits
Hi David,

I just checked to make sure I had the latest version.  I see no 
boxsize option in the  forestplot function parameters or any other 
place in the code.

function (labeltext, mean, lower, upper, align = NULL, is.summary = FALSE,
 clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2,
 inches), col = meta.colors(), xlog = FALSE, xticks = NULL,
 ...)
{


Thanks,

Gerard


At 10:32 AM 3/21/2009, David Winsemius wrote:
  if (!is.null(boxsize))
 info - rep(boxsize, length = length(info))

[[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] Forestplot () box size question

2009-03-21 Thread Gerard Smits
Hi David,

I did a general package update, but it must not have been quite as 
complete as I had hoped.

I will make sure I download 2.15 and go from there.

Thanks for you help.

Gerard

At 11:10 AM 3/21/2009, David Winsemius wrote:
Latest version is a tad non-specific. The help page for (my) package
rmeta, version 2.15 (download and compiled today)  says:

Usage
forestplot(labeltext, mean, lower, upper, align = NULL, is.summary =
FALSE, clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2,
inches), col = meta.colors(), xlog = FALSE, xticks=NULL,
boxsize=NULL,...)
--
  sessionInfo()
R version 2.8.1 Patched (2009-01-19 r47650)
i386-apple-darwin9.6.0
locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grid  stats graphics  grDevices utils datasets
methods   base
other attached packages:
[1] rmeta_2.15 zoo_1.5-5
loaded via a namespace (and not attached):
[1] lattice_0.17-20 tools_2.8.1
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
On Mar 21, 2009, at 2:01 PM, Gerard Smits wrote:

Hi David,

I just checked to make sure I had the latest version.  I see no
boxsize option in the  forestplot function parameters or any other
place in the code.

function (labeltext, mean, lower, upper, align = NULL, is.summary =
FALSE,
 clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2,
 inches), col = meta.colors(), xlog = FALSE, xticks = NULL,
 ...)
{


Thanks,

Gerard


At 10:32 AM 3/21/2009, David Winsemius wrote:
  if (!is.null(boxsize))
 info - rep(boxsize, length = length(info))



[[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] Forestplot () box size question

2009-03-21 Thread Gerard Smits
I have tried several sites (2 in Ca and also Australia) and find only 
version 2.14.

Which site did you pull 2.15 from?

Thanks

At 11:10 AM 3/21/2009, David Winsemius wrote:
Latest version is a tad non-specific. The help page for (my) package
rmeta, version 2.15 (download and compiled today)  says:

Usage
forestplot(labeltext, mean, lower, upper, align = NULL, is.summary =
FALSE, clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2,
inches), col = meta.colors(), xlog = FALSE, xticks=NULL,
boxsize=NULL,...)
--
  sessionInfo()
R version 2.8.1 Patched (2009-01-19 r47650)
i386-apple-darwin9.6.0
locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grid  stats graphics  grDevices utils datasets
methods   base
other attached packages:
[1] rmeta_2.15 zoo_1.5-5
loaded via a namespace (and not attached):
[1] lattice_0.17-20 tools_2.8.1
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
On Mar 21, 2009, at 2:01 PM, Gerard Smits wrote:

Hi David,

I just checked to make sure I had the latest version.  I see no
boxsize option in the  forestplot function parameters or any other
place in the code.

function (labeltext, mean, lower, upper, align = NULL, is.summary =
FALSE,
 clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2,
 inches), col = meta.colors(), xlog = FALSE, xticks = NULL,
 ...)
{


Thanks,

Gerard


At 10:32 AM 3/21/2009, David Winsemius wrote:
  if (!is.null(boxsize))
 info - rep(boxsize, length = length(info))



[[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] SAS Institute Adding Support for R

2009-02-13 Thread Gerard Smits
It seems that SAS is willing to offer this  interface if you are 
willing to purchase one of their expensive add-on packages.  Not surprising.

Gerard Smits 
[[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] Modifying forestplot function in rmeta

2009-02-08 Thread Gerard Smits
All,

I am using the forestplot function in rmeta.

I was able to modify the x axis range by commenting out one line and 
feeding it two new parameters (I wanted to set zero as the axis start point).

 #xrange - c(max(min(lower, na.rm = TRUE), clip[1]), 
min(max(upper, na.rm = TRUE), clip[2]))

 #new line
 xrange - c(xlow,xhigh)

Now I am trying to modify the text font size for the elements in 
labeltext and also trying to remove the variability in OR box size, 
which is some function of the width of the lower and upper confidence 
interval boundaries or the OR.

I am a reasonable programer (other than with R), but have not been 
able to decipher what I should be modifying.  Any suggestions will be 
appreciated.

Thanks,

Gerard Smits





At 02:32 PM 9/7/2007, Gerard Smits wrote:
Hi R users,

I have a test dataframe (file1, shown below) for which I am trying 
to create a flag for the first and last ID record (equivalent to SAS 
first.id and last.id variables.

Dump of file1:

  file1
id rx week dv1
1   1  11   1
2   1  12   1
3   1  13   2
4   2  11   3
5   2  12   4
6   2  13   1
7   3  11   2
8   3  12   3
9   3  13   4
10  4  11   2
11  4  12   6
12  4  13   5
13  5  21   7
14  5  22   8
15  5  23   5
16  6  21   2
17  6  22   4
18  6  23   6
19  7  21   7
20  7  22   8
21  8  21   9
22  9  21   4
23  9  22   5

I have written code that correctly assigns the first.id and last.id variabes:

require(Hmisc)  #for Lags
#ascending order to define first dot
file1- file1[order(file1$id, file1$week),]
file1$first.id - (Lag(file1$id) != file1$id)
file1$first.id[1]-TRUE  #force NA to TRUE

#descending order to define last dot
file1- file1[order(-file1$id,-file1$week),]
file1$last.id  - (Lag(file1$id) != file1$id)
file1$last.id[1]-TRUE   #force NA to TRUE

#resort to original order
file1- file1[order(file1$id,file1$week),]



I am now trying to get the above code to work as a function, and am 
clearly doing something wrong:

  first.last - function (df, idvar, sortvars1, sortvars2)
+   {
+   #sort in ascending order to define first dot
+   df- df[order(sortvars1),]
+   df$first.idvar - (Lag(df$idvar) != df$idvar)
+   #force first record NA to TRUE
+   df$first.idvar[1]-TRUE
+
+   #sort in descending order to define last dot
+   df- df[order(-sortvars2),]
+   df$last.idvar  - (Lag(df$idvar) != df$idvar)
+   #force last record NA to TRUE
+   df$last.idvar[1]-TRUE
+
+   #resort to original order
+   df- df[order(sortvars1),]
+   }
 

Function call:

  first.last(df=file1, idvar=file1$id, 
 sortvars1=c(file1$id,file1$week), sortvars2=c(-file1$id,-file1$week))

R Error:

Error in as.vector(x, mode) : invalid argument 'mode'
 

I am not sure about the passing of the sort strings.  Perhaps this 
is were things are off.  Any help greatly appreciated.

Thanks,

Gerard

[[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] product of vector elements

2008-01-12 Thread Gerard Smits
All,

I would like to find a simper method that I now have to find the 
product of all elements  in a vector:

#get product of vector elements: (1,2,3,4,5)
vec.product - exp(sum(log(c(1,2,3,4,5

I have not found a vector product function, if one has been written.

Thanks,

Gerard 
[[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] product of vector elements

2008-01-12 Thread Gerard Smits
Thanks for cumprod() and prod().

I should have tried the help.search first.  Next time 

Gerard

At 04:55 PM 1/12/2008, Gabor Grothendieck wrote:
help.search(product)

On Jan 12, 2008 7:38 PM, Gerard Smits [EMAIL PROTECTED] wrote:
  All,
 
  I would like to find a simper method that I now have to find the
  product of all elements  in a vector:
 
  #get product of vector elements: (1,2,3,4,5)
  vec.product - exp(sum(log(c(1,2,3,4,5
 
  I have not found a vector product function, if one has been written.
 
  Thanks,
 
  Gerard
 [[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] if statement problem

2008-01-01 Thread Gerard Smits
Hi All,

I have a small dataset named das  (43 cases) in which I am trying to 
create a binary outcome (1/0) based on the following code:

if (das$age65  das$bmi30) {das$danger-1} else das$danger-0

I am setting a flag called 'danger' to 1 of the subject is over 65 
and has a BMI  30.

I find that my statement evaluates the first record in the data.frame 
and then carries that assignment for all. I detected this as I played 
around with the values and found that the T/F status of the first 
record was always carried dowqn. I have gotten this to work with an 
elseif construction, but would like to know what is happening here.

Thanks,

Gerard

Using: Windows Vista and R 2.61


Code and output:

das- sasxport.get(c:\\personal\\r\\das.xpt)
if (das$age65  das$bmi30) {das$danger-1} else das$danger-0
attach(das)
das


 The following object(s) are masked from das ( position 3 ) :

  age bmi day id male sex status

   id age sex  bmi status day male danger
1  33001  35   M 27.5  0 3651  0
2  33002  29   M 34.9  1  221  0
3  33003  41   F 23.6  0 3650  0
4  33004  55   F 27.0  0 3650  0
5  42001  37   M 39.0  0 3651  0
6  42002  53   M 26.6  1 1241  0
7  42003  46   F 45.4  1 2870  0
8  42004  35   F 36.2  0 3650  0
9  42005  38   F 24.6  0 3650  0
10 42006  58   F 28.0  0 3650  0
11 42007  27   M 25.0  0 3651  0
12 42008  65   F 24.6  0 3650  0
13 42009  25   F 28.0  0 3650  0
14 43001  66   M 27.8  0 3651  0
15 43002  57   F 34.0  0 3650  0
16 43003  45   F 38.1  0 3650  0
17 43004  33   F 53.3  1  620  0
18 43005  56   F 36.5  0 3650  0
19 43006  31   F 22.4  1   10  0
20 43007  53   F 32.2  1  210  0
21 55001  51   M 29.2  0 3651  0
22 55002  33   F 18.7  0 3650  0
23 55003  40   F 30.3  0 3650  0
24 55004  67   M 31.9  0 3651  0 - Problem case should 
=1 for danger
25 55005  41   F 35.0  0 3650  0
26 55006  44   F 37.3  0 3650  0
27 55007  67   M 28.4  1   11  0
28 55008  65   F 28.8  0 3650  0
29 55009  76   M 18.8  1 2251  0
30 55010  75   F 21.1  1  390  0
31 63001  30   F 24.9  0 3650  0
32 63002  36   F 47.2  1 3770  0
33 63003  45   F 32.0  0 3650  0
34 63004  49   F 32.3  0 3650  0
35 63005  41   F 20.2  0 3650  0
36 63006  60   F 28.2  0 3650  0
37 63007  33   F 24.5  0 3650  0
38 63008  36   F 28.4  1  560  0
39 63009  31   F 22.1  0 3650  0
40 63010  77   M 26.6  1   91  0
41 63011  41   F 32.0  0 3650  0
42 63012  40   F 38.5  1  920  0
43 63013  27   M 20.6  0 3651  0

[[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] if statement problem

2008-01-01 Thread Gerard Smits

Thanks, but I tried the single ampersand, but got a warning msg with 
the same lack of correct assignment:

  if (das$age65  das$bmi30) {das$danger-1} else das$danger-0
Warning message:
In if (das$age  65  das$bmi  30) { :
   the condition has length  1 and only the first element will be used
  attach(das)

 The following object(s) are masked from das ( position 3 ) :

  age bmi day id male sex status

  das
   id age sex  bmi status day male danger
1  33001  35   M 27.5  0 3651  0
2  33002  29   M 34.9  1  221  0
3  33003  41   F 23.6  0 3650  0
4  33004  55   F 27.0  0 3650  0
5  42001  37   M 39.0  0 3651  0
6  42002  53   M 26.6  1 1241  0
7  42003  46   F 45.4  1 2870  0
8  42004  35   F 36.2  0 3650  0
9  42005  38   F 24.6  0 3650  0
10 42006  58   F 28.0  0 3650  0
11 42007  27   M 25.0  0 3651  0
12 42008  65   F 24.6  0 3650  0
13 42009  25   F 28.0  0 3650  0
14 43001  66   M 27.8  0 3651  0
15 43002  57   F 34.0  0 3650  0
16 43003  45   F 38.1  0 3650  0
17 43004  33   F 53.3  1  620  0
18 43005  56   F 36.5  0 3650  0
19 43006  31   F 22.4  1   10  0
20 43007  53   F 32.2  1  210  0
21 55001  51   M 29.2  0 3651  0
22 55002  33   F 18.7  0 3650  0
23 55003  40   F 30.3  0 3650  0
24 55004  67   M 31.9  0 3651  0 -
25 55005  41   F 35.0  0 3650  0
26 55006  44   F 37.3  0 3650  0
27 55007  67   M 28.4  1   11  0
28 55008  65   F 28.8  0 3650  0
29 55009  76   M 18.8  1 2251  0
30 55010  75   F 21.1  1  390  0
31 63001  30   F 24.9  0 3650  0
32 63002  36   F 47.2  1 3770  0
33 63003  45   F 32.0  0 3650  0
34 63004  49   F 32.3  0 3650  0
35 63005  41   F 20.2  0 3650  0
36 63006  60   F 28.2  0 3650  0
37 63007  33   F 24.5  0 3650  0
38 63008  36   F 28.4  1  560  0
39 63009  31   F 22.1  0 3650  0
40 63010  77   M 26.6  1   91  0
41 63011  41   F 32.0  0 3650  0
42 63012  40   F 38.5  1  920  0
43 63013  27   M 20.6  0 3651  0



At 02:11 PM 1/1/2008, Christos Hatzis wrote:
You need to use '' instead of '':

A shorter version of your code using ifelse:

das$danger - with(das, ifelse(age65  bmi30, 1, 0))

HTH

-Christos

  -Original Message-
  From: [EMAIL PROTECTED]
  [mailto:[EMAIL PROTECTED] On Behalf Of Gerard Smits
  Sent: Tuesday, January 01, 2008 5:04 PM
  To: r-help@r-project.org
  Subject: [R] if statement problem
 
  Hi All,
 
  I have a small dataset named das  (43 cases) in which I am
  trying to create a binary outcome (1/0) based on the following code:
 
  if (das$age65  das$bmi30) {das$danger-1} else das$danger-0
 
  I am setting a flag called 'danger' to 1 of the subject is
  over 65 and has a BMI  30.
 
  I find that my statement evaluates the first record in the
  data.frame and then carries that assignment for all. I
  detected this as I played around with the values and found
  that the T/F status of the first record was always carried
  dowqn. I have gotten this to work with an elseif
  construction, but would like to know what is happening here.
 
  Thanks,
 
  Gerard
 
  Using: Windows Vista and R 2.61
 
 
  Code and output:
 
  das- sasxport.get(c:\\personal\\r\\das.xpt)
  if (das$age65  das$bmi30) {das$danger-1} else das$danger-0
  attach(das)
  das
 
 
   The following object(s) are masked from das ( position 3 ) :
 
age bmi day id male sex status
 
 id age sex  bmi status day male danger
  1  33001  35   M 27.5  0 3651  0
  2  33002  29   M 34.9  1  221  0
  3  33003  41   F 23.6  0 3650  0
  4  33004  55   F 27.0  0 3650  0
  5  42001  37   M 39.0  0 3651  0
  6  42002  53   M 26.6  1 1241  0
  7  42003  46   F 45.4  1 2870  0
  8  42004  35   F 36.2  0 3650  0
  9  42005  38   F 24.6  0 3650  0
  10 42006  58   F 28.0  0 3650  0
  11 42007  27   M 25.0  0 3651  0
  12 42008  65   F 24.6  0 3650  0
  13 42009  25   F 28.0  0 3650  0
  14 43001  66   M 27.8  0 3651  0
  15 43002  57   F 34.0  0 3650  0
  16 43003  45   F 38.1  0 3650  0
  17 43004  33   F 53.3  1  620  0
  18 43005  56   F 36.5  0 3650  0
  19 43006  31   F 22.4  1   10  0
  20 43007  53   F 32.2  1  210  0
  21 55001  51   M 29.2  0 3651  0
  22 55002  33   F 18.7  0 3650  0
  23 55003  40   F 30.3  0 3650  0
  24 55004  67   M 31.9  0 3651  0

Re: [R] if statement problem

2008-01-01 Thread Gerard Smits
Hi Domenico,

I was incorrectly assuming it would use a vector of equal length to 
my data. frame.  Thanks for the clarification.

Also, thanks for the many alternate programming approaches provided by others.

Gerard

At 02:25 PM 1/1/2008, Domenico Vistocco wrote:
You should look for your answer using the help for the if statement (?if).
The cond argument should be a scalar (otherwise only the first 
element is used).

?if
.
cond: A length-one logical vector that is not 'NA'. Conditions of
  length greater than one are accepted with a warning, but only
  the first element is used.  Other types are coerced to
  logical if possible, ignoring any class.
...

The ifelse statement check the condition for each element of your 
input (returning
a value with the same shape).

domenico

Gerard Smits wrote:
Hi All,

I have a small dataset named das  (43 cases) in which I am trying 
to create a binary outcome (1/0) based on the following code:

if (das$age65  das$bmi30) {das$danger-1} else das$danger-0

I am setting a flag called 'danger' to 1 of the subject is over 65 
and has a BMI  30.

I find that my statement evaluates the first record in the 
data.frame and then carries that assignment for all. I detected 
this as I played around with the values and found that the T/F 
status of the first record was always carried dowqn. I have gotten 
this to work with an elseif construction, but would like to know 
what is happening here.

Thanks,

Gerard

Using: Windows Vista and R 2.61


Code and output:

das- sasxport.get(c:\\personal\\r\\das.xpt)
if (das$age65  das$bmi30) {das$danger-1} else das$danger-0
attach(das)
das


  The following object(s) are masked from das ( position 3 ) :

   age bmi day id male sex status

id age sex  bmi status day male danger
1  33001  35   M 27.5  0 3651  0
2  33002  29   M 34.9  1  221  0
3  33003  41   F 23.6  0 3650  0
4  33004  55   F 27.0  0 3650  0
5  42001  37   M 39.0  0 3651  0
6  42002  53   M 26.6  1 1241  0
7  42003  46   F 45.4  1 2870  0
8  42004  35   F 36.2  0 3650  0
9  42005  38   F 24.6  0 3650  0
10 42006  58   F 28.0  0 3650  0
11 42007  27   M 25.0  0 3651  0
12 42008  65   F 24.6  0 3650  0
13 42009  25   F 28.0  0 3650  0
14 43001  66   M 27.8  0 3651  0
15 43002  57   F 34.0  0 3650  0
16 43003  45   F 38.1  0 3650  0
17 43004  33   F 53.3  1  620  0
18 43005  56   F 36.5  0 3650  0
19 43006  31   F 22.4  1   10  0
20 43007  53   F 32.2  1  210  0
21 55001  51   M 29.2  0 3651  0
22 55002  33   F 18.7  0 3650  0
23 55003  40   F 30.3  0 3650  0
24 55004  67   M 31.9  0 3651  0 - Problem case should 
=1 for danger
25 55005  41   F 35.0  0 3650  0
26 55006  44   F 37.3  0 3650  0
27 55007  67   M 28.4  1   11  0
28 55008  65   F 28.8  0 3650  0
29 55009  76   M 18.8  1 2251  0
30 55010  75   F 21.1  1  390  0
31 63001  30   F 24.9  0 3650  0
32 63002  36   F 47.2  1 3770  0
33 63003  45   F 32.0  0 3650  0
34 63004  49   F 32.3  0 3650  0
35 63005  41   F 20.2  0 3650  0
36 63006  60   F 28.2  0 3650  0
37 63007  33   F 24.5  0 3650  0
38 63008  36   F 28.4  1  560  0
39 63009  31   F 22.1  0 3650  0
40 63010  77   M 26.6  1   91  0
41 63011  41   F 32.0  0 3650  0
42 63012  40   F 38.5  1  920  0
43 63013  27   M 20.6  0 3651  0

 [[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] applying math/stat functions to rows in data frame

2007-09-17 Thread Gerard Smits
Hi all,

Thanks for the suggestions. I have not yet tried the apply () 
approach, but have tried to get the indexed version working, so far 
with limited success.  I realize that a transpose, as suggested, 
would work, but want to avoid that for something simpler.

To repeat, the task is to perform a function on N rows (all numeric) 
in a data frame.  I can use rowMeans, rowSums, pmin, and pmax to 
successfully average, sum, and find the min/max var1-var4).  But If I 
try to get the mean (var5) using, no doubt the incorrect syntax: 
mean(df[,c(4,5,6,7)], na.rm=T), I do not get the mean of 4 column.  I 
am not sure what is being returned as a value.

I summarize the code below with the output: any further suggestions 
are appreciated,

Thanks Gerard


Code with output:

  df - read.table(textConnection(id,workshop,gender,q1,q2,q3,q4
+ 1,1,f,1,1,5,1
+ 2,2,f,2,1,4,1
+ 3,1,f,2,2,4,3
+ 4,2,f,3,1, ,3
+ 5,1,m,4,5,2,4
+ 6,2,m,5,4,5,5
+ 7,1,m,5,3,4,4
+ 8,2,m,4,5,5,5), header=TRUE, sep=,)
 
  attach(df)
 
  df$var1-rowMeans(cbind(q1,q2,q3,q4),na.rm=T)
  df$var2-rowSums (cbind(q1,q2,q3,q4),na.rm=T)
  df$var3-pmin(q1,q2,q3,q4, na.rm=T)
  df$var4-pmax(q1,q2,q3,q4, na.rm=T)
 
  df$var5-mean(df[,c(4,5,6,7)],na.rm=T)  #not doing what I want
  df$var6-sd  (df[,c(4,5,6,5)],na.rm=T)  #not doing what I want
  df$var7-min (df[,c(4,5,6,5)],na.rm=T)  #not doing what I want
  df$var8-max (df[,c(4,5,6,5)],na.rm=T)  #not doing what I want
 
  df


output with problem vars underlined:

   id workshop gender q1 q2 q3 q4 var1 var2 var3 
var4 var5 var6 var7 var8
1  11  f  1  1  5  1 2.00815 3.25 
1.48804815
2  22  f  2  1  4  1 2.00814 2.75 
1.75254915
3  31  f  2  2  4  3 2.75   1124 4.142857 
1.06904515
4  42  f  3  1 NA  3 2.33713 3.25 
1.75254915
5  51  m  4  5  2  4 3.75   1525 3.25 
1.48804815
6  62  m  5  4  5  5 4.75   1945 2.75 
1.75254915
7  71  m  5  3  4  4 4.00   1635 4.142857 
1.06904515
8  82  m  4  5  5  5 4.75   1945 3.25 
1.75254915
 

[[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] applying math/stat functions to rows in data frame

2007-09-15 Thread Gerard Smits
Hi All,

There are a variety of functions that can be applied to a variable 
(column) in a data frame: mean, min, max, sd, range, IQR, etc.

I am aware of only two that work on the rows, using q1-q3 as example 
variables:

rowMeans(cbind(q1,q2,q3),na.rm=T)   #mean of multiple variables
rowSums (cbind(q1,q2,q3),na.rm=T)   #sum of multiple variables

Can the standard column functions (listed in the first sentence) be 
applied to rows, with the use of correct indexes to reference the 
columns of interest?  Or, must these summary functions be programmed 
separately to work on a row?

Thanks,

Gerard



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