I'm attempting to generate random 'constant' variables. I mean random as in randomly generated, and constant as in constant across all observations. I intend this to be used as a multiplier of sorts which is randomly generated when the syntax is run to introduce a little variation.
For example, I have a probability for a certain event, and I am running multiple 'trials' of this event and recording the outcome. For theoretical reasons, I want to add or subtract a randomly generated value (something like RV.Normal(0,.1)) from this probability for each observation. However, just generating a variable such as: compute randomadjustment = RV.Normal(0,.1). will create a unique random number for each observation. However, I want this adjustment to be constant across all observations. This way, every time the syntax is run, every observation's probability has the same random number added or subtracted from it. Is it possible to generate a 'random constant variable'? I hope all of this makes sense. Thanks for any help, -dk |
Administrator
|
dk,
DO IF $CASENUM=1. COMPUTE #RV=NORMAL(0,.1). END IF. * If you want a permanent copy *. COMPUTE RV=#RV. '-------- Note use of scratch variable. Read up on scratch variables. --
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
I interpreted the request as asking for
a column of constant values, so something like this would be required.
DO IF $casenum = 1. COMPUTE RV = rv.normal(0,1). END IF. LEAVE RV. Jon Peck Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: David Marso <[hidden email]> To: [hidden email] Date: 06/08/2011 02:20 PM Subject: Re: [SPSSX-L] Generating random 'constants' Sent by: "SPSSX(r) Discussion" <[hidden email]> dk, DO IF $CASENUM=1. COMPUTE #RV=NORMAL(0,.1). END IF. * If you want a permanent copy *. COMPUTE RV=#RV. '-------- Note use of scratch variable. Read up on scratch variables. -- drewk wrote: > > I'm attempting to generate random 'constant' variables. I mean random as > in randomly generated, and constant as in constant across all > observations. I intend this to be used as a multiplier of sorts which is > randomly generated when the syntax is run to introduce a little variation. > > For example, I have a probability for a certain event, and I am running > multiple 'trials' of this event and recording the outcome. For theoretical > reasons, I want to add or subtract a randomly generated value (something > like RV.Normal(0,.1)) from this probability for each observation. However, > just generating a variable such as: > > compute randomadjustment = RV.Normal(0,.1). > > will create a unique random number for each observation. However, I want > this adjustment to be constant across all observations. This way, every > time the syntax is run, every observation's probability has the same > random number added or subtracted from it. Is it possible to generate a > 'random constant variable'? > > I hope all of this makes sense. Thanks for any help, > -dk > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Generating-random-constants-tp4470695p4470810.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
FWIW: The 2 are equivalent aside from the option of using the scratch variable in the later computations and NOT having it remain in the file unless desired.
Isn't RV.Normal() just long hand for NORMAL()?
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by David Marso
minor correction and explanation:
correction: line 2 should be: compute #rv=rv.normal(0,.1). explanation: This code works by taking advantage of the fact that scratch (temporary variables identified with a # prefix) are not reinitialized for each case. If you used: compute rv=rv.normal(0, .1) the values for all but the first case would be missing. From: David Marso <[hidden email]> To: [hidden email] Date: 06/08/2011 03:15 PM Subject: Re: Generating random 'constants' Sent by: "SPSSX(r) Discussion" <[hidden email]> dk, DO IF $CASENUM=1. COMPUTE #RV=NORMAL(0,.1). END IF. * If you want a permanent copy *. COMPUTE RV=#RV. '-------- Note use of scratch variable. Read up on scratch variables. -- drewk wrote: > > I'm attempting to generate random 'constant' variables. I mean random as > in randomly generated, and constant as in constant across all > observations. I intend this to be used as a multiplier of sorts which is > randomly generated when the syntax is run to introduce a little variation. > > For example, I have a probability for a certain event, and I am running > multiple 'trials' of this event and recording the outcome. For theoretical > reasons, I want to add or subtract a randomly generated value (something > like RV.Normal(0,.1)) from this probability for each observation. However, > just generating a variable such as: > > compute randomadjustment = RV.Normal(0,.1). > > will create a unique random number for each observation. However, I want > this adjustment to be constant across all observations. This way, every > time the syntax is run, every observation's probability has the same > random number added or subtracted from it. Is it possible to generate a > 'random constant variable'? > > I hope all of this makes sense. Thanks for any help, > -dk > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Generating-random-constants-tp4470695p4470810.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by David Marso
When we add 20+ random number generators
and associated function a long while ago, the generators were all given
the common rv. root, so rv.normal is a synonym for normal but is the preferred
style (uniform and normal no longer appear in the Compute dialog). Using
the scratch variable works, though, because it survives outside the DO
IF loop. Readability favors LEAVE IMO.
Jon Peck Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: David Marso <[hidden email]> To: [hidden email] Date: 06/08/2011 02:42 PM Subject: Re: [SPSSX-L] Generating random 'constants' Sent by: "SPSSX(r) Discussion" <[hidden email]> FWIW: The 2 are equivalent aside from the option of using the scratch variable in the later computations and NOT having it remain in the file unless desired. Isn't RV.Normal() just long hand for NORMAL()? Jon K Peck wrote: > > I interpreted the request as asking for a column of constant values, so > something like this would be required. > > DO IF $casenum = 1. > COMPUTE RV = rv.normal(0,1). > END IF. > LEAVE RV. > > Jon Peck > Senior Software Engineer, IBM > [hidden email] > new phone: 720-342-5621 > > > > > From: David Marso <[hidden email]> > To: [hidden email] > Date: 06/08/2011 02:20 PM > Subject: Re: [SPSSX-L] Generating random 'constants' > Sent by: "SPSSX(r) Discussion" <[hidden email]> > > > > dk, > > DO IF $CASENUM=1. > COMPUTE #RV=NORMAL(0,.1). > END IF. > * If you want a permanent copy *. > COMPUTE RV=#RV. > > '-------- > Note use of scratch variable. > Read up on scratch variables. > > -- > drewk wrote: >> >> I'm attempting to generate random 'constant' variables. I mean random as >> in randomly generated, and constant as in constant across all >> observations. I intend this to be used as a multiplier of sorts which is >> randomly generated when the syntax is run to introduce a little > variation. >> >> For example, I have a probability for a certain event, and I am running >> multiple 'trials' of this event and recording the outcome. For > theoretical >> reasons, I want to add or subtract a randomly generated value (something >> like RV.Normal(0,.1)) from this probability for each observation. > However, >> just generating a variable such as: >> >> compute randomadjustment = RV.Normal(0,.1). >> >> will create a unique random number for each observation. However, I want >> this adjustment to be constant across all observations. This way, every >> time the syntax is run, every observation's probability has the same >> random number added or subtracted from it. Is it possible to generate a >> 'random constant variable'? >> >> I hope all of this makes sense. Thanks for any help, >> -dk >> > > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/Generating-random-constants-tp4470695p4470810.html > > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Generating-random-constants-tp4470695p4470882.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by drewk
At 03:44 PM 6/8/2011, drewk wrote:
>I'm attempting to generate random 'constant', randomly generated >[but] constant across all observations. For example, I have a >probability for a certain event, and I am running multiple 'trials' >of this event and recording the outcome. For theoretical reasons, I >want to add or subtract a randomly generated value (something like >RV.Normal(0,.1)) from this probability for each observation. There are several ways. Here's one (tested): NUMERIC RandConst (F7.3). LEAVE RandConst. IF $CASENUM EQ 1 RandConst = RV.Normal(0,.1). ============================= APPENDIX: Test data, and code (Listing not posted) ============================= NEW FILE. INPUT PROGRAM. . NUMERIC RecdNumb (F2). . LOOP RecdNumb = 1 TO 4. . END CASE. . END LOOP. END FILE. END INPUT PROGRAM. NUMERIC RandConst (F7.3). LEAVE RandConst. IF $CASENUM EQ 1 RandConst = RV.Normal(0,.1). LIST. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
In reply to this post by Rick Oliver-3
My bad, I forgot that the naked unqualified NORMAL has an implicit 0
mean so either. RV.NORMAL(mean,sd) or NORMAL(sd). OTOH, as Jon posts below, NORMAL no longer appears in the CONFUSE dialog box (which I NEVER use), so RV.NORMAL(mean,sd) is likely the preferred (how long before it becomes so deprecated that they remove it). On Wed, Jun 8, 2011 at 4:41 PM, Rick Oliver <[hidden email]> wrote: > minor correction and explanation: > > correction: line 2 should be: > compute #rv=rv.normal(0,.1). > > explanation: > This code works by taking advantage of the fact that scratch (temporary > variables identified with a # prefix) are not reinitialized for each case. > If you used: > compute rv=rv.normal(0, .1) > the values for all but the first case would be missing. > > > > From: David Marso <[hidden email]> > To: [hidden email] > Date: 06/08/2011 03:15 PM > Subject: Re: Generating random 'constants' > Sent by: "SPSSX(r) Discussion" <[hidden email]> > ________________________________ > > > dk, > > DO IF $CASENUM=1. > COMPUTE #RV=NORMAL(0,.1). > END IF. > * If you want a permanent copy *. > COMPUTE RV=#RV. > > '-------- > Note use of scratch variable. > Read up on scratch variables. > > -- > drewk wrote: >> >> I'm attempting to generate random 'constant' variables. I mean random as >> in randomly generated, and constant as in constant across all >> observations. I intend this to be used as a multiplier of sorts which is >> randomly generated when the syntax is run to introduce a little variation. >> >> For example, I have a probability for a certain event, and I am running >> multiple 'trials' of this event and recording the outcome. For theoretical >> reasons, I want to add or subtract a randomly generated value (something >> like RV.Normal(0,.1)) from this probability for each observation. However, >> just generating a variable such as: >> >> compute randomadjustment = RV.Normal(0,.1). >> >> will create a unique random number for each observation. However, I want >> this adjustment to be constant across all observations. This way, every >> time the syntax is run, every observation's probability has the same >> random number added or subtracted from it. Is it possible to generate a >> 'random constant variable'? >> >> I hope all of this makes sense. Thanks for any help, >> -dk >> > > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/Generating-random-constants-tp4470695p4470810.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > > ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by David Marso
NORMAL and RV.NORMAL are different functions
with different numbers of arguments. The former has 1 argument (standard
deviation). The latter has two arguments (mean and standard deviation).
From: David Marso <[hidden email]> To: [hidden email] Date: 06/08/2011 03:41 PM Subject: Re: Generating random 'constants' Sent by: "SPSSX(r) Discussion" <[hidden email]> FWIW: The 2 are equivalent aside from the option of using the scratch variable in the later computations and NOT having it remain in the file unless desired. Isn't RV.Normal() just long hand for NORMAL()? Jon K Peck wrote: > > I interpreted the request as asking for a column of constant values, so > something like this would be required. > > DO IF $casenum = 1. > COMPUTE RV = rv.normal(0,1). > END IF. > LEAVE RV. > > Jon Peck > Senior Software Engineer, IBM > [hidden email] > new phone: 720-342-5621 > > > > > From: David Marso <[hidden email]> > To: [hidden email] > Date: 06/08/2011 02:20 PM > Subject: Re: [SPSSX-L] Generating random 'constants' > Sent by: "SPSSX(r) Discussion" <[hidden email]> > > > > dk, > > DO IF $CASENUM=1. > COMPUTE #RV=NORMAL(0,.1). > END IF. > * If you want a permanent copy *. > COMPUTE RV=#RV. > > '-------- > Note use of scratch variable. > Read up on scratch variables. > > -- > drewk wrote: >> >> I'm attempting to generate random 'constant' variables. I mean random as >> in randomly generated, and constant as in constant across all >> observations. I intend this to be used as a multiplier of sorts which is >> randomly generated when the syntax is run to introduce a little > variation. >> >> For example, I have a probability for a certain event, and I am running >> multiple 'trials' of this event and recording the outcome. For > theoretical >> reasons, I want to add or subtract a randomly generated value (something >> like RV.Normal(0,.1)) from this probability for each observation. > However, >> just generating a variable such as: >> >> compute randomadjustment = RV.Normal(0,.1). >> >> will create a unique random number for each observation. However, I want >> this adjustment to be constant across all observations. This way, every >> time the syntax is run, every observation's probability has the same >> random number added or subtracted from it. Is it possible to generate a >> 'random constant variable'? >> >> I hope all of this makes sense. Thanks for any help, >> -dk >> > > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/Generating-random-constants-tp4470695p4470810.html > > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Generating-random-constants-tp4470695p4470882.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by Jon K Peck
NORMAL(stddev). Numeric. Returns a normally distributed pseudorandom
number from a distribution with mean 0 and standard deviation stddev, which
must be a positive number.
RV.NORMAL(mean, stddev). Numeric. Returns a random value from a normal distribution with specified mean and standard deviation. One is not a synonym for the other. From: Jon K Peck/Chicago/IBM@IBMUS To: [hidden email] Date: 06/08/2011 03:52 PM Subject: Re: Generating random 'constants' Sent by: "SPSSX(r) Discussion" <[hidden email]> When we add 20+ random number generators and associated function a long while ago, the generators were all given the common rv. root, so rv.normal is a synonym for normal but is the preferred style (uniform and normal no longer appear in the Compute dialog). Using the scratch variable works, though, because it survives outside the DO IF loop. Readability favors LEAVE IMO. Jon Peck Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: David Marso <[hidden email]> To: [hidden email] Date: 06/08/2011 02:42 PM Subject: Re: [SPSSX-L] Generating random 'constants' Sent by: "SPSSX(r) Discussion" <[hidden email]> FWIW: The 2 are equivalent aside from the option of using the scratch variable in the later computations and NOT having it remain in the file unless desired. Isn't RV.Normal() just long hand for NORMAL()? Jon K Peck wrote: > > I interpreted the request as asking for a column of constant values, so > something like this would be required. > > DO IF $casenum = 1. > COMPUTE RV = rv.normal(0,1). > END IF. > LEAVE RV. > > Jon Peck > Senior Software Engineer, IBM > [hidden email] > new phone: 720-342-5621 > > > > > From: David Marso <[hidden email]> > To: [hidden email] > Date: 06/08/2011 02:20 PM > Subject: Re: [SPSSX-L] Generating random 'constants' > Sent by: "SPSSX(r) Discussion" <[hidden email]> > > > > dk, > > DO IF $CASENUM=1. > COMPUTE #RV=NORMAL(0,.1). > END IF. > * If you want a permanent copy *. > COMPUTE RV=#RV. > > '-------- > Note use of scratch variable. > Read up on scratch variables. > > -- > drewk wrote: >> >> I'm attempting to generate random 'constant' variables. I mean random as >> in randomly generated, and constant as in constant across all >> observations. I intend this to be used as a multiplier of sorts which is >> randomly generated when the syntax is run to introduce a little > variation. >> >> For example, I have a probability for a certain event, and I am running >> multiple 'trials' of this event and recording the outcome. For > theoretical >> reasons, I want to add or subtract a randomly generated value (something >> like RV.Normal(0,.1)) from this probability for each observation. > However, >> just generating a variable such as: >> >> compute randomadjustment = RV.Normal(0,.1). >> >> will create a unique random number for each observation. However, I want >> this adjustment to be constant across all observations. This way, every >> time the syntax is run, every observation's probability has the same >> random number added or subtracted from it. Is it possible to generate a >> 'random constant variable'? >> >> I hope all of this makes sense. Thanks for any help, >> -dk >> > > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/Generating-random-constants-tp4470695p4470810.html > > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Generating-random-constants-tp4470695p4470882.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Free forum by Nabble | Edit this page |