"Error in X_chosen[data$obsID, ] : subscript out of bounds" after LOGITR - react-error-boundary

I was trying to figure out a mixed logit model with "Willingness-to-pay" (WTP) space utility parameterizations using the LOGITR function. However, the following error comes out: "Error in X_chosen[data$obsID, ] : subscript out of bounds".
I know that one of the indices (maybe obsID?) exceed the array boundary but I would like to know how to solve this issue.
The following is the code I was trying to run:
mxl_pref <- logitr(data = DCE_data, outcome = 'final_decision', obsID = 'id1', pars = c('Test_cost', 'Diagnostic_Yield', 'Counselling_time', 'Turnaround_time'), randPars = c(Diagnostic_Yield = 'n', Counselling_time = 'ln', Turnaround_time = 'ln'), numMultiStarts = 10)
Thank you for your support
Best regards

Related

NMDS with betapart error incorrect dimensions

I have been using the vegdist to run the nmds with no issues, but now I wanted to try for betapart to get the turnover and nestedness. So I tried this code below and got the following error when I tried to run the scores code to then plug into the ggplot: Error in x$species[, choices, drop = FALSE] :
incorrect number of dimensions
I doubled checked my objects for the right numbers, and they looked clear. Not sure what I'm missing. Any help is greatly appreciated.
"# Shannon diversity and evenness"
"matrix_ten <- build_community_data(all_species, plots_tens, tens)"
"# Tens"
"dist_plots_10 <- beta.pair(matrix_ten, index.family = "Sorensen")"
"dist10_sim<- dist_plots_10$beta.sim"
"nmds_plots_10 <- metaMDS(dist10_sim, k=3, try=200, trace=TRUE)"
"nmds_plots_scores_10 <- plots_tens %>%"
"bind_cols(NMDS1 = scores(nmds_plots_10)[,1], NMDS2 = scores(nmds_plots_10)[,2])"

Report with side by side two images and a splited table - Matlab

I am trying in the code below to generate a report with side by side two images and a splited table but I get an error. Why this error occur?
Code:
close all;
clear all;
clc;
import mlreportgen.report.*
import mlreportgen.dom.*
import mlreportgen.utils.*
Name = {'A';'B';'C';'D';'E';'A';'B';'C';'D';'E'};
codeA = [8;3;8;0;4;8;3;8;0;4];
Height = [1;8;4;7;8;8;3;1;0;4];
Weight = [6;2;1;4;5;8;3;1;1;4];
T = table(Name,codeA,Height,Weight,codeA,Height,Weight,codeA,Height,Weight);
Image1 = Image(which('coins.png'));
Image2 = Image(which('sevilla.jpg'));
rpt = Report("myPDF","pdf");
imgStyle = {ScaleToFit(true)};
Image2.Style = imgStyle;
Image1.Style = imgStyle;
lot = Table({Image2, ' ', Image1});
lot.entry(1,1).Style = {Width('3.2in'), Height('3in')};
lot.entry(1,2).Style = {Width('.2in'), Height('3in')};
lot.entry(1,3).Style = {Width('3.2in'), Height('3in')};
lot.Style = {ResizeToFitContents(false), Width('100%')};
add(rpt, lot);
chapter = Chapter("Title",'Table Report');
table = FormalTable(T);
table.Border = 'Solid';
table.RowSep = 'Solid';
table.ColSep = 'Solid';
para = Paragraph(['The table is sliced into two tables, '...
'with the first column repeating in each table.']);
para.Style = {OuterMargin('0in','0in','0in','12pt')};
para.FontSize = '14pt';
add(chapter,para)
slicer = TableSlicer("Table",table,"MaxCols",5,"RepeatCols",1);
totcols = slicer.MaxCols - slicer.RepeatCols;
slices = slicer.slice();
for slice=slices
str = sprintf('%d repeating column and up to %d more columns',...
slicer.RepeatCols,totcols);
para = Paragraph(str);
para.Bold = true;
add(chapter,para)
add(chapter,slice.Table)
end
add(rpt,chapter)
close(rpt)
rptview(rpt)
Error:
*Index exceeds the number of array elements. Index must not exceed 10.
Error in try1 (line 26)
lot.entry(1,1).Style = {Width('3.2in'), Height('3in')};*
You define the variable
Height = [1;8;4;7;8;8;3;1;0;4];
Then you try and use the report gen function Height
lot.entry(1,1).Style = {Width('3.2in'), Height('3in')};
Because you've shadowed the Height function with a variable, MATLAB is trying to get the element of this array at index '3in', which is either nonsensical or (via some implicit ASCII conversion) is way out of range.
Per my comment on your previous question, I think the way the documentation suggests the report gen functions are imported is bad practice. By using import mlreportgen.dom.* you are putting all of the nicely name-spaced functions from that package into the common area, and in this case it has caused an unclear clash between two things. So there are two options:
Use the namespaced version of Height (and Width), if you did this with all of the report gen functions you would not need the import. The nice side-effect is you get tab-completion when typing the various functions from this package
lot.entry(1,1).Style = {mlreportgen.dom.Width('3.2in'), mlreportgen.dom.Height('3in')};
Sure, you code is longer, but it is more explicit.
... or ...
Simply don't define a variable called Height. Rename this and everything else can stay the same.

