I'm trying to use the mnrfit
function but I get the error
If Y is a column vector, it must contain positive integer category numbers.
.
My data is in a double and my Y values are floats , eg 0.6667. Is there a way that I can adjust my data to be able to use the mnrfit function?
Thanks in advance! An unexperienced beginner
Y
should be a "nominal outcome", ie non-continuous, to use mnrfit
. We don't need to turn Y
into integers, just categoricals. A categorical array is discrete as far as MATLAB is concerned, regardless whether the categories are represented by double values.
X = rand(5,3); % Predictors (should be double or single)
Y = rand(5,1); % Response (doubles, will cause error)
B = mnrfit( X, Y )
% ERROR: If Y is a column vector, it must contain positive integer category numbers.
B = mnrfit( X, categorical(Y) )
% No error, regression matrix B is output successfully.
Be careful , if you're expecting a continuous response variable (hence why Y
is a vector of doubles) then mnrfit
may not be suitable in the first place!
Note the valid data types are specified in the docs
Y can be one of the following:
An n-by-k matrix, where Y(i,j) is the number of outcomes of the multinomial category j for the predictor combinations given by X(i,:). In this case, the number of observations are made at each predictor combination.
An n-by-1 column vector of scalar integers from 1 to k indicating the value of the response for each observation. In this case, all sample sizes are 1.
An n-by-1 categorical array indicating the nominal or ordinal value of the response for each observation. In this case, all sample sizes are 1.
I have quick question when I use "B = merit( X, categorical(Y) )" I am getting a negative Beta value but the actual Beta value is positive of what I got. EX) actual Beta = 50 , -90 , 8 what I am getting= -50, 90 ,-8
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.