SEM Model Syntax Given Path Diagram - statistics

I am trying to recreate an analysis of mediation using SEM. I have the following path diagram
It's clear to me that "FM" is related to "EI" through RMR. The indirect effect is 0.25 (0.40 * 0.63) with a "direct effect" of -0.41. However, I am unable to confidently write the model syntax for lavaan . How would one write this syntax?
Additionally, what do the double arrows represent (for example, 0.11 between FM and FFM) -- is this the "covariance". Does this impact the paths going from FM to FFM? Lastly, is this mediation model achievable just using an OLS framework? What advantage did SEM provide?

I would first recommend reading the method section of the paper that diagram came from because it will give you additional clues about their model that can't always be seen from a path diagram. However, I think the model would look something like this (but check that you get the same coefficient estimates as in the diagram):
model <- '
EI ~ RMR + FM
RMR ~ FM + FFM + Age + Sex
FM ~~ FFM
FM ~~ Age
FM ~~ Sex
FFM ~~ Age
FFM ~~ Sex
Age ~~ Sex
'
The double arrows (indicated by ~~ in the model) represent the covariance of the residuals. You would include these if you think two variables are related beyond what you were able to measure. Whether you include those residual covariances or not will affect the estimated coefficients because in one case you are saying the variables are unrelated beyond the measured variables, and in the other case you are expecting there to be some association.
I dont think this is achievable with regular OLS, although I'm not 100% sure. SEM has the benefit of modelling latent variables (which you dont have), but it also allows for simultaneous estimation of multiple dependent variables (which you do have). Additionally, notice that the model is actually constrained because it is not modelling a path between Age and EI, for example, and SEM allows for arbitrary constraints that aren't easy to achieve with OLS

I realize this post is years old, but I typically use Onyx to draw path diagrams and have it generate the code for lavaan. Not sure how well it handles mediation-
I would double-check it, but in my experience it has worked out well and is easy to do.
Link to Onyx download here: https://onyx-sem.com/
If you draw your path diagram and right-click, there should be an option to generate code for lavaan, OpenMX, etc. You can also change the arrow heads after drawing them to represent covariances.

Related

How would I construct an integer optimization model corresponding to a graph

Suppose we're given some sort of graph where the feasible region of our optimization problem is given. For example: here is an image
How would I go on about constructing these constraints in an integer optimization problem? Anyone got any tips? Thanks!
Mate, I agree with the others that you should be a little more specific than that paint-ish picture ;). In particular you are neither specifying any objective/objective direction nor are you giving any context, what about this graph should be integer-variable related, except for the existence of disjunctive feasible sets, which may be modeled by MIP-techniques. It seems like your problem is formalization of what you conceptualized. However, in case you are just being lazy and are just interested in modelling disjunctive regions, you should be looking into disjunctive programming techniques, such as "big-M" (Note: big-M reformulations can be problematic). You should be aiming at some convex-hull reformulation if you can attain one (fairly easily).
Back to your picture, it is quite clear that you have a problem in two real dimensions (let's say in R^2), where the constraints bounding the feasible set are linear (the lines making up the feasible polygons).
So you know that you have two dimensions and need two real continuous variables, say x[1] and x[2], to formulate each of your linear constraints (a[i,1]*x[1]+a[i,2]<=rhs[i] for some index i corresponding to the number of lines in your graph). Additionally your variables seem to be constrained to the first orthant so x[1]>=0 and x[2]>=0 should hold. Now, to add disjunctions you want some constraints that only hold when a certain condition is true. Therefore, you can add two binary decision variables, say y[1],y[2] and an additional constraint y[1]+y[2]=1, to tell that only one set of constraints can be active at the same time. You should be able to implement this with the help of big-M by reformulating the constraints as follows:
If you bound things from above with your line:
a[i,1]*x[1]+a[i,2]-rhs[i]<=M*(1-y[1]) if i corresponds to the one polygon,
a[i,1]*x[1]+a[i,2]-rhs[i]<=M*(1-y[2]) if i corresponds to the other polygon,
and if your line bounds things from below:
-M*(1-y[1])<=-a[i,1]*x[1]-a[i,2]+rhs[i] if i corresponds to the one polygon,
-M*(1-y[1])<=-a[i,1]*x[1]-a[i,2]+rhs[i] if i corresponds to the other polygon.
It is important that M is sufficiently large, but not too large to cause numerical issues.
That being said, I am by no means an expert on these disjunctive programming techniques, so feel free to chime in, add corrections or make things clearer.
Also, a more elaborate question typically yields more elaborate and satisfying answers ;) If you had gone to the effort of making up a true small example problem you likely would have gotten a full formulation of your problem or even an executable piece of code in no time.

How to Use conceptual dependencies , predicate calculus/logic , conceptual graph in NLP

How to Solve This Problem ..?
Using
conceptual dependencies
predicate calculus/logic
conceptual graph
to represent the following sentences
a) All dogs bark.
b) No school buses are purple.
c) Some drivers do not obey the speed limit
d) Mary borrows a book with red cover from the library.
f) Every book is either an encyclopedia or a dictionary but not both.
This seems like a homework assignment. If it is, I'd love to know more about the class. It seems to be one I would like to know the professor etc.
Because it amuses me, I'll try one of these.
All dogs bark.
this seems to be an English form of the predicate calculus.
forall ((x Dog)) (bark x).
assuming that Dog is defined as a proper category and bark is an appropriate predicate.
I can't help with the Conceptual Dependency representation unless you share what set of primitives you have to work with. Do you use PTRANS and MTRANS ? Is the air moving from a bark considered to be a physical object moved ? We need more definition to understand what you are trying to do.
Why did you not include DRS ? It seems to be a very common representation in many NLP applications currently.
Which syntax for Conceptual graphs are you using? the original John Sowa set from 1984? What grammar do you need to use ? CGIF ? Common Logic ?
Best Wishes,
David

