Description Usage Arguments Details Value Author(s) See Also Examples
A quick way to cook up some fake data.
1 |
formula |
A formula which describes the relationship you wish your fake data to have to an existing numeric vector. For example, if you have a numeric vector |
s |
A numeric value which describes the amount of variablity you want your fake data to have. If |
Quickly cooking up fake data may be useful for experimenting with differnt plotting functions in R with data that you can control. You can control the relationship between your data and an existing vector, and you can control the variablity of the data, i.e. how closely correlated the fake data is to the existing vector. You also know that the residuals are normally distributed with mean 0, which satisfies a major assumption of linear regression.
The function returns a numeric vector.
Jonathan Schwartz
1 2 3 4 5 6 7 8 9 10 11 | x=sample(0:1000,100)
y=fakedata(3*x+10) #y is a vector of fake data which will have a linear relationship with x
plot(x,y)
cor(x,y) #x and y are very highly correlated
y2=fakedata(3*x+10,1) #increasing the value of s decreases the correlation
plot(x,y2)
cor(x,y2) #x and y2 are not as highly correlated
##you can also, of course do non-linear relationships
y3=fakedata(sqrt(1/x))
plot(x,y3)
|
[1] 0.9639611
[1] 0.661195
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.