RStudio - Stargazer issue - text table - text

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.

Related

Flask-AppBuilder equivalent of SQLite WHERE clause to filter column data

I'm new to Flask and have started designing a front end for an inventory management database using Flask-AppBuilder.
I have created several models and have have managed to display my sqlite data in tables using Flask-AppBuilder's views.
However, I don't seem to be able to find the equivalent of SQLite WHERE clause to filter or "restrict" column data. I've been reading a lot about sqlalchemy, filters, queries but this has left me more confused that anything else and the explanations seem to be extremely elaborate and complicated to do something which is extremely simple.
Assuming we reproduce the following SQLite query in Flask-AppBuilder:
SELECT Field_A
FROM Table_A
WHERE Field_A = 'some text'
with:
result = session.query(Table_A).filter_by(Field_A = 'some text').all()
Where does the above line of code go in my app?
Considering I have the following Class:
class Table_A(Model):
id = Column(Integer, primary_key=True)
Field_A = Column(String)
def __repr__(self):
return self
and View:
class Table_AView(ModelView):
datamodel = SQLAInterface(Table_AView)
label_columns = {'Field_A':'A'}
list_columns = ['Field_A']
After much digging flask-appbuilder uses it's own filterclass in order to enable you to filter your views.
All the classes are referenced here on GitHub:
Flask Filter Clases List
Also not the difference between FilterEqual and FilterEqualFunction here:
What is the difference between : FilterEqual and FilterEqualFunction?
For other customisation and first port of call of Flask-appbuilder go straight to the API Reference where you'll find a couple of examples of the filterclass in action.
In essence it is extremely simple. In your views.py code within the ModelView class you want to filter simply add base_filters = [['field_A', FilterEqual, 'abc']] like so:
`class Table_AView(ModelView):
datamodel = SQLAInterface(Table_AView)
label_columns = {'Field_A':'A'}
list_columns = ['Field_A']
base_filters = [['field_A', FilterEqual, 'abc']]`
This will only show the lines where the field_A variable is equal to abc.
Hope this helps someone as it took me nearly (sigh) two weeks to figure it out...
SQLALchemy is an ORM (Object-Relational Mapping), it mean that you dont have to deal with raw SQL, you will call a function that you "build" (by adding filters in your case). It will transparently generate an SQL query, execute it, and return the result as python objects.
I would suggest you to read closely at sqlalchemy documentation about filters again, especially filter_by :
http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.filter_by
It is the easiest way to apply a WHERE with sqlalchemy.
If you have declared correctly the model for Table_A, you should be able to use it so:
result = session.query(Table_A).filter_by(Field_A = 'some text').all()
Here session.query(Table_A).filter_by(Field_A = 'some text') will generate the SQL, and .all() will execute it.

Is there a way to auto-fill arguments names?

