everybody.
I am trying to run an LCA using poLCA package. I have six categorical variables, from which one is binary (gender) and the other ones range from 3 to 7 categories. I keep getting an alert message as follows:
ALERT: some manifest variables contain values that are not
positive integers. For poLCA to run, please recode categorical
outcome variables to increment from 1 to the maximum number of
outcome categories for each variable.
I applied as.integer() and I tried recoding replacing level 0, but it is still not working. Any ideas on how this could be, please? Thank you in advance!
Below, my code:
f<- with(mydata, cbind(v1, v2, v3, v4, v5, v6)~outcome)
LCA<-poLCA(f, data, nclass=6, nrep=50)
summary(LCA)
Output:
ALERT: some manifest variables contain values that are not
positive integers. For poLCA to run, please recode categorical
outcome variables to increment from 1 to the maximum number of
outcome categories for each variable.
Manifest values needs to be an integer starting from 1 and not 0, hence it shows that error.
You need to add 1 to your dataset.
data=data+1;
Now run the function :)
For continuous variables (if you have in your dataset, you can round them to nearest digit)
round(mydata, digits=0)
Related
In my dataset, I have a variable which takes values like abc-ABC or abc-def-ABC (i.e., one or more lower-case codes and one upper-case code). I would like to (1) count the number of lower-case codes and capture this no. in a new variable (2) multiply the initial observation by this number (e.g., for abc-def-ABC, I would want 2 obs). Can anyone help?
I don't understand what you want with (2) but... To count the occurrences, can't you just
code = 'abc-def-ABC';
observations = numel(regexp(code, '[a-z]+-'))
How could I correlate the first (also second and third, etc) line of each function together? I meant I want to pick up the value of the first line of function 1, first line of function 2 and so on... Specially number of these lines (between two #...#) are not always equal.
Let's say the values between (# -#) is one matrix. I see that the problem is I need to break them down into different matrix and then equalize all these matrix to the same size by adding NaN values and then reconstruct them again. That is what I think but I dont know how to ask Matlab do these tasks.
Would you please give me a help?
Thank you very much !!
I have a set of numbers and I want to use predictive coding to get smaller values for this set of data as each value should not differ to much from the last. I was just starting very simply with a expected value that each value would be the same as the last, and then just store the error.
For some simple data:
1 2 -3 1
The values I should get are
1 1 -5 4
The way I was doing this compression was one line, but to decompress I need the last value, so I put this in a loop. Is there a way to do this, and possibly more complex(looking at more the just the last value) predictive coding without needing to use Matlab loops.
As suggested by #Divakar, constructing the new values can be done by
B = [A(1) diff(A)];
Obtaining the original from this result, the inverse of the above procedure, is done through
A = cumsum(B);
Back to basics. How can I extract max and min values from 'variable' table in workspace? min(nameofvariable) don't work, returns an error message 'Subscript indices must either be real positive integers or logicals'.
Thanks for your help!
Assuming you have a matrix called nameofvariable, the correct syntax is indeed:
min(nameofvariable)
This will give you the column wise min
For the full minimum:
min(nameofvariable(:))
The error you have suggests that you have a variable named min (try to avoid this at all times), try:
clear min
min(nameofvariable)
can I do this with the standard SQL or I need to create a function for the following problem?
I have 14 columns, which represent 2 properties of 7 consecutive objects (the order from 1 to 7 is important), so
table.object1prop1, ...,table.object1prop7,table.objects2prop2, ..., table.objects2prop7.
I need compute the minimum value of the property 2 of the 7 objects that have smaller values than a specific threshold for property 1.
The values of the property 1 of the 7 objects take values on a ascending arithmetic scale. So property 1 of the object 1 will ever be smaller than property 2 of the objects 1.
Thanks in advance for any clue!
This would be easier if the data were normalized. (Hint, any time you find a column name with a number in it, you are looking at a big red flag that the schema is not in 3rd normal form.) With the table as you describe, it will take a fair amount of code, but the greatest() and least() functions might be your best friends.
http://www.postgresql.org/docs/current/interactive/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
If I had to write code for this, I would probably feed the values into a CTE and work from there.