Ironpython script in Ansys Customization tool

I'm a beginner in Python and I'm working with the Ansys Customization Tool (ACT) to add my own extension.
Is there a direct way to fill a file with every node's coordinates after deformation?
hopefully in 3 lines or columns: x , y , z
So far I only found the GetNodeValue object but it only gives me the displacement and I need the deformed coordinates for the entire model.
My first idea was to add the displacements to the initial coordinates but I didn't manage to do it.
Many thanks for your help
Lara
APDL Snippet
Add an APDL Snippet in the solution part of the tree:
/prep7
UPGEOM,1,1,1,file,rst ! adds the displacements to the nodal coordinates.
cdwrite,geom,nodesAndelements,geom ! Writes node and element data to nodesAndelement.geom
I'm not sure if you can work with the output format from cdwrite, but this is the quickest solution i can think of.
If you want to automate you have to insert the command snippet via
solution = ExtAPI.DataModel.Project.Model.Analyses[0].Solution
fullPath = "path//to//snippet"
snippet = solution.AddCommandSnippet()
snippet.ImportTextFile(fullPath)
ACT
If you want to stay in ACT it could be done like this:
global nodeResults
import units
analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
mesh = analysis.MeshData
# Get nodes
allNodes = mesh.Nodes
# get the result data
reader = analysis.GetResultsData()
# get the deformation result
myDeformation = reader.GetResult("U")
nodeResultsTemp = []
result_unit = myDeformation.GetComponentInfo("X").Unit
for node in allNodes:
# get node deformation and convert values in meter
deformationNode1 = myDeformation.GetNodeValues(node.Id)
deformationNode1[0] = units.ConvertUnit(deformationNode1[0],result_unit,"m","Length")
deformationNode1[1] = units.ConvertUnit(deformationNode1[1],result_unit,"m","Length")
deformationNode1[2] = units.ConvertUnit(deformationNode1[2],result_unit,"m","Length")
# add node coordinates (in meter) to the displacement
mesh_unit = mesh.Unit
node1 = mesh.NodeById(node.Id)
node1CoorX = units.ConvertUnit(node1.X,mesh_unit,"m","Length")
node1CoorY = units.ConvertUnit(node1.Y,mesh_unit,"m","Length")
node1CoorZ = units.ConvertUnit(node1.Z,mesh_unit,"m","Length")
deformationNode1[0] = deformationNode1[0]+node1CoorX
deformationNode1[1] = deformationNode1[1]+node1CoorY
deformationNode1[2] = deformationNode1[2]+node1CoorZ
nodeResultsTemp.append([node1.X,node1.Y,node1.Z,deformationNode1[0],deformationNode1[1],deformationNode1[2]])
nodeResults = nodeResultsTemp

How to overcome indefinite matrix error (NbClust)?

