[Error] length of 'dimnames' [2] not equal to array extent

#1
Hello all,

I'm trying to use the user-created multinomRob to make some models for my data. While documentation for that function is great and I think I'm using it correctly, I'm getting the following error when I try to use my dataframes.

data <- read.csv("data.csv", header=FALSE)
subj1 <- data.frame(radius=data$V3[9:11], x1=data$V4[9:11], x2=data$V5[9:11], x3=data$V6[9:11])
> subj1
radius x1 x2 x3
1 436.61 1.00000 0.000000 0.000000
2 735.27 1.00000 0.000000 0.000000
3 901.73 0.96081 0.053223 -0.055439
co1 <- multinomRob(model=list(radius ~ x1 + x2 + x3), subj1, starting.values=NULL, equality=list(radius ~ x1 + x2 + x3 + 0))
Error in dimnames(XYdata$Y) <- list(NULL, XYdata$ynames) :
length of 'dimnames' [2] not equal to array extent


I'm coming from a background of several years with MATLAB so this particular message means nothing to me. My prior experience with R is limited to using lm() but I converted for this particular application because I was told it was quite good and handling nonlinear regression. But looking at what I have, I see an array where I have the same number of labels as columns so I have no idea what the issue is. Thank you in advance for your assistance!
 

bryangoodrich

Probably A Mammal
#2
The error is an internal error. Somewhere it is doing that assignment statement within the multinomRob function and it is generating an error. You're not intended to diagnose it yourself, but my guess is that it has something to do with the fact you're using a list of models with one entry. As the help page for that function shows, you're suppose to input a list of formula, like model = list(y1 ~ x1, y2 ~ x2). It appears you're trying to do a multinomial model of one normal variable? You also don't need the starting.values = NULL since that is the default parameter already. Is there a reason you put an equality constraint? Do you know what your statement entails? What are you trying to model in this example that erred?
 
#3
I am trying to use maximum likelihood estimations to get the coefficients A, B, and C for the equation radius = Ax1 + Bx2 + Cx3. The equality function was supposed to indicate I want no constant.

I know least-squares regression does not give me the results I want because my data is really not linear at all, so I was told to try maximum likelihood estimation, which led me to that function. Most of the other MLE functions seem to rely on having a known probability distribution - which I don't have, I just have data points.

And while this data I have does contain data at different difficulty levels so I could technically split it up to get a binomial distribution for logistic regression, that doesn't change the fact what I really need is a final equation that predicts radius, not probability.

Thanks again. I suppose I should know better than to assume because a function works for two entries it should work for one!
 

bryangoodrich

Probably A Mammal
#4
I have no idea about that function. You need to make sure it serves the task you want. If you want to do MLE, I'd suggest looking at what is in the mle package of R. I'm sure what you desire is beyond my skills to give a precise answer, but since you are in ignorance about the probability distribution, it seems a ripe example to use simulation and other computational methods.
 

TheEcologist

Global Moderator
#5
Most of the other MLE functions seem to rely on having a known probability distribution - which I don't have, I just have data points.
Well you are also fitting a distribution to it aren't you? Standard practice would be to fit a variety of different models to your data and select the best and most parsimonious fit. Seldom if ever do we deal with a truly known distribution.

Furthermore, the fact that we are not of much help is because we don't know what you are doing.
In short you cant expect us to understand what is wrong if you give us a function wrapper "multinomRob" and no code. Nor can we tell if any analysis is appropriate if you don't specify exactly what your problem is, your goals are, and the data you have.

This should help, especially point 6.
 
#6
Apologies, I thought I was explaining it well enough but I suppose having my head deep in this for so long made it hard to explain what I was doing.

I was basically trying to use a linear combination of spherical harmonics to model some data. I had participants reaching for a series of points in space and rating the difficulty. I was trying to model the surfaces of each difficulty by fitting the equation r = said linear combination of spherical harmonics while still accounting for difficulty.

As this is not a linear relationship, calculating my coefficients via least squares didn't work and that has been the extent of my experience with regression thus far. What I found has worked was separating the data according to difficulty so I've ended up with a piecewise function: my user selects the individual model to use based on the difficulty, then inputs points to get the result. I found MATLAB's nlmfit worked well to help me calculate the coefficients.

I very much appreciate your finding my thread and trying to help. I figured explaining what I was trying to do and how I fixed it might help people later on if they are Googling something similar. Thanks again!
 

bryangoodrich

Probably A Mammal
#7
You might want to check out the nlm package. There's also an mle function in the stat4 package. You can also do stuff with MLE's through the glm stuff in R.