Re: [R] Sampling the Distance Matrix

2015-09-25 Thread David Winsemius
On Sep 25, 2015, at 12:54 PM, Lorenzo Isella wrote: > Apologies for not letting this thread rest in peace. > The small script > > # > set.seed(1234) > > x <- rnorm(20) > y <- rnorm(20) > > > goodcls <- apply(mtxcomb , 2, function(idx) al

Re: [R] Sampling the Distance Matrix

2015-09-25 Thread Lorenzo Isella
Apologies for not letting this thread rest in peace. The small script # set.seed(1234) x <- rnorm(20) y <- rnorm(20) goodcls <- apply(mtxcomb , 2, function(idx) all( dist( cbind( x[idx], y[idx]) ) > 0.9)) mycomb <- mtxcomb [ , goodcls] #

Re: [R] Sampling the Distance Matrix

2015-09-25 Thread Lorenzo Isella
lt;-(dist(mm)) - David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Thursday, September 24, 2015 6:30 PM To: Lorenzo Isella Cc: David L Carlson; r-help@r-project.org

Re: [R] Sampling the Distance Matrix

2015-09-25 Thread David L Carlson
-Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Thursday, September 24, 2015 6:30 PM To: Lorenzo Isella Cc: David L Carlson; r-help@r-project.org Subject: Re: [R] Sampling the Distance Matrix On Sep 24, 2015, at 1:54 PM, Lorenzo Isella wrote: > On

Re: [R] Sampling the Distance Matrix

2015-09-24 Thread David Winsemius
On Sep 24, 2015, at 1:54 PM, Lorenzo Isella wrote: > On Thu, Sep 24, 2015 at 01:30:02PM -0700, David Winsemius wrote: >> >> On Sep 24, 2015, at 12:36 PM, Lorenzo Isella wrote: >> >>> Hi, >>> And thanks for your reply. >>> Essentially, your script gets the job done. >>> For instance, if I run >>

Re: [R] Sampling the Distance Matrix

2015-09-24 Thread Lorenzo Isella
On Thu, Sep 24, 2015 at 01:30:02PM -0700, David Winsemius wrote: On Sep 24, 2015, at 12:36 PM, Lorenzo Isella wrote: Hi, And thanks for your reply. Essentially, your script gets the job done. For instance, if I run mm <- cbind(5/(1:5), -2*sqrt(1:5)) dst <- dist(mm) dst2 <- as.matrix(dst) diag

Re: [R] Sampling the Distance Matrix

2015-09-24 Thread David Winsemius
>>13 18 19 >> 13 NA 2.272407 3.606054 >> 18 2.272407 NA 1.578150 >> 19 3.606054 1.578150 NA >> >> - >> David L Carlson >> Department of Anthropology >> Texas A&M Univers

Re: [R] Sampling the Distance Matrix

2015-09-24 Thread Lorenzo Isella
p-boun...@r-project.org] On Behalf Of William Dunlap Sent: Wednesday, September 23, 2015 3:23 PM To: Lorenzo Isella Cc: r-help@r-project.org Subject: Re: [R] Sampling the Distance Matrix mm <- cbind(1/(1:5), sqrt(1:5)) d <- dist(mm) d 1 2 3 4 2 0.6492864

Re: [R] Sampling the Distance Matrix

2015-09-23 Thread David L Carlson
-Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of William Dunlap Sent: Wednesday, September 23, 2015 3:23 PM To: Lorenzo Isella Cc: r-help@r-project.org Subject: Re: [R] Sampling the Distance Matrix > mm <- cbind(1/(1:5), sqrt(1:5)) > d <- dist

Re: [R] Sampling the Distance Matrix

2015-09-23 Thread William Dunlap
> mm <- cbind(1/(1:5), sqrt(1:5)) > d <- dist(mm) > d 1 2 3 4 2 0.6492864 3 0.9901226 0.3588848 4 1.250 0.6369033 0.2806086 5 1.4723668 0.8748970 0.5213550 0.2413050 > which(as.matrix(d)>0.9, arr.ind=TRUE) row col 3 3 1 4 4 1 5 5 1 1 1 3 1 1

[R] Sampling the Distance Matrix

2015-09-23 Thread Lorenzo Isella
Dear All, Suppose you have a distance matrix stored like a dist object, for instance x<-rnorm(20) y<-rnorm(20) mm<-as.matrix(cbind(x,y)) dst<-(dist(mm)) Now, my problem is the following: I would like to get the rows of mm corresponding to points whose distance is always larger of, let's say, 0

Re: [R] sampling rows with values never sampled before

2015-06-23 Thread Jon Skoien
If df is the data.frame with values and you want nn samples, then this is a slightly different approach: # example data.frame: df = data.frame(a1 = sample(1:20,50, replace = TRUE), a2 = sample(seq(0.1,10,length.out = 30),50, replace = TRUE),

