Ronaldo Reis Jr.
2002-Jun-21 16:48 UTC
[R] generating points over a function, its possible???
Hi, I have a new (for me) situation. I have a function for one linear model: y = 9.7909-0.035*x I have the variance of system var = 13.01403 Is possible to create a random vector points of Y (simulating the real data) over this curve using the function and the variance? I need this to a discipline. I have this: | \ | \ -> y = 9.7909-0.035*x and var = 13.014 | \ | \ | \ | \ |__________ I need something like this (generate this points): |* \* | * \** | **\ * | *\ ** | * \* | * \ * | *\ |____________ Thanks for all Ronaldo -- "It ain't over until it's over." -- Casey Stengel -- | //|\\ [*****************************][*******************] || ( ? ? ) [Ronaldo Reis J?nior ][PentiumIII-600 ] | V [ESALQ/USP-Entomologia, CP-09 ][HD: 30 + 10 Gb ] || / l \ [13418-900 Piracicaba - SP ][RAM: 128 Mb ] | /(lin)\ [Fone: 19-429-4199 r.229 ][Video: SiS620-8Mb ] ||/(linux)\ [chrysopa at insecta.ufv.br ][Modem: Pctel-onboar] |/ (linux) \[ICQ#: 5692561 ][SO: CL 7.0 (2.2.19)] || ( x ) [*****************************][*******************] ||| _/ \_Powered by Conectiva Linux 7.0 D+:) | Lxuser#: 205366 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Huntsinger, Reid
2002-Jun-21 19:50 UTC
[R] generating points over a function, its possible???
You can use R's random-number generating functions (e.g. rnorm) to generate a vector of independent "deviations" from the line, and add them to your y vector. You can scale them to make the variance match your 13.01403, usually with a parameter to the function, or simply by multiplying by the appropriate scale factor. You can get dependent deviations in various ways, e.g., see "filter" in the ts package for autocorrelated or moving-average structures. Also check the "mvnorm" package. Reid Huntsinger -----Original Message----- From: Ronaldo Reis Jr. [mailto:chrysopa at insecta.ufv.br] Sent: Friday, June 21, 2002 12:49 PM To: R-Help Subject: [R] generating points over a function, its possible??? Hi, I have a new (for me) situation. I have a function for one linear model: y = 9.7909-0.035*x I have the variance of system var = 13.01403 Is possible to create a random vector points of Y (simulating the real data) over this curve using the function and the variance? I need this to a discipline. I have this: | \ | \ -> y = 9.7909-0.035*x and var = 13.014 | \ | \ | \ | \ |__________ I need something like this (generate this points): |* \* | * \** | **\ * | *\ ** | * \* | * \ * | *\ |____________ Thanks for all Ronaldo -- "It ain't over until it's over." -- Casey Stengel -- | //|\\ [*****************************][*******************] || ( ? ? ) [Ronaldo Reis J?nior ][PentiumIII-600 ] | V [ESALQ/USP-Entomologia, CP-09 ][HD: 30 + 10 Gb ] || / l \ [13418-900 Piracicaba - SP ][RAM: 128 Mb ] | /(lin)\ [Fone: 19-429-4199 r.229 ][Video: SiS620-8Mb ] ||/(linux)\ [chrysopa at insecta.ufv.br ][Modem: Pctel-onboar] |/ (linux) \[ICQ#: 5692561 ][SO: CL 7.0 (2.2.19)] || ( x ) [*****************************][*******************] ||| _/ \_Powered by Conectiva Linux 7.0 D+:) | Lxuser#: 205366 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ ------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it. ============================================================================= -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
How about this? f <- function(x) { 9.7909 - 0.035 * x } x <- 1:100 ## or whatever sigma <- sqrt(13.01403) sim.y <- f(x) + sigma * rnorm(length(x)) This uses Normal errors, which (by your picture) seems like what you want. You might want to use set.seed() so that you can reproduce the results. -roger _______________________________ UCLA Department of Statistics rpeng at stat.ucla.edu http://www.stat.ucla.edu/~rpeng On Fri, 21 Jun 2002, Ronaldo Reis Jr. wrote:> Hi, > I have a new (for me) situation. > I have a function for one linear model: > y = 9.7909-0.035*x > I have the variance of system > var = 13.01403 > Is possible to create a random vector points of Y (simulating the real data) > over this curve using the function and the variance? I need this to a > discipline. > > I have this: > > | \ > | \ -> y = 9.7909-0.035*x and var = 13.014 > | \ > | \ > | \ > | \ > |__________ > > I need something like this (generate this points): > > |* \* > | * \** > | **\ * > | *\ ** > | * \* > | * \ * > | *\ > |____________ > > Thanks for all > Ronaldo > -- > "It ain't over until it's over." > -- Casey Stengel > -- > | //|\\ [*****************************][*******************] > || ( õ õ ) [Ronaldo Reis Júnior ][PentiumIII-600 ] > | V [ESALQ/USP-Entomologia, CP-09 ][HD: 30 + 10 Gb ] > || / l \ [13418-900 Piracicaba - SP ][RAM: 128 Mb ] > | /(lin)\ [Fone: 19-429-4199 r.229 ][Video: SiS620-8Mb ] > ||/(linux)\ [chrysopa at insecta.ufv.br ][Modem: Pctel-onboar] > |/ (linux) \[ICQ#: 5692561 ][SO: CL 7.0 (2.2.19)] > || ( x ) [*****************************][*******************] > ||| _/ \_Powered by Conectiva Linux 7.0 D+:) | Lxuser#: 205366 > > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
kjetil halvorsen
2002-Jun-21 20:32 UTC
[R] generating points over a function, its possible???
what you need is rnorm, which gives N(0,1) variates, and then multiply with the standard deviation you have estimated, sqrt(13.01403). Then x (your data ve ctor) yhat <- 9.7909 + 0.035*x ysim <- yhat + sqrt(13.01403)*rnorm(x) Kjetil halvorsen "Ronaldo Reis Jr." wrote:> > Hi, > I have a new (for me) situation. > I have a function for one linear model: > y = 9.7909-0.035*x > I have the variance of system > var = 13.01403 > Is possible to create a random vector points of Y (simulating the real data) > over this curve using the function and the variance? I need this to a > discipline. > > I have this: > > | \ > | \ -> y = 9.7909-0.035*x and var = 13.014 > | \ > | \ > | \ > | \ > |__________ > > I need something like this (generate this points): > > |* \* > | * \** > | **\ * > | *\ ** > | * \* > | * \ * > | *\ > |____________ > > Thanks for all > Ronaldo > -- > "It ain't over until it's over." > -- Casey Stengel > -- > | //|\\ [*****************************][*******************] > || ( ? ? ) [Ronaldo Reis J?nior ][PentiumIII-600 ] > | V [ESALQ/USP-Entomologia, CP-09 ][HD: 30 + 10 Gb ] > || / l \ [13418-900 Piracicaba - SP ][RAM: 128 Mb ] > | /(lin)\ [Fone: 19-429-4199 r.229 ][Video: SiS620-8Mb ] > ||/(linux)\ [chrysopa at insecta.ufv.br ][Modem: Pctel-onboar] > |/ (linux) \[ICQ#: 5692561 ][SO: CL 7.0 (2.2.19)] > || ( x ) [*****************************][*******************] > ||| _/ \_Powered by Conectiva Linux 7.0 D+:) | Lxuser#: 205366 > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._