[R] Genrating Ordinal Responses in R

JS Huang js.huang at protective.com
Sat Feb 14 00:03:30 CET 2015


Hi,

  Here assume there are four elements in the ordinal set y and take a random
sample of size 10 according to the cumulative distribution given, or
probability distribution p below.


> y <- c(levels = c("First", "Second", "Third", "Fourth"))
> y
 levels1  levels2  levels3  levels4 
 "First" "Second"  "Third" "Fourth" 
> (x <- c(1/9, 1/4, 3/5, 1))
[1] 0.1111111 0.2500000 0.6000000 1.0000000
> p <- c(x[1], x[2]-x[1], x[3]-x[2], x[4]-x[3])
> p
[1] 0.1111111 0.1388889 0.3500000 0.4000000
> sample(y, 10, replace=TRUE, prob=p)
 levels2  levels4  levels4  levels3  levels1  levels3  levels4  levels2 
levels4  levels3 
"Second" "Fourth" "Fourth"  "Third"  "First"  "Third" "Fourth" "Second"
"Fourth"  "Third" 



--
View this message in context: http://r.789695.n4.nabble.com/Genrating-Ordinal-Responses-in-R-tp4703159p4703244.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list