Hi everyone, I am having a bit of trouble correctly structuring an equation in R. Here is the equation Here is what I thought for(i in 1:numItem)for(x in 1:numCat) Ptheta[,i,x]<-(exp(-1.702*a[i]*(theta-b[i,x+1])) My problem is that I am not sure how to get it to read the equation as having two indexing points (i and x). Right now it is trying to read it as a matrix, but each value (i and x) are only vectors. Does anyone have any suggestions on how to get R to recognize this? As an example, numItem may = 20 and numCat may = 3 and I am trying to evaluate this over all values of numCat for each value of numItem. Thanks, Brendan
Brendan It looks like you're working with the 2PL, what are you trying to estimate exactly? There are a lot of built in psychometric functions that you might consider using.> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Brendan Morse > Sent: Monday, April 13, 2009 10:54 AM > To: r-help at r-project.org > Subject: [R] equation help > > Hi everyone, I am having a bit of trouble correctly > structuring an equation in R. > > > Here is the equation > > > > Here is what I thought > > for(i in 1:numItem)for(x in 1:numCat) > > Ptheta[,i,x]<-(exp(-1.702*a[i]*(theta-b[i,x+1])) > > My problem is that I am not sure how to get it to read the > equation as having two indexing points (i and x). Right now > it is trying to read it as a matrix, but each value (i and x) > are only vectors. Does anyone have any suggestions on how to > get R to recognize this? As an example, numItem may = 20 and > numCat may = 3 and I am trying to evaluate this over all > values of numCat for each value of numItem. > > Thanks, > Brendan > > ______________________________________________ > 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. >
On Apr 13, 2009, at 10:54 AM, Brendan Morse wrote:> Hi everyone, I am having a bit of trouble correctly structuring an > equation in R. > > Here is the equationIt's really a series of assignments.> > > Here is what I thought > > for(i in 1:numItem)for(x in 1:numCat) > > Ptheta[,i,x]<-(exp(-1.702*a[i]*(theta-b[i,x+1]))I am guessing that what you really want is: for(i in 1:numItem){ for(x in 1:numCat){ Ptheta[i,x]<-(exp(-1.702*a[i]*(theta-b[i,x+1])) } } #obviously untested That should populate the i, x entries of a matrix with your calculations. The extra comma in your attempt was telling R that you wanted a three dimensional array. The other possibility as a construction would be to use expand.grid> > > My problem is that I am not sure how to get it to read the equation > as having two indexing points (i and x). Right now it is trying to > read it as a matrix, but each value (i and x) are only vectors.Each value is an integer by the time it gets to the innards of the loop.> Does anyone have any suggestions on how to get R to recognize this? > As an example, numItem may = 20 and numCat may = 3 and I am trying > to evaluate this over all values of numCat for each value of numItem. > > Thanks, > Brendan-- David Winsemius, MD Heritage Laboratories West Hartford, CT