Thanoon,

Firstly, please remember to reply to the R help list as well so that other
may benefit from your questions as well.

Regarding your second request, I have written the following as a very naive
way of inducing correlations.  Hopefully this makes it perfectly clear what
you change for different sample sizes.

ords <- seq(4)
p <- 10
N <- 1000
percent_change <- 0.9

R <- as.data.frame(replicate(p, sample(ords, N, replace = T)))

# spearman is more appropriate for ordinal data
cor(R, method = "spearman")

# subset variable to have a stronger correlation
v1 <- R[,1, drop = FALSE]

# randomly choose which rows to retain
keep <- sample(as.numeric(rownames(v1)), size = percent_change*nrow(v1))
change <- as.numeric(rownames(v1)[-keep])

# randomly choose new values for changing
new.change <- sample(ords, ((1-percent_change)*N)+1, replace = T)

# replace values in copy of original column
v1.samp <- v1
v1.samp[change,] <- new.change

# closer correlation
cor(v1, v1.samp, method = "spearman")

# set correlated column as one of your other columns
R[,2] <- v1.samp

This obviously only creates a correlation between two columns.  You need to
decide what you expect from this synthetic dataset.  Do you want perfect
correlations?  Does it matter which variables are correlated?  How many
variables will be correlated?  Are there correlations between multiple
variables?  Do you want negative correlations (hint: opposite values)?

All of these questions would be great exercises for you to improve your R.
You can also turn the above code into a function and have it randomly
select two columns to be correlated if that works for you.  Because of all
of these possibilities I cannot provide the 'right' code but rather guide
you towards something more useful.

Cheers,
Charles




On Fri, Apr 4, 2014 at 8:37 PM, thanoon younis
<thanoon.younis80@gmail.com>wrote:

> thanks alot for your help
> now i want two different sample size in R what should i  change in
> previous command? and how can i get correlated simulation data (there are
> an interrelationships between variables)
>
> regards
> thanoon
>
>
> On 4 April 2014 18:42, Charles Determan Jr <deter088@umn.edu> wrote:
>
>> Hi Thanoon,
>>
>> How about this?
>> # replicate p=10 times random sampling n=1000 from a vector containing
>> your ordinal categories (1,2,3,4)
>> R <- replicate(10, sample(as.vector(seq(4)), 1000, replace = T))
>>
>> Cheers,
>> Charles
>>
>>
>>
>> On Fri, Apr 4, 2014 at 7:10 AM, thanoon younis <
>> thanoon.younis80@gmail.com> wrote:
>>
>>> dear sir
>>> i want to simulate multivariate ordinal data matrix with categories (1,4)
>>> and n=1000 and p=10.
>>> thanks alot
>>>
>>> thanoon
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>>
>> --
>> Charles Determan
>> Integrated Biosciences PhD Candidate
>> University of Minnesota
>>
>
>


-- 
Charles Determan
Integrated Biosciences PhD Candidate
University of Minnesota

	[[alternative HTML version deleted]]