When I instantiate classes (or call methods) with a large number of parameters I'm always using named arguments. But it's tiring to type each argument name every time:
data class User(val id: String,
val name: String,
val age: Int)
val user = User(id = "1", name = "John", age = 99)
Can IDEA pre-fill parameters like this?
val user = User(
id = ,
name = ,
age =
)
There's a great plugin for that: https://plugins.jetbrains.com/plugin/10942-kotlin-fill-class
It autofills the constructor with some default parameters so you can override the ones you want ;)
This is the way:
Right click on the constructor method
Show Context Actions
Add names to call arguments
Profit
Though this is not actually generating the whole call template with all the parameter names, it might be helpful anyway.
Kotlin IDEA plugin 1.1.1 suggests the parameter names in auto completion as you start typing them. For the User constructor from the example, start typing:
val u = User(i
^
There should be a suggestion id =:
It is inserted if you press Enter or Tab. Then you can continue with the other arguments:
val u = User(id = "123", n
^
Here, name = should appear in suggestions, and so on.
Also, the parameters info popup should help you with it:
See the following requests:
IDEABKL-6690 Automatic code completion when choosing a signature
IDEABKL-5496 Auto-filling the actual Java call arguments
There is an experimental feature you can enable by adding java.completion.argument.live.template=true into Help | Edit Custom Properties.
If you already added all the params values in the constructor, Android studio will help you to do that.
Just click on the Object, in your case on User, then click on option + enter (on mac) and you will have add names to call arguments.
you can use Live template:
setting > Editor > Live Templates
choice code group and add by Green Plus 1.live Template
now you need fill items
Abbreviation is name for call template code.
in template type your code like it:
val user = User(
id = $arg1$,
name = $arg2$,
age = $arg3$
)
$arg1$ means where you can type new and jump by Tab
in code when you type Abbreviation name of your code, can selected and Code Generate there
GoodLuck

Choice data with no-choice option in mlogit

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

In Spotfire, how to trellis a SummaryTable using IronPython script

I am trying to "trellis" a summary table using a script. The TrellisVisualization is not available for the SummaryTable class. Using the GUI, I can trellis a summary table by assigning a specific column to the Categorization property under Columns Properties. However, while using the IronPython script, I don't see any property named Categorization for the SummaryTable object. So, I tried assigning the column to the CategoryAxis as follows:
mySummaryTable.CategoryAxis = "<[myColumn]>"
But this throws an error:
AttributeError: 'SummaryTable' object has no attribute 'CategoryAxis'
I also tried using Axis or CategoricalAxisBase etc. as properties, but these options did not work out. If anyone has more ideas on this, please let me know. Thanks.
RD
The key issue here is that the CategoryAxis property underneath the Summary Table class is a GET of this visual's object of the GroupByAxis class. You can see this by using the print command and getting information about the object:
print mySummaryTable.CategoryAxis
results in my Spotfire example:
<Spotfire.Dxp.Application.Visuals.GroupByAxis object at 0x000000000000002C [Spotfire.Dxp.Application.Visuals.GroupByAxis]>
You were actually quite close though. In order to set the CategoryAxis you need to set the Expression property of the CategoryAxis like so:
from Spotfire.Dxp.Application.Visuals import SummaryTable
mySummaryTable = myVisual.As[SummaryTable]()
mySummaryTable.CategoryAxis.Expression = "<[COLUMN]>"
If you need to pass an actual column name into that rather than hardcoded, I would concatenate the expression syntax and set the Expression equal to that variable:
myColumnExp = "<[" + myColumnName + "]>"
mySummaryTable.CategoryAxis.Expression = myColumnExp
Please let me know if you need any clarity regarding this. My Spotfire version for this answer is v6.5.2.26 and my API information from https://docs.tibco.com/pub/doc_remote/spotfire/6.5.0/api/Index.aspx

neo4j nodejs strength or properties's relationship modified : how to do it?

I meet a problem with count request of neo4j with nodejs.
Here my problem :
When I insert a data, it will present like this:
start a = node(0)
create unique a-[:HAS_ID]->(b{id:'xx'})
create unique b-[:HAS_INFO]->(c{info:'xx'})
return a,b,c;
because it's unique node, so that it will not insert a new node if there are a same node exist. But, I wanna count how many request to call this query.
Ex :
request: -domain/id01/info
--return a node[0], b node[1] and c node[2]
add another data:
request: -domain/id02/info
-- return : a node[0], b node[3], c node[4]
call it again :
request: -domain/id01/info
--return a node[0], b node[1] and c node[2] //but here is any attribute or properties count to 2.
I've read any solution about strength. It told me create an properties of relationship as example :
[:HAS_INFO{strength:num}]
and let it increase but I still don't get it.
Anyone please give me solution and tell me how to do it.
Thank you.
more info : Representing (and incrementing) relationship strength in Neo4j
You can use the CASE statement, see http://gist.neo4j.org/?6052414 for an example. Feel free to for the underlying gist and improve it!
MATCH path=(a)-[rel:HAS_INFO]->(b)
WHERE a.name?='A' AND b.name?='Info'
SET rel.weight = (
CASE
WHEN not(has(rel.weight))
THEN 0
ELSE rel.weight + 1
END)
RETURN path, rel.weight;

Resources