Choice data with no-choice option in mlogit - nested

I struggle with modeling a no-choice option within the mlogit package to estimate part worths from conjoint data. I have choice data from 600 respondents (respid). Each respondent choose between 3 hypothetical products (alt: A-C) and a no choice option (alt: D). Everyone does the choice 4 times (ques).
I prepare the data the following:
data.test<-mlogit.data(data=robottest, choice="choice", shape="long", varying = 4:7, alt.var = "alt", alt.levels = paste("pos",1:4),id.var = "respid")
I get the following error message but it does create the data anyway.
Warning messages:
1: In mlogit.data(data = robottest, choice = "choice", shape = "long", :
variable alt exists and will be replaced
2: Setting row names on a tibble is deprecated.
I than want to estimate the model with the following code
m1<-mlogit(data=data.test, choice~apperance+features+brand+price, nests = list(Buy=c("A","B","C"), NoBuy=c("D")), unscaled = TRUE)
That does not work and I get the error saying
Error in solve.default(H, g[!fixed]) :
system is computationally singular: reciprocal condition number = 4.91778e-24
Do somebody know how to solve this issue? Would you model the no-choice option in general the same as I did? Any help is more than welcommed! Thank you very much.
Bests,
Michael
My data looks like this

Related

RStudio - Stargazer issue - text table

I am currently learning RStudio (beginner level) and I have a question regarding stargazer function and especially how to create the table of descriptive statistics. I did start by updloading my dataset (called d) and all relevant libraries like stargazer. I did run command line:
stargazer(d, type = 'text', title = "Statistiques descriptives",digits = 1, out="table1.txt")
There is an error message:
*Error in if (nchar(text.matrix[r, c]) > max.length[real.c]) { :
missing value where TRUE / FALSE is required*
How can I complete the table with relevant information (mean, standard deviation...) ?
Thank you
Try to describe your data more in detail. Provide a minimal working example, if possible. The command is fine in principle:
library(stargazer)
stargazer(mtcars, type = 'text', title = "Statistiques descriptives",digits = 1, out="table1.txt")
Same issue was related to underscore in variable names:
How to fix 'Error in if (nchar(text.matrix[r, c]) > max.length[real.c]) { : missing value where TRUE/FALSE needed' using stargazer in rstudio?
Please provide str of your dataframe.

How to set compound structure for two different layers if I used 2 different categories of material for wall structure , using revit api

I am trying to create a wall with 2 layers and each layer materials are different. When I try to set the CompoundStructure for the wall I am getting an exception that CompoundStructure is not valid.
CompoundStructure cStructure = CompoundStructure.CreateSimpleCompoundStructure(clayer);
wallType.SetCompoundStructure(cStructure);
Can anyone tell me how I can create compound structure for layers with different materials?
First of all, solve your task manually through the end user interface and verify that it works at all.
Then, use RevitLookup and other database exploration tools to examine the results in the BIM elements, their properties and relationships.
Once you have done that, you will have a good idea how to address the task programmatically – and have confidence that it will work as expected:
How to research to find a Revit API solution
Intimate Revit database exploration with the Python Shell
newWallMaterial = wallMaterial.Duplicate("newCreatedMaterial");
newWallmaterial2 = wallMaterial.Duplicate("NewCreatedMAterial2");
//roofMaterial3 = roofMaterial2.Duplicate("NewCreatedMAterial3");
bool usr = newWallMaterial.UseRenderAppearanceForShading;
//newWallMaterial.Color = BuiltInTypeParam.materialCol;
foreach (Layers layer in layers)
{
if (layer.layerId == 0)
{
c = new CompoundStructureLayer(layer.width, layer.materialAssignement, newWallMaterial.Id);
newWallMaterial.Color = color;
clayer.Add(c);
}
if (layer.layerId == 1)
{
c1 = new CompoundStructureLayer(layer.width, layer.materialAssignement, newWallmaterial2.Id);
newWallmaterial2.Color = color;
clayer.Add(c1);
}

How can I set transparent walls in a given view with Revit API?

I try to set transparent walls, using pyRevit. I do the following:
categories = List[ElementId]()
wallCatId = ElementId(BuiltInCategory.OST_Walls)
categories.Add(wallCatId)
ogs = OverrideGraphicSettings()
ogs.SetSurfaceTransparency(70)
t = Transaction(doc, "New parameter filter")
t.Start()
filter = ParameterFilterElement.Create(doc, "Walls filter", categories)
t.Commit()
all_views = FilteredElementCollector(doc).OfClass(View).ToElements()
for i in all_views:
if (i.ViewType == ViewType.ThreeD) or (i.ViewType == ViewType.FloorPlan):
views_to_treat.append(i)
t = Transaction(doc, "New visibility filter")
t.Start()
for i in views_to_treat:
i.AddFilter(filter.Id)
i.SetFilterOverrides(filter.Id, ogs)
t.Commit()
Nothing happens, I don't know why. Is it my "categories" that is wrongly defined (how can I know what kind of ElementId it expects? Is it the Id of the Wall Category? In that case, it should be ok here)? Or is it when applying the filter override to the view?
Any help would be greatly appreciated!
Arnaud.
I can see that you are applying the transparency filter to Walls. I am not 100% sure that this is the most efficient way to achieve this since we can override transparency via Category override. Please keep in mind that Filters are limited as we can apply only a handful of them to the view. There is a max number. I don't remember from top of my head, but there is. Also, order of filters matters, as they can potentially override each other's rules based on order. Either way overriding transparency can be achieved by changing it on a Category like so:
catId = ElementId(BuiltInCategory.OST_Walls)
all_views = FilteredElementCollector(doc).OfClass(View).ToElements()
overrides = OverrideGraphicSettings()
overrides.SetSurfaceTransparency(70)
t = Transaction(doc, "Override Categories")
t.Start()
for i in all_views:
if ((i.ViewType == ViewType.ThreeD) or (i.ViewType == ViewType.FloorPlan)) and (i.IsCategoryOverridable(catId)):
try:
i.SetCategoryOverrides(catId, overrides)
except:
# print out error?
pass
t.Commit()
Also, just a few generic comments. Try to minimize the amount of times you iterate over lists, especially if they are the same items. If you can do what you need to do in the first loop, then that's the best. The above can be simplified even more with list comprehension but I wanted to keep it "obvious" for educational purposes.
I am also checking if Category is overridable before attempting to do so. Why? Because if view category overrides are controlled by a view template, it will not allow us to set the overrides. Also some categories don't have a surface transparency override ex. lines if I remember correctly.
Finally I like to put it all in a try/except statement so that i can catch any issues in my loop and still continue with other items. if I don't do that, and one view fails, we would have failed the whole operation.
This is what the result should be:

Find all references to a supplied noun in StanfordNLP

I'm trying to parse some text to find all references to a particular item. So, for example, if my item was The Bridge on the River Kwai and I passed it this text, I'd like it to find all the instances I've put in bold.
The Bridge on the River Kwai is a 1957 British-American epic war film
directed by David Lean and starring William Holden, Jack Hawkins, Alec
Guinness, and Sessue Hayakawa. The film is a work of fiction, but
borrows the construction of the Burma Railway in 1942–1943 for its
historical setting. The movie was filmed in Ceylon (now Sri Lanka).
The bridge in the film was near Kitulgala.
So far my attempt has been to go through all the mentions attached to each CorefChain and loop through those hunting for my target string. If I find the target string, I add the whole CorefChain, as I think this means the other items in that CorefChain also refer to the same thing.
List<CorefChain> gotRefs = new ArrayList<CorefChain>();
String pQuery = "The Bridge on the River Kwai";
for (CorefChain cc : document.get(CorefCoreAnnotations.CorefChainAnnotation.class).values()) {
List<CorefChain.CorefMention> corefMentions = cc.getMentionsInTextualOrder();
boolean addedChain = false;
for (CorefChain.CorefMention cm : corefMentions) {
if ((!addedChain) &&
(pQuery.equals(cm.mentionSpan))) {
gotRefs.add(cc);
addedChain = true;
}
}
}
I then loop through this second list of CorefChains, re-retrieve the mentions for each chain and step through them. In that loop I show which sentences have a likely mention of my item in a sentence.
for (CorefChain gr : gotRefs) {
List<CorefChain.CorefMention> corefMentionsUsing = gr.getMentionsInTextualOrder();
for (CorefChain.CorefMention cm : corefMentionsUsing) {
//System.out.println("Got reference to " + cm.mentionSpan + " in sentence #" + cm.sentNum);
}
}
It finds some of my references, but not that many, and it produces a lot of false positives. As might be entirely apparently from reading this, I don't really know the first thing about NLP - am I going about this entirely the wrong way? Is there a StanfordNLP parser that will already do some of what I'm after? Should I be training a model in some way?
I think a problem with your example is that you are looking for references to a movie title, and there isn't support in Stanford CoreNLP for recognizing movie titles, book titles, etc...
If you look at this example:
"Joe bought a laptop. He is happy with it."
You will notice that it connects:
"Joe" -> "He"
and
"a laptop" -> "it"
Coreference is an active research area and even the best system can only really be expected to produce an F1 of around 60.0 on general text, meaning it will often make errors.

Filtering Haystack (SOLR) results by django_id

With Django/Haystack/SOLR, I'd like to be able to restrict the result of a search to those records within a particular range of django_ids. Getting these IDs is not a problem, but trying to filter by them produces some unexpected effects. The code looks like this (extraneous code trimmed for clarity):
def view_results(request,arg):
# django_ids list is first calculated using arg...
sqs = SearchQuerySet().facet('example_facet') # STEP_1
sqs = sqs.filter(django_id__in=django_ids) # STEP_2
view = search_view_factory(
view_class=SearchView,
template='search/search-results.html',
searchqueryset=sqs,
form_class=FacetedSearchForm
)
return view(request)
At the point marked STEP_1 I get all the database records. At STEP_2 the records are successfully narrowed down to the number I'd expect for that list of django_ids. The problem comes when the search results are displayed in cases where the user has specified a search term in the form. Rather than returning all records from STEP_2 which match the term, I get all records from STEP_2 plus all from STEP_1 which match the term.
Presumably, therefore, I need to override one/some of the methods in for SearchView in haystack/views.py, but what? Can anyone suggest a means of achieving what is required here?
After a bit more thought, I found a way around this. In the code above, the problem was occurring in the view = search_view_factory... line, so I needed to create my own SearchView class and override the get_results(self) method in order to apply the filtering after the search has been run with the user's search terms. The result is code along these lines:
class MySearchView(SearchView):
def get_results(self):
search = self.form.search()
# The ID I need for the database search is at the end of the URL,
# but this may have some search parameters on and need cleaning up.
view_id = self.request.path.split("/")[-1]
view_query = MyView.objects.filter(id=view_id.split("&")[0])
# At this point the django_ids of the required objects can be found.
if len(view_query) > 0:
view_item = view_query.__getitem__(0)
django_ids = []
for thing in view_item.things.all():
django_ids.append(thing.id)
search = search.filter_and(django_id__in=django_ids)
return search
Using search.filter_and rather than search.filter at the end was another thing which turned out to be essential, but which didn't do what I needed when the filtering was being performed before getting to the SearchView.

Resources