Need help with a function not returning values as expected

Hello,

This post is more related to R than to RStudio but I don't know where to post it.

I have a function that's supposed to return a vector or a dataframe, depending on the given parameters. Now when I call this function, it returns only the second element of my vector (if I input a single value in thetas) or the second column of my dataframe (if I input multiple values in thetas)

When I enter these lines directly in R, I get the data I need, but through a function incorprated in a package (SAME function!), it seems part of it is truncated and I don't know why.

If this is not the place for such requests, please tell me (and maybe a suggestion as to where to post this!)

Thanks!

Christian

#----Start of script

#Function #1 :
CalcIOfit<-function (thetas, items, patterns)
{
if (length(dim(items))!=2)
dim(items)=c(1,length(items))

if (length(thetas)==1){
p <- CalcProbItems(thetas,items)
q <- 1-p
infit <- sum((patterns-p)^2)/sum(pq)
outfit <- sum(((patterns-p)^2)/(p
q))/length(patterns)
result <- c(infit,outfit)
}
else{
result <- NULL
for(i in 1:length(thetas)){
p <- CalcProbItems(thetas[i],items)
q <- 1-p
infit <- sum((patterns[i,]-p)^2)/sum(pq)
outfit <- sum(((patterns[i,]-p)^2)/(p
q))/length(patterns[i,])
result <- rbind(result,c(infit,outfit))
}
}

return(result)
}

#Function #2 :
CalcProbItems<-function (theta, items)
{
if (length(dim(items))!=2)
dim(items)=c(1,length(items))

if (length(theta)==1)
probs <- 1/(1+exp(-(theta-items[,2])))
else{
probs<-NULL
for(i in 1:length(theta))
probs <- rbind(probs,1/(1+exp(-(theta[i]-items[,2]))))
}

return(probs)
}

#Needed variables :
items<-1:5
items <-cbind(items,c(-2,-1,0,1,2))
items <-cbind(items,c(-2,-1,0,1,2))
thetas<-0.59
pattern<-c(0,1,1,0,1)

#Call :
CalcIOfit(thetas,items,pattern)

#----End of script

I

Nevermind, it seems my function didn't save within the package so everytime I saved and reinstalled, it didn't take the last version of the version I was working on!

Now everything is OK!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.