I'm getting the following error when calling NbClust():
Error in NbClust(data = ds[, sapply(ds, is.numeric)], diss = NULL, distance = "euclidean", : The TSS matrix is indefinite. There must be too many missing values. The index cannot be calculated.
I've called ds <- ds[complete.cases(ds),] just before running NbClust so there's no missing values.
Any idea what's behind this error?
Thanks
I had same issue in my research.
So, I had mailed to Nadia Ghazzali, who is the package maintainer, and got an answer.
I'll attached my mail and her reply.
my e-mail:
Dear Nadia Ghazzali. Hello Nadia. I have some questions about
NbClust function in R library. I have tried googling but could not
find satisfying answers. First, I’m so grateful for you to making
this awsome R library. It is very helpful for my reasearch. I tested
NbClust function in NbClust library with my own data like below.
> clust <- NbClust(data, distance = “euclidean”,
min.nc = 2, max.nc = 10, method = ‘kmeans’, index =”all”)
But soon, an error has occurred. Error: division by zero! Error in
Indices.WBT(x = jeu, cl = cl1, P = TT, s = ss, vv = vv) : object
'scott' not found So, I tried NbClust function line by line and
found that some indices, like CCC, Scott, marriot, tracecovw,
tracew, friedman, and rubin, were not calculated because of object
vv = 0. I’m not very familiar with argebra so I don’t know meaning
of eigen value. But it seems to me that object ss(which is squart of
eigenValues) should not be 0 after prodected.
So, here is my questions.
I assume that my data is so sparse(a lot of zero values) that sqrt(eigenValues) becomes too small, is that right? I’m sorry I
can’t attach my data but I can attach some part of eigenValues and
squarted eigenValues.
> head(eigenValues)
[1] 0.039769880 0.017179826 0.007011972 0.005698736 0.005164871 0.004567238
> head(sqrt(eigenValues))
[1] 0.19942387 0.13107184 0.08373752 0.07548997 0.07186704 0.06758134
And if my assume is right, what can I do for this problems? Only one
way to drop out 7 indices?
Thank you for reading and I’ll waiting your reply. Best regards!
and her reply:
Dear Hansol,
Thank you for your interest. Yes, your understanding is good.
Unfortunately, the seven indices could not be applied.
Best regards,
Nadia Ghazzali
#seni The cause of this error is data related. If you look at the source code of this function,
NbClust <- function(data, diss="NULL", distance = "euclidean", min.nc=2, max.nc=15, method = "ward", index = "all", alphaBeale = 0.1)
{
x<-0
min_nc <- min.nc
max_nc <- max.nc
jeu1 <- as.matrix(data)
numberObsBefore <- dim(jeu1)[1]
jeu <- na.omit(jeu1) # returns the object with incomplete cases removed
nn <- numberObsAfter <- dim(jeu)[1]
pp <- dim(jeu)[2]
TT <- t(jeu)%*%jeu
sizeEigenTT <- length(eigen(TT)$value)
eigenValues <- eigen(TT/(nn-1))$value
for (i in 1:sizeEigenTT)
{
if (eigenValues[i] < 0) {
print(paste("There are only", numberObsAfter,"nonmissing observations out of a possible", numberObsBefore ,"observations."))
stop("The TSS matrix is indefinite. There must be too many missing values. The index cannot be calculated.")
}
}
And I think the root cause of this error is the negative eigenvalues that seep in when the number of clusters is very high, i.e. the max.nc is high. So to solve the problem, you must look at your data. See if it got more columns then rows. Remove missing values, check for issues like collinearity & multicollinearity, variance, covariance etc.
For the other error, invalid clustering method, look at the source code of the method here. Look at line number 168, 169 in the given link. You are getting this error message because the clustering method is empty. if (is.na(method))
stop("invalid clustering method")

(App Designer) Error using matlab.ui.control.EditField/set.Value (line 96) 'Value' must be a character vector

So I am creating an app to find a value based on several inputs but hit an error as one of the outputs won't show.
This is the app layout
1
The problem is the total cost section won't show the value when I clicked the calculate button. The 'Q Optimal' works just fine.
2
the formula associated with the button on the right side looks like this:
dm=app.MinimumDemandEditField.Value;
dM=app.MaximumDemandEditField.Value;
tm=app.MinimumLeadTimeEditField.Value;
tM=app.MaximumLeadTimeEditField.Value;
r1=app.ReorderLevelEditField.Value;
Et = 0.5*(tm+tM);
vart = 1/12*(tM-tm)^2;
Ed = 0.5*(dm+dM);
vard = 1/12*(dM-dm)^2;
ED = 1/4*(dm+dM)*(tm+tM);
varD = 1/144*(3*(dm+dM)^2*(tM-tm)^2+3*(dM-dm)^2*(tm+tM)^2+(tM-
tm)^2*(dM-dm)^2);
gt = 1/(tM-tm);
fd = 1/(dM-dm);
fD = 1/((dM-dm)*(tM-tm));
f1=app.FixedCostEditField.Value;
c1=app.VariableCostEditField.Value;
h=app.HoldingCostEditField.Value;
s=50*c1;
app.ShortageCostEditField.Value = s
A1=c1+(h/Ed)*(r1-ED);
A2=fD*(r1*(tM-tm)*log(r1/(tM*dm))-(r1^2/dM)+(r1*tM)-
(r1*tm)*log((dM*tM)/r1)-Et);
syms x;
f=(x-r1)*fD;
EB= int(f,r1,dM*tM);
A3=Ed*f1+h*Ed*(fD*((r1^2*tm/2)-(dm*r1/2)*(tM^2-tm^2)+(dm^2/6)*
(tM^3-tm^3)-((r1^3/6*dM)-(dM*r1*tm^2/2)+(dM^2*tm^3/6)))+(fD/18)*
(tM^3-tm^3)*(dM^3-dm^3)-r1*ED+Ed*s*EB);
Q=(1/h)*((Ed*(A1+h*A2-c1)+(h*(ED-r1))));
Eoh=fD*((((r1^3*tM)/2)-(((dm*r1)/2)*(tM^2-tm^2))+(((dm^2)/6)*
(tM^3-tm^3))-((r1^3)/(6*dM))-((dM*r1*tm^2)/2)+((dM^2*tm^3)/6))+
((Q^2)/2*Ed)-(Q*ED/Ed)+((fD/(18*Ed))*((tM^3-tm^3)*(dM^3-dm^3)))+
(Q*r1/Ed)-(r1*ED/Ed));
TC= f1+c1*Q+h*Eoh+s*EB;
app.QOptimalEditField.Value = Q
app.TotalCostEditField.Value = TC
Running this gives the error:
3
I suspect the problem is with my integration process. Have I missed something or is there a better way to do this?
Thank you in advance
Regards,
Kevin Renard
I solved the problem as I noticed that the last error notification states that the input value must be a double scalar and the value of the integration process is not a double scalar, so I revised the integration code into:
syms x;
f=(x-r1)*fD;
EB= double(int(f,r1,dM*tM));
1