Re: [R] sampling rows with values never sampled before

2015-06-22 Thread C W
Hi Jean, Thanks! Daniel, Yes, you are absolutely right. I want sampled vectors to be as different as possible. I added a little more to the earlier data set. x1 x2 x3 [1,] 1 3.7 2.1 [2,] 2 3.7 5.3 [3,] 3 3.7 6.2 [4,] 4 3.7 8.9 [5,] 5 3.7 4.1 [6,] 1 2.9 2.1 [7,] 2 2

Re: [R] sampling rows with values never sampled before

2015-06-22 Thread Daniel Nordlund
On 6/22/2015 9:42 AM, C W wrote: Hello R list, I am have question about sampling unique coordinate values. Here's how my data looks like dat <- cbind(x1 = rep(1:5, 3), x2 = rep(c(3.7, 2.9, 5.2), each=5)) dat x1 x2 [1,] 1 3.7 [2,] 2 3.7 [3,] 3 3.7 [4,] 4 3.7 [5,] 5 3.7

Re: [R] sampling rows with values never sampled before

2015-06-22 Thread Adams, Jean
Mike, There may be a more efficient way to do this, but this works on your example. # mix up the order of the rows mix <- dat[order(runif(dim(dat)[1])), ] # get rid of duplicate x1s and x2s sub <- mix[!duplicated(mix[, "x1"]) & !duplicated(mix[, "x2"]), ] sub Jean On Mon, Jun 22, 2015 at 11:42

[R] sampling rows with values never sampled before

2015-06-22 Thread C W
Hello R list, I am have question about sampling unique coordinate values. Here's how my data looks like > dat <- cbind(x1 = rep(1:5, 3), x2 = rep(c(3.7, 2.9, 5.2), each=5)) > dat x1 x2 [1,] 1 3.7 [2,] 2 3.7 [3,] 3 3.7 [4,] 4 3.7 [5,] 5 3.7 [6,] 1 2.9 [7,] 2 2.9 [8,] 3 2.9

Re: [R] Sampling

2015-03-29 Thread Daniel Nordlund
On 3/29/2015 11:10 PM, Partha Sinha wrote: I have 1000 data points. i want to take 30 samples and find mean. I also want to repeat this process 100 times. How to go about it? Regards Parth __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and mor

[R] Sampling

2015-03-29 Thread Partha Sinha
I have 1000 data points. i want to take 30 samples and find mean. I also want to repeat this process 100 times. How to go about it? Regards Parth __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/

Re: [R] sampling dataframe based upon number of record occurrences

2015-03-04 Thread Curtis Burkhalter
d))),] > } > > Now take the samples and combine them into a single data frame: > > sample <- do.call(rbind, lapply(dta.list, smp)) > sample > > - > David L Carlson > Department of Anthropology > Texas A&M University > Colle

Re: [R] sampling dataframe based upon number of record occurrences

2015-03-04 Thread JS Huang
Since you indicated there are six more columns in the data.frame, getSample modified below to take care of it. > getSample function(x) { sites <- unique(x$SiteID) years <- unique(x$Year) result <- data.frame() x$ID <- seq(1,nrow(x)) for (i in 1:length(sites)) { for (j in 1:length(y

Re: [R] sampling dataframe based upon number of record occurrences

2015-03-04 Thread JS Huang
Here is an implementation with function named getSample. Some modification to the data was made so that it can be read as a table. > fitting.set IDbyYear SiteID Year 1 42.24 A-Airport 2006 2 42.24 A-Airport 2006 3 42.24 A-Airport 2006 4 42.

Re: [R] sampling dataframe based upon number of record occurrences

2015-03-04 Thread David L Carlson
versity College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Curtis Burkhalter Sent: Tuesday, March 3, 2015 3:23 PM To: r-help@r-project.org Subject: [R] sampling dataframe based upon number of record occurrences Hello everyone, I&#x

[R] sampling dataframe based upon number of record occurrences

2015-03-03 Thread Curtis Burkhalter
Hello everyone, I'm having trouble performing a task that is probably very simple, but can't seem to figure out how to get my code to work. What I want to do is use the sample function to pick records within in a dataframe, but only if a column attribute value is repeated more than 3 times. So if

Re: [R] Sampling according to type

2014-03-05 Thread Suzen, Mehmet
> myProbs[ which(ntype == 0)] <- 0.75/7 # Divide so the sum will be 1.0 > myProbs[ which(ntype == 1)] <- 0.25/3 Here of course you need to divide by number of 0s and 1s, 7 and 3 were was just an example. __ R-help@r-project.org mailing list https://sta

Re: [R] Sampling according to type

2014-03-05 Thread Suzen, Mehmet
If I understood correctly, you need weighted sampling. Try 'prob' argument from 'sample'. For your example: n <- 10 ntype <- rbinom(n, 1, 0.5) myProbs <- rep(1/10, 10) # equally likely myProbs[ which(ntype == 0)] <- 0.75/7 # Divide so the sum will be 1.0 myProbs[ which(ntype == 1)] <- 0.25/3 samp

[R] Sampling according to type

2014-03-05 Thread Thomas
I have a matrix where each entry represents a data subject's type, 1 or 0: n <- 10 ntype <- rbinom(n, 1, 0.5) and I'd like to sample say 3 subjects from ntype where those subjects who are Type 1 are selected with probability say 0.75, and Type 0 with (1-0.75). (So the sample would produce

Re: [R] Sampling question

2013-11-05 Thread arun
Hi, You may try: dat1 <- structure(list(SubID = 1:8, CSE1 = c(6L, 6L, 5L, 5L, 5L, 5L, 3L, 3L), CSE2 = c(5L, 4L, 5L, 4L, 6L, 4L, 6L, 6L), CSE3 = c(6L, 7L, 5L, 3L, 7L, 3L, 6L, 6L), CSE4 = c(2L, 2L, 5L, 4L, 5L, 6L, 3L, 3L), WSE1 = c(6L, 6L, 5L, 4L, 6L, 4L, 6L, 6L), WSE2 = c(2L, 6L, 5L, 4L, 4L, 3L

Re: [R] Sampling Weights and lmer() update?

2013-05-14 Thread Thomas Lumley
Arguably you are looking in the wrong place (there's a special mixed-models mailing list for R), but I can answer the question. No. At least, there's nothing in lme4, and I haven't done anything (since I want a more general solution than Stata and MLWiN implement) and I'd be surprised if someone

[R] Sampling Weights and lmer() update?

2013-05-13 Thread Richard Blissett
Perhaps I am not looking in the right place, but I am looking for a way to use lmer() to run a multilevel model that incorporates sampling weights. I have used the Lumley survey package to use sampling weights in the past, but according to post I found online from Thomas Lumley in mid-2012, R is cu

Re: [R] Sampling data without having infinite numbers after diong a transformation

2012-12-25 Thread Jeff Newmiller
Perhaps you should read the help file for rnorm more carefully. ?rnorm Keep in mind that the normal probability distribution is a density function, so the smaller the standard deviation is, the greater the magnitude of the density function is. --

[R] Sampling data without having infinite numbers after diong a transformation

2012-12-25 Thread Agnes Ayang
Hello R-helpers.. I want to ask about how I can sample data sets without having the infinite numbers coming out. For example, set.seed(1234) a<-rnorm(15,0,1) b<-rnorm(15,0,1) c<-rnorm(15,0,1) d<-rnorm(15,0,36) After come out with the sample, I need to do a transformation (by Hoaglin, 1985) f

Re: [R] Sampling from a Population

2012-12-08 Thread R. Michael Weylandt
Hi Lorenzo, This has the feel of a homework problem, but I will suggest to you that this is "sampling without replacement" and there exist easy mathematical formulas (no need to resort to R) to calculate your desired probability. Michael On Sat, Dec 8, 2012 at 11:54 AM, Lorenzo Isella wrote: >

[R] Sampling from a Population

2012-12-08 Thread Lorenzo Isella
Dear All, I hope this is not too off topic, but I am sure it has to be a one-liner in R. Suppose you have a population of size N and that you take a random sample of n_s individuals out of this population. This population includes a subgroup of n_i individuals. For any individual in n_i, what

Re: [R] sampling weights for multilevel models

2012-06-10 Thread Tamara
Thank you very much, Thomas! As I need to estimate the variance components, I will most probably have to switch from R to HLM or Mplus to apply different weights to different levels. Although I prefer R in general. -- View this message in context: http://r.789695.n4.nabble.com/sampling-weights-

Re: [R] sampling weights for multilevel models

2012-06-10 Thread Tamara
Thank you very much, Rui! But I am afraid that I won't be able to use this function for multilevel analysis, as unfortunately I don't see how exactly I will combine it with functions in the R packages for multilevel analysis . -- View this message in context: http://r.789695.n4.nabble.com/samplin

Re: [R] sampling weights for multilevel models

2012-06-10 Thread Thomas Lumley
On Mon, Jun 11, 2012 at 7:00 AM, Tamara wrote: > Dear all, > > I am struggling with a problem which I have been reading on the forums about > and it did not seem to me that there is a precise answer to my question. > However, I still hope there is one. > > I am working with  http://timss.bc.edu/ P

Re: [R] sampling weights for multilevel models

2012-06-10 Thread Rui Barradas
Hello, The link you've posted is to a page that does NOT have a dataset, it has links to other pages. The proper way of posting a data example would be # paste the output of this in a post dput(head(yourdata, 20)) # or 30 Now, if I understand your question, function sample() does have a we

[R] sampling weights for multilevel models

2012-06-10 Thread Tamara
Dear all, I am struggling with a problem which I have been reading on the forums about and it did not seem to me that there is a precise answer to my question. However, I still hope there is one. I am working with http://timss.bc.edu/ PIRLS data and trying to conduct multilevel analysis. Ther

Re: [R] sampling rows from a list

2012-04-02 Thread Justin Haynes
## recreating your data mydata<-list(matrix(1:9, nrow=3, byrow=T), matrix(10:15, nrow=2, byrow=T), matrix(16:30, nrow=5, byrow=T)) ## get the shortest matrix in your list n <- min(unlist(lapply(mydata, nrow))) ## subset the list into random samples of length n

Re: [R] sampling rows from a list

2012-04-02 Thread Bert Gunter
?? Something like: lapply(mydata, function(x){ nr <- nrow(x) x[sample(seq_len(nr),nr,rep=TRUE),] }) maybe. The idea is to use the sampled rows as your row index. -- Bert On Mon, Apr 2, 2012 at 11:24 AM, Bcampbell99 wrote: > Hi: > > I'm sure this seems like a rudimentary question, but I am n

[R] sampling rows from a list

2012-04-02 Thread Bcampbell99
Hi: I'm sure this seems like a rudimentary question, but I am not well versed with R syntax for lists. I have a ragged array from which I've removed records (entire rows) with missing data. The functions I used to remove the missing cases resulted in the generation of an R list class object, tha

[R] sampling matrix 1 conditional on values in matrix 2

2012-03-26 Thread John.Morrongiello
Hi I am trying to estimate bottom temperatures over a particular depth range, based on one dataset containing synthetic temperature profiles (for set depths) and another that contains information on bathymetry. I need to do this for multiple regions and thus would ideally like an automated solut

Re: [R] Sampling problems

2012-03-08 Thread R. Michael Weylandt
Please use dput() to give a reproducible example: I can make this work on a data frame quite easily -- x <- data.frame(1:10, letters[1:10], rnorm(10)) str(x) print(x) x[sample(nrow(x), 5), ] So it's not a problem with something being a data frame or having factors. Michael On Thu, Mar 8, 2012 a

Re: [R] Sampling problems

2012-03-08 Thread Oritteropus
Thanks, but it doesn't work either, it gives me the same message error. It works just if my first sample is taken in this way: mysample <- sample(1:nrow(MeanA), 20, replace=FALSE) However, in this way it sample just the number of rows: [1] 71 24 12 36 2 39 69 62 43 38 9 44 13 54 50 63 67 66 3

Re: [R] Sampling problems

2012-03-08 Thread Petr PIKAL
> > Hi, thank you but it does work for vectors and matrix but not dataframes, it > gives me this message error: > > MeanA <- read.csv("MeanAmf.csv",header=T) > mysample <- MeanA[sample(1:nrow(MeanA), 20, replace=FALSE),] Well, maybe slight correction mysample <- sample(1:nrow(MeanA), 20, repla

Re: [R] Sampling problems

2012-03-08 Thread Petr PIKAL
Hi I have only faint idea what was you problem as there is no context in you message but maybe remainder<-MeanA[-mysample, ] could work. Regards Petr > > Hi, thank you but it does work for vectors and matrix but not dataframes, it > gives me this message error: > > MeanA <- read.csv("MeanA

Re: [R] Sampling problems

2012-03-08 Thread Oritteropus
Hi sarah, it is not clear to me how to do that, can you show me please? Imagine I have a situation like this: MeanA <- read.csv("MeanAmf.csv",header=T) mysample <- MeanA[sample(1:nrow(MeanA), 20, replace=FALSE),] Then? -- View this message in context: http://r.789695.n4.nabble.com/Sampling-pr

Re: [R] Sampling problems

2012-03-08 Thread Oritteropus
Hi, thank you but it does work for vectors and matrix but not dataframes, it gives me this message error: MeanA <- read.csv("MeanAmf.csv",header=T) mysample <- MeanA[sample(1:nrow(MeanA), 20, replace=FALSE),] remainder<-MeanA[-mysample] Error in `[.default`(MeanA, -mysample) : invalid subscript ty

Re: [R] Sampling problems

2012-03-07 Thread David Winsemius
On Mar 7, 2012, at 11:41 AM, Oritteropus wrote: Hi, I need to sample randomly my dataset for 1000 times. The sample need to be the 80%. I know how to do that, my problem is that not only I need the 80%, but I also need the corresponding 20% each time. Is there any way to do that? Alterna

Re: [R] Sampling problems

2012-03-07 Thread Petr Savicky
On Wed, Mar 07, 2012 at 08:41:35AM -0800, Oritteropus wrote: > Hi, > I need to sample randomly my dataset for 1000 times. The sample need to be > the 80%. I know how to do that, my problem is that not only I need the 80%, > but I also need the corresponding 20% each time. Is there any way to do > t

Re: [R] Sampling problems

2012-03-07 Thread Sarah Goslee
You could make a vector containing the number of TRUE values that makes up 80% of your data, and the number of FALSE values that makes up 20% of your data. Use sample() to reorder it, then use it to divide your dataset. If you had provided a reproducible example, I could write you code. Sarah On

[R] Sampling problems

2012-03-07 Thread Oritteropus
Hi, I need to sample randomly my dataset for 1000 times. The sample need to be the 80%. I know how to do that, my problem is that not only I need the 80%, but I also need the corresponding 20% each time. Is there any way to do that? Alternatively, I was thinking to something like setdiff () functio

Re: [R] Sampling with Constraints for testing and training data

2012-01-25 Thread Petr Savicky
On Wed, Jan 25, 2012 at 04:00:27AM -0800, Eliano wrote: > Hi People, > > Does anyone have a good solution for this problem: > > a database called DB. > > > index <- sample(1:nrow(DB), size=0.2*nrow(BD)) > test <- DB[index,] > train <- DB[-index,] > > One of the variables in this database

Re: [R] Sampling with Constraints for testing and training data

2012-01-25 Thread Eliano
Hi People, Does anyone have a good solution for this problem: a database called DB. index <- sample(1:nrow(DB), size=0.2*nrow(BD)) test <- DB[index,] train <- DB[-index,] One of the variables in this database contais a target variable with two values 0 and 1. Imagine now that i want to

[R] Sampling with Constraints for testing and training data

2012-01-24 Thread Eliano
Hi People, Thus anyone have a good solution for this problem: a database called DB. index <- sample(1:nrow(DB), size=0.2*nrow(BD)) test <- DB[index,] train <- DB[-index,] One of the variables in this database contais a target variable with two values 0 and 1. Imagine now that i want to constr

Re: [R] sampling weights in package lme4

2012-01-24 Thread peter dalgaard
On Jan 24, 2012, at 20:41 , Thomas Lumley wrote: > It's not meant for sampling weights. It's meant for precision > weights. How best to include sampling weights in mixed models is a > research problem at the moment, but you can rely on getting the wrong > answer if you just use the weights= arg

Re: [R] sampling weights in package lme4

2012-01-24 Thread Thomas Lumley
On Tue, Jan 24, 2012 at 6:19 PM, Mohd masood wrote: > > Dear All > I am trying to include sampling weights in multilavel regression analysis > using packege lme4 using following codes > > print(fm1 <- lmer(DC~sex+age+smoker+alcohol+fruits(1|setting), > dataset,REML = FALSE), corr = FALSE) > prin

[R] sampling weights in package lme4

2012-01-24 Thread Mohd masood
Dear All I am trying to include sampling weights in multilavel regression analysis using packege lme4 using following codes print(fm1 <- lmer(DC~sex+age+smoker+alcohol+fruits(1|setting), dataset,REML = FALSE), corr = FALSE) print(fm2 <- lmer(DC~sex+age+smoker+alcohol+fruits(1|setting), d

Re: [R] Sampling data every third hour

2011-12-14 Thread R. Michael Weylandt
1) Use dput() to submit data. 2) Would this work? (It requires your data are evenly spaced, but I think that's it) d[seq(1, nrow(d), by = 3), ] Michael On Wed, Dec 14, 2011 at 7:17 AM, abcdef ghijk wrote: >  Good Morning , > > I want to sample the following time series for every third hour. For

[R] Sampling data every third hour

2011-12-14 Thread abcdef ghijk
 Good Morning , I want to sample the following time series for every third hour. For example at 00:00,03:00,06:00,09:00 etc.     2011-01-01 00:00:00 0.00e+00 2011-01-01 01:00:00 1.471667e+01 2011-01-01 02:00:00 1.576667e+01 2011-01-01 03:00:00 0.00e+00 2011-01-01 04:00:

Re: [R] Sampling with conditions

2011-11-08 Thread SarahJoyes
Dan Nordlund, Dan (DSHS/RDA) wrote: > >> -Original Message- >> From: r-help-bounces@ [mailto:r-help-bounces@r- >> project.org] On Behalf Of SarahJoyes >> Sent: Tuesday, November 08, 2011 5:57 AM >> To: r-help@ >> Subject: Re: [R] Sampling with c

Re: [R] Sampling with conditions

2011-11-08 Thread Dennis Murphy
-Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- >> project.org] On Behalf Of SarahJoyes >> Sent: Tuesday, November 08, 2011 5:57 AM >> To: r-help@r-project.org >> Subject: Re: [R] Sampling with conditions >> >> Tha

Re: [R] Sampling with conditions

2011-11-08 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of SarahJoyes > Sent: Tuesday, November 08, 2011 5:57 AM > To: r-help@r-project.org > Subject: Re: [R] Sampling with conditions > > That is exactly what I

Re: [R] Sampling with conditions

2011-11-08 Thread SarahJoyes
That is exactly what I want, and it's so simple! Thanks so much! -- View this message in context: http://r.789695.n4.nabble.com/Sampling-with-conditions-tp4014036p4016050.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-projec

Re: [R] Sampling with conditions

2011-11-08 Thread SarahJoyes
Sorry about being confusing, I have so many loops in loops and ifelses that I get mixed up sometimes, it was just a typo, it was supposed to be "for(i in 1:5)" Sorry, Thanks for you help! SJ -- View this message in context: http://r.789695.n4.nabble.com/Sampling-with-conditions-tp4014036p40

Re: [R] Sampling with conditions

2011-11-08 Thread Ted Harding
[Yet another correction -- this one is important. I start from scratch this time] On 07-Nov-11 22:22:54, SarahJoyes wrote: > Hey everyone, > I am at best, an amateur user of R, but I am stuck on how > to set-up the following situation. > I am trying to select a random sample of numbers from 0 t

Re: [R] Sampling with conditions

2011-11-07 Thread Ted Harding
[Correction below (I was writing too late at night ... ] On 08-Nov-11 00:25:57, Ted Harding wrote: > On 07-Nov-11 22:22:54, SarahJoyes wrote: >> Hey everyone, >> I am at best, an amateur user of R, but I am stuck on how >> to set-up the following situation. >> I am trying to select a random samp

Re: [R] Sampling with conditions

2011-11-07 Thread Ted Harding
On 07-Nov-11 22:22:54, SarahJoyes wrote: > Hey everyone, > I am at best, an amateur user of R, but I am stuck on how > to set-up the following situation. > I am trying to select a random sample of numbers from 0 to 10 > and insert them into the first column of a matrix (which will > used later in

Re: [R] Sampling with conditions

2011-11-07 Thread Daniel Nordlund
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of SarahJoyes > Sent: Monday, November 07, 2011 2:23 PM > To: r-help@r-project.org > Subject: [R] Sampling with conditions > > Hey everyone, > I am at

Re: [R] Sampling with conditions

2011-11-07 Thread Weidong Gu
Not sure this is valid that you can have 9 random samples out of 10, but the last one has to be fixed to meet the restraint, sum=10. Weidong On Mon, Nov 7, 2011 at 5:22 PM, SarahJoyes wrote: > Hey everyone, > I am at best, an amateur user of R, but I am stuck on how to set-up the > following sit

[R] Sampling with conditions

2011-11-07 Thread SarahJoyes
Hey everyone, I am at best, an amateur user of R, but I am stuck on how to set-up the following situation. I am trying to select a random sample of numbers from 0 to 10 and insert them into the first column of a matrix (which will used later in a loop). However, I need to have those numbers add u

Re: [R] sampling from the multivariate truncated normal

2011-07-05 Thread statfan
Well, for 0.828324 < x[2] < Inf the probablility is roughly 0 hence not easy to draw random numbers out there Uwe Ligges How is this probability roughly 0? -- View this message in context: http://r.789695.n4.nabble.com/sampling-from-the-multivariate-truncated-normal-tp3626438p3647039.ht

Re: [R] sampling from the multivariate truncated normal

2011-06-27 Thread Uwe Ligges
On 26.06.2011 21:26, statfan wrote: I am trying generate a sample for a truncated multivariate normal distribution via the rtmvnorm function in the {tmvtnorm} package. Why does the following produce NaNs? rtmvnorm(1, mean = rep(0, 2), matrix(c(0.06906084, -0.07463565, -0.07463565, 0.0807808

[R] sampling from the multivariate truncated normal

2011-06-26 Thread statfan
I am trying generate a sample for a truncated multivariate normal distribution via the rtmvnorm function in the {tmvtnorm} package. Why does the following produce NaNs? rtmvnorm(1, mean = rep(0, 2), matrix(c(0.06906084, -0.07463565, -0.07463565, 0.08078086),2),c(-0.4316738, 0.8283240), c(Inf,

Re: [R] sampling design runs with no errors but returns empty data set

2011-03-30 Thread Thomas Lumley
On Thu, Mar 31, 2011 at 4:01 AM, Simon Kiss wrote: > Dear colleagues, > I'm working with the 2008 Canada Election Studies > (http://www.queensu.ca/cora/_files/_CES/CES2008.sav.zip), trying to construct > a weighted national sample using the survey package. > Three weights are included in the nat

[R] sampling design runs with no errors but returns empty data set

2011-03-30 Thread Simon Kiss
Dear colleagues, I'm working with the 2008 Canada Election Studies (http://www.queensu.ca/cora/_files/_CES/CES2008.sav.zip), trying to construct a weighted national sample using the survey package. Three weights are included in the national survey (a household weight, a provincial weight and a

[R] Sampling Weights in HB Choice Modelling (e.g., rhierMnlRwMixture)

2011-03-26 Thread Klaus
Is anyone familiar with a way to account for sampling weights (e.g., in order to cope with selection bias) for individual respondents using the bayesm package (e.g., rhierMnlRwMixture)? In the regular MNL this can easily be done in STATA using the mlogit function with pweights option. However, I a

Re: [R] sampling

2011-02-17 Thread Dennis Murphy
Hi: A couple more approaches to consider: # Utility function to extract two rows from a data frame # Meant to be applied to each data subset sampler <- function(d) if(nrow(d) > 2) d[sample(1:nrow(d), 2, replace = FALSE), ] else d library(plyr) > ddply(x, 'id', sampler) id v1 V2 1 1 2 13 2 1

Re: [R] sampling

2011-02-17 Thread David Winsemius
On Feb 17, 2011, at 1:33 PM, andrija djurovic wrote: This is, maybe, not the best solution but I hope it will help you: x<-data.frame(id=c(1,1,1,2,2,2,2,3,3,3,4,4), v1=c(1:12), V2=c(12:23)) do.call("rbind",by(x,x$id,function(x) x[c(sample(nrow(x),2)),])) Andrija Another way (and note that

Re: [R] sampling

2011-02-17 Thread andrija djurovic
This is, maybe, not the best solution but I hope it will help you: x<-data.frame(id=c(1,1,1,2,2,2,2,3,3,3,4,4), v1=c(1:12), V2=c(12:23)) do.call("rbind",by(x,x$id,function(x) x[c(sample(nrow(x),2)),])) Andrija On Thu, Feb 17, 2011 at 6:39 PM, yf wrote: > > But i need for each id have two data

Re: [R] sampling

2011-02-17 Thread yf
But i need for each id have two data. Like... > x id v1 V2 1 1 1 12 2 1 2 13 4 2 4 15 5 2 5 16 8 3 8 19 9 3 9 20 11 4 11 22 12 4 12 23 So should write sample( if sample id >2 ,2). I don't know how to write (if sample id >2). Thanks. -- View this message in context:

Re: [R] sampling

2011-02-17 Thread David Winsemius
On Feb 16, 2011, at 11:35 PM, yf wrote: I want to sample from the ID. For each ID, i want to have 2 set of data. I try the sample() function but it didn't work. You don't say _how_ you used the sample function. You should show what code you used when stating the _something_ "doesn't wor

Re: [R] sampling

2011-02-17 Thread Mohamed Lajnef
Hi , what about split function ? ?split divided x into 2 data.frame a<-split(x,1:2) a[[1]] first data frame a[[2]] second data frame regrads M Le 17/02/11 05:35, yf a écrit : > I want to sample from the ID. For each ID, i want to have 2 set of data. I > try the sample() function but it did

[R] sampling

2011-02-17 Thread yf
I want to sample from the ID. For each ID, i want to have 2 set of data. I try the sample() function but it didn't work. > x<-data.frame(id=c(1,1,1,2,2,2,2,3,3,3,4,4), v1=c(1:12), V2=c(12:23)) > x id v1 V2 1 1 1 12 2 1 2 13 3 1 3 14 4 2 4 15 5 2 5 16 6 2 6 17 7 2 7 18 8

[R] Sampling question

2011-01-17 Thread Chris Mcowen
Dear list i have a sample question I have a dataframe of 1500 species and 13 life history traits. small example code: traits <- data.frame(letters[1:9], sample(letters, 9), sample(letters, 9), sample(letters, 9), sample(letters, 9), sample(letters, 9),

Re: [R] Sampling from multi-dimensional kernel density estimation

2010-11-23 Thread Greg Snow
801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Christoph Goebel > Sent: Friday, November 19, 2010 1:56 PM > To: r-help@r-project.org > Subject: [R] Sampling from multi-dimensional kernel density

[R] Sampling from multi-dimensional kernel density estimation

2010-11-19 Thread Christoph Goebel
Hi, I'd like to use a three-dimensional dataset to build a kernel density and then sample from the distribution. I already used the npudens function in the np package to estimate the density and plot it: fit<-npudens(~x+y+z) plot(fit) It takes some time but appears to work well.

Re: [R] Sampling problem

2010-11-16 Thread wangwallace
yes, the data.frame is exactly the same as the one I posted earlier. I was trying to see if the loop function works. And I got that message. here below is the syntax I was trying to run, followed by the error message at the end: > sampleX<-function(X,nGrp1,nsamples){if(nGrp1>=4)stop("can't sampl

Re: [R] Sampling problem

2010-11-16 Thread Michael Bedward
On 16 November 2010 16:10, wangwallace wrote: > > Michael, I really appreciate your help. > > but I got the following error message when I wan trying to run the function > written by you: > > Error in out[i, ] <- apply(help[, c(grp1 + 1, grp2 + 5)], 2, sample, 1) : >  number of items to replace is

Re: [R] Sampling problem

2010-11-16 Thread wangwallace
Michael, I really appreciate your help. but I got the following error message when I wan trying to run the function written by you: Error in out[i, ] <- apply(help[, c(grp1 + 1, grp2 + 5)], 2, sample, 1) : number of items to replace is not a multiple of replacement length I am not quite sure

Re: [R] Sampling problem

2010-11-15 Thread Michael Bedward
Hello, Is this what you want ? sampleX <- function(X, nGrp1, nsamples) # X is matrix or data.frame with cols for two groups of variables # with grp1 in cols 2:5 and grp2 in cols 6:9 # # nGrp1 <- number of variables to sample from group 1 # # nsamples <- number of rows in output matrix if (nGrp

[R] Sampling problem

2010-11-15 Thread wangwallace
Hey, I am hoping someone can help me with a sampling question. I have a data frame of 8 variables (the first column is the subjects' id): SubIDCSE1 CSE2 CSE3 CSE4 WSE1 WSE2 WSE3 WSE4 1 6 5 6 2 6 22 4 2 6 4

Re: [R] sampling from normal

2010-10-19 Thread Wu Gong
Hi Solafah, You are right that two commands are equivalent when p= pnorm(a). You can check the results by following codes. n <- 5 a <- -1 set.seed(123456) qnorm(runif(n,0,pnorm(a))) p <- pnorm(a) set.seed(123456) qnorm(p*runif(n)) Anyway, the elements of the lower tail are not chosen equally by

[R] sampling from normal

2010-10-19 Thread solafah bh
Hello If i want to resample from the lower tail of normal distribution , are these commands equivelant??  lower tail :qnorm(runif(n,0,pnorm(a))) if a is a lower tail bound or  lower tail:qnorm(p*runif(n)) if p is the probability of each interval(the observations are divided to intervals)   Regard

Re: [R] Sampling from data set

2010-10-05 Thread Jeffrey Spies
If poproh.3 was your dataset as a data.frame (an object with row and column dimensions), you need a comma following the row selection (sample(...)) to indicate that you want to select those rows and all columns: newsample <-poprho.3[sample(1:1,100),] # note the last comma in the brackets Gene

Re: [R] Sampling from data set

2010-10-05 Thread Jeffrey Spies
We'll probably need much more info, but this should get you started: nameOfDataSet[sample(1:1, 100),] You can replace the 1 with dim(nameOfDataSet)[1] to make it more dynamic. Jeff. On Tue, Oct 5, 2010 at 3:07 AM, Jumlong Vongprasert wrote: > Dear all. > I have data with 2 variable x,y

[R] Sampling from data set

2010-10-05 Thread Jumlong Vongprasert
Dear all. I have data with 2 variable x,y size 1. I want to sampling from this data with size 100. How I can do it. THANK. -- Jumlong Vongprasert Institute of Research and Development Ubon Ratchathani Rajabhat University Ubon Ratchathani THAILAND 34000 [[alternative HTML version dele

Re: [R] sampling from normal distribution

2010-10-03 Thread Duncan Murdoch
On 03/10/2010 6:38 PM, solafah bh wrote: Hello If i want to resampl from the tails of normal distribution , are these commans equivelant?? upper tail:qnorm(runif(n,pnorm(b),1)) if b is an upper tail boundary or upper tail:qnorm((1-p)+p(runif(n)) if p is the probability of each interval

Re: [R] sampling from normal distribution

2010-10-03 Thread Daniel Nordlund
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of solafah bh > Sent: Sunday, October 03, 2010 3:39 PM > To: R help mailing list > Subject: [R] sampling from normal distribution > > Hello > If i wan

[R] sampling from normal distribution

2010-10-03 Thread solafah bh
Hello If i want to resampl from the tails of normal distribution , are these commans equivelant??   upper tail:qnorm(runif(n,pnorm(b),1))  if b is an upper tail boundary   or   upper tail:qnorm((1-p)+p(runif(n))  if p is the probability of each interval (the observatins are divided to intervals)

  1   2   >