Re: [R] Generate random numbers under constrain

2014-11-22 Thread David Winsemius
In the 2 and 3 vector case it is possible do define a fairly simple sampling space where this is possible. Consider the unit square where the sample space is the area where x+y <1. It generalizes to 3 dimensions with no difficulty. x= (0:100)/100 y= (0:100)/100 z=outer(x,y, function(x,y) 1-

Re: [R] Formula with dynamic number of variables

2014-11-22 Thread Sven E. Templer
# fixed formula part: f <- dat ~ a0 * exp(-S*(x - 250)) + K # convert to character f <- as.character(f) # component: C <- "(p0*exp(-0.5*((x-p1)/p2)^2))" # number of components (defined randomly): n <- sample(1:3, 1) C <- rep(C, n) # collapse: C <- paste(C, collapse = "+") # combine f <- paste(f[2],

Re: [R] How do I extract single entries from a factor?

2014-11-22 Thread Chel Hee Lee
> xx <- as.factor(c("AL", "AK", "CA", "FL")) > xx [1] AL AK CA FL Levels: AK AL CA FL > as.character(xx) [1] "AL" "AK" "CA" "FL" I hope this helps. Chel Hee Lee On 14-11-22 01:12 AM, Aditya Singh wrote: Dear Boris and R-Experts, I have a variable my_state which is a 2-letter character string

Re: [R] Help with Time

2014-11-22 Thread Raghuraman Ramachandran
Hi Boris/ David Many thanks for the kind assistance. I will try following your codes. Time has always been a slippery subject to me! Cheers On Sat, Nov 22, 2014 at 12:59 AM, David Winsemius wrote: > > On Nov 21, 2014, at 3:19 PM, David Winsemius wrote: > >> >> On Nov 21, 2014, at 2:55 PM, Ragh

Re: [R] Bootstrap CIs for weighted means of paired differences

2014-11-22 Thread i.petzev
Ok, thanks for the suggestions. I will look into that. And you are absolutely right that I should have been more clear about what type of weighting I want. So to clarify: I run time series regressions of returns of company i on two different sets of explanatory variables. Then I extract the resp

Re: [R] Bootstrap CIs for weighted means of paired differences

2014-11-22 Thread i.petzev
On 21 Nov 2014, at 19:18, David Winsemius wrote: > > On Nov 21, 2014, at 6:52 AM, ivan wrote: > >> I am aware of the fact that bootstrapping produces different CIs with every >> run. I still believe that there is a difference between both types of >> procedures. My understanding is that sett

Re: [R] Generate random numbers under constrain

2014-11-22 Thread Boris Steipe
Of course they are random. But they can't all be randomly picked from [0,1). By scaling them, one is effectively scaling the interval from which they are picked. B. Nb: the scaling procedure will work for any probability distribution. On Nov 22, 2014, at 10:54 AM, Ranjan Maitra wrote: > I d

Re: [R] Generate random numbers under constrain

2014-11-22 Thread Ranjan Maitra
I don't understand this discussion at all. n random numbers constrained to have sum <=1 are still random. They are not all independent. That said, the original poster's question is ill=formed since there can be multiple distributions these random numbers come from. best wishes, Ranjan On Sa

Re: [R] Generate random numbers under constrain

2014-11-22 Thread Boris Steipe
These are contradictory requirements: either you have n random numbers from the interval [0,1), then you can't guarantee anything about their sum except that it will be in [0,n). Or you constrain the sum, then your random numbers cannot be random in [0,1). You could possibly scale the random num

Re: [R] Generate random numbers under constrain

2014-11-22 Thread Bert Gunter
(Hit send key by accident before I was finished ...) Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." Clifford Stoll On Sat, Nov 22, 2014 at 7:14 AM, Bert Gunter wrote: > Well, if th

Re: [R] Generate random numbers under constrain

2014-11-22 Thread Bert Gunter
Well, if their sum must be < 1 they ain't random... But anyway... given n randnums <- function(n) { Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." Clifford Stoll On Sat, Nov 22,

[R] Generate random numbers under constrain

2014-11-22 Thread Ragia Ibrahim
Dear all, I use R 3.1.1 for Windows. kindly how can I generate n number of random numbers with probability from [0,1] and their sum must not be more than one thanks in advance Ragia [[alternative HTML version deleted]]

Re: [R] How do I extract single entries from a factor?

2014-11-22 Thread peter dalgaard
> On 22 Nov 2014, at 08:12 , Aditya Singh wrote: > > Dear Boris and R-Experts, > > I have a variable my_state which is a 2-letter character string telling which > American state the user inputs. This I am do a if(identical(database > entry,my_state)) to check for occurrences in the database.