UML constraint across three associations?

Let's say I have class A with associations to classes X, Y, and Z, respectively. I need to indicate that only one of these associations may be instantiated for any given instance of class A (so, an xor constraint). I know how to do this if the constraint is just across two associations. Obviously I can just make three seperate xor constraints (X-Y, X-Z, Y-Z) but I'm wondering if there is a better/cleaner/proper way to do it?
edit: The multiplicity constraints on the respective associations are not the same. Using an abstract class or interface will not work. Furthermore, a note is insufficient. I need to use some sort of formalized structure, preferably something standardized (e.g. by OMG) to express this because I am programmatically processing the model elements (i.e. it isn't just a picture). I understand how the underlying model for UML provides for this facility. It also specifies (though slightly vaguely) how it should be notated. I guess my main issue is, in fact, with finding a tool that allows me to make that notation. I don't think MagicDraw does so. I should have stated these things earlier.
FWIW, I'm using MagicDraw. It would be a nice bonus if the I could do this in a way that MagicDraw actually understood. I can live with it if that isn't possible.
The xor constraint is just a stylized and rather under-specified constraint for the 2-way case.
You can define an explicit constraint (in Complete OCL) as:
context A
inv OnlyAorBorC: A->size() + B->Size() + C->size() <= 1
MagicDraw may allow you to specify a similar contextual Constraint on A.
If "X", "Y" and/or "Z" can be somehow generalized (I mean, if you not doing this puraly for a conditional flow control), you can make an interface (or and abstract class) "I" for example, and make "X", "Y" and "Z" implement this interface. Then, you put an association with multiplicity 1 between A and the interface I.
See the diagram below:
Edit: The example above doesn't work in the case of A having different cardinalities between X, Y and Z. For this case, the only way that I can see is use an UML Constraint to restrict those relationships. You can define a Constraint in UML putting some OCL expression between curly braces. E. g.
Here, account owner is either Person or Corporation and this {xor} is predefined UML constraint.
I'm not sure about the details of your cardinalities requirements but, a combination between this {xor} and the interface example that I gave might be enough. At least it gives you a little bit more of options, like:
If you need to know more about the UML constraints subject, I got this example from uml-diagrams.org: http://www.uml-diagrams.org/constraint.html

Mapping interchangeably terms such as Weight to Mass for QAnswering NLP

I've been working on a Question Answering engine in C#. I have implemented the features of most modern systems and are achieving good results. Despite the aid of Wordnet , one problem I haven't been able to solve yet is changing the user input to the correct term.
For example
changing Weight -> Mass
changing Tall -> Height
My question is about the existence of some sort of resource that can aid me in this task of changing the terms to the correct terms.
Thank You
Looking at all the synsets in WordNet for both Mass and Weight I can see that there is no shared synset and thus there is no meaning in common. Words that actually do have the same meaning can be matched by means of their synset labels, as I'm sure you've realized.
In my own natural language engine (http://nlp.abodit.com) I allow users to use any synset label in the grammar they define but I would still create two separate grammar rules in this case, one recognizing questions about mass and one recognizing questions about weight.
However, there are also files for Wordnet that give you class relationships between synsets too. For example, if you type 'define mass' into my demo page you'll see:-
4. wn30:synset-mass-noun-1
the property of a body that causes it to have weight in a gravitational field
--type--> wn30:synset-fundamental_quantity-noun-1
--type--> wn30:synset-physical_property-noun-1
ITokenText, IToken, INoun, Singular
And if you do the same for 'weight' you'll also see that it too has a class relationship to 'physical property'.
In my system you can write a rule that recognizes a question about a 'physical property' and perhaps a named object and then try to figure out which physical property they are likely to be asking about. And, perhaps, if you can't match maybe just tell them all about the physical properties of the object.
The method signature in my system would be something like ...
... QuestionAboutPhysicalProperties (... IPhysicalProperty prop,
INamedObject obj, ...)
... and in code I would look at the properties of obj and try to find one called 'prop'.
The only way that I know how to do this effectively requires having a large corpus of user query sessions and a happiness measure on sessions, and then finding correlations between substituting word x for word y (possibly given some context z) that improves user happiness.
Here is a reasonable paper on generating query substitutions.
And here is a new paper on generating synonyms from anchor text, which doesn't require a query log.

draw UML like diagram to represent math algorithm

Suppose I have math algorithm e.g.
A = B + C
C = D + E
F = B + D
I would like to draw a diagram to represent it and the flow of the algorithm i.e. people know how the value of A calculate. Is there tool or the name of UML diagram that I can take a look?
Maybe a Dataflow Diagram?
Something like this:
It's not part of UML, but can be a very useful way to show computation.
hth.
There is an proposal to supplement UML diagrams by the diagrams called KOPENOGRAM. Which rather on data flow focus on algorithmical structure, conditions, loops, etc. As this is an proposal, limited specific tools exist to generate or draw kopenograms from source code (AFAIK there are Java plugins for BlueJ or NetBeans). However, Excel or any spreadsheet app might be used to make table and borders.
Your example will look like:
No dependency is shown on operations as in previous example, as this is task rather for compiler.
UML diagrams are either about static structure (classes/components/packages) or interaction between entities (activity/sequence diagrams/state machines).
Algorithms or algorithm design are not covered by UML (very much like any other type of concrete method specification).

Resources