On Feb 4, 2011, at 4:24 PM, Mcmahon, Kwyatt wrote:
> Hello compadRes,
>
> I'm developing a script that selects "cells" over a certain
> metabolic rate to kill them. A rate between 9 and 12 means that the
> cells are candidates for death.
>
> I'll show you what I mean:
>
> # a would be a vector of cell metabolic rates.
> a<-c(8, 7, 9, 6, 10, 11, 4, 5, 6)
>
> #now identify which cells will be candidates for death, namely those
> cells with metabolic rates>9
> b<-a[a>6]
> #This would select all cells with rates >6
> rbinom(length(b), size=1, prob=1)
No, you have an overly complex way of generating a vector of all 1's
with length(b). And it's not clear what you mean by "select". I
see no
caode that would do any selection or indexing.
>
> #This will select cells using a an exponential probability
> distribution
> rbinom(length(b), size=1, prob=(seq(0, 1, by=0.1)^2))
Again no selection appears to be taking place.
>
> I have two questions:
>
> 1) Am I correct in my interpretations?
>
> 2) I'd actually like to have this probability scaled so that
> cells with rates of 9 are unlikely to be selected and those near 12
> are highly likely. How can I code this?
a[ sample(1:length(a), prob=0.1+(a>9) ,replace=TRUE) ]
[1] 10 10 11 10 10 11 10 11 10
> a[sample(1:length(a), prob=0.1+(a>9) ,replace=TRUE) ]
[1] 10 10 11 11 11 11 5 10 10
The "rates" over 9 are 11 times (= 1.1/0.1) as likely to be selected.
You can adjust the ratio by altering the 0.1 value."+" with the first
argument numeric act to coerce the logical vector to 1's and 0's.
--
David.
>
> Thanks in advance,
>
> Wyatt
>
>> sessionInfo()
> R version 2.11.1 (2010-05-31)
> i386-pc-mingw32
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> loaded via a namespace (and not attached):
> [1] tools_2.11.1
>
>
>
> K. Wyatt McMahon, Ph.D.
> Postdoctoral Research Associate
> Department of Internal Medicine
> 3601 4th St. - Lubbock, TX - 79430
> P: 806-743-4072
> F: 806-743-3148
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT