From: Robin Hankin <r.hankin_at_noc.soton.ac.uk>

Date: Thu 31 Aug 2006 - 01:10:26 EST

Date: Thu 31 Aug 2006 - 01:10:26 EST

OK,

With this extra detail, a

third solution follows, which may be closer in spirit
to your application.

It may or may not be faster than the other two,
depending on the exact parameters used:

library(partitions)

1+blockparts(n=15,y=c(3,4,2,5,6)-1,include.fewer=T)

(720 distinct solutions)

rksh

On 30 Aug 2006, at 15:49, Doran, Harold wrote:

> Hi Duncan

*>
**> Here is a bit more detail, this is a bit tough to explain, sorry
**> for not
**> being clear. Ordering is not important because the vector I am
**> creating
**> is used as a sufficient statistic in an optimization routine to get
**> some
**> MLEs. So, any combination of the vector that sums to X is OK. But, the
**> condition that x2[i] <= x[i] must be maintained. So, the example below
**> would not work because x2[1] > x[1] as you note below.
**>
**>> I don't think it's really clear what you mean by "ordering is
**>> not important". Would
**>>
**>> x2 <- c(6,5,2,4,2)
**>> be acceptable (a re-ordering of your first two examples),
**>> even though x2[1] > x1[1]?
**>
**> To be concrete, the following is the optimization function. This is a
**> psychometric problem where the goal is to get the MLE for a test taker
**> conditional on their response pattern (i.e., number of points on the
**> test) and the item parameters.
**>
**> pcm.max3 <- function(score, d){
**> pcm <- function(theta, d, score)
**> exp(sum(theta-d[1:score]))/sum(exp(cumsum(theta-d)))
**> opt <- function(theta) -sum(log(mapply(pcm, d, theta = theta,
**> score=
**> score )))
**> start_val <- log(sum(score-1)/(length(score-1)/sum(score-1)))
**> out <- optim(start_val, opt, method = "BFGS", hessian = TRUE)
**> cat('theta is about', round(out$par, 2), ', se',
**> 1/sqrt(out$hes),'\n')
**> }
**>
**> Suppose we have a three item test. I store the item parameters in a
**> list
**> as
**>
**> items <- list(c(0,.5,1), c(0,1), c(0, -1, .5, 1))
**>
**> We can get the total possible number correct as
**>
**> (x <- sapply(items, length))
**> [1] 3 2 4
**>
**> But, you cannot actually get the MLE for this because the
**> likelihood is
**> unbounded in this case.
**>
**> So, let's say the student scored in the following categories for each
**> item:
**>
**> x2 <- c(3,1,4)
**>
**> By x2[i] <= x[i], I mean that there are 3 possible categories for
**> item 1
**> above. So, a student can only score in categories 1,2 or 3. He cannot
**> score in category 4. This is why the condition that x2[i] <= x[i] is
**> critical.
**>
**> But, because total score is a sufficient statistic, (i.e.,
**> "ordering is
**> not important") we could either vector in the function pcm.
**>
**> x3 <- c(3,2,3)
**>
**> Using the function
**>
**> pcm.max3(x2, items)
**> pcm.max3(x3, items)
**>
**> Gives the same MLE.
**>
**> But, the vector
**>
**> X_bad <- c(4,1,3)
**>
**> Would not work. You can see that the elements of this vector actually
**> serve as indices denoting which category a test taker scored in for
**> each
**> item in the list "items"
**>
**> I hope this is helpful and appreciate your time.
**>
**> Harold
**>
**>
**>>>
**>>> ______________________________________________
**>>> R-help@stat.math.ethz.ch 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.
**>>
**>>
**>
**> ______________________________________________
**> R-help@stat.math.ethz.ch 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.
*

-- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 ______________________________________________ R-help@stat.math.ethz.ch 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.Received on Thu Aug 31 11:32:04 2006

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Thu 31 Aug 2006 - 12:27:01 EST.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*