From: Doran, Harold <HDoran_at_air.org>

Date: Wed, 02 Jun 2010 10:44:12 -0400

R-help_at_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. Received on Wed 02 Jun 2010 - 16:33:57 GMT

Date: Wed, 02 Jun 2010 10:44:12 -0400

I have a function that I am currently using very inefficiently. The following are needed to illustrate the problem:

First, I create a matrix of some predicted probabilities as:

rasch <- function(theta,b) 1/ (1 + exp(b-theta)) mat <- apply(as.matrix(theta), 1, rasch, b_vector)

Afterwards, the function computes the gradient and hessians needed to complete the MLE estimation.

derivs <- function(dat, b_vector, theta){

mat <- apply(as.matrix(theta), 1, rasch, b_vector) mat[empty] <- NA gradient <- -(colSums(dat, na.rm = TRUE) - rowSums(mat, na.rm = TRUE)) hessian <- -(rowSums(mat * (1-mat), na.rm = TRUE)) list('gradient' = gradient, 'hessian' = hessian) }

*> sessionInfo()
*

R version 2.10.1 (2009-12-14)

i386-pc-mingw32

locale:

[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252

[4] LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] tools_2.10.1

*>
*

[[alternative HTML version deleted]]

R-help_at_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. Received on Wed 02 Jun 2010 - 16:33:57 GMT

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

Archive generated by hypermail 2.2.0, at Thu 03 Jun 2010 - 00:20:27 GMT.

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