SPSS- how to make the histogram template refer to the y axis as percentage - templates

I have an odd issue regarding the SPSS (version 20) use of Chart Template, and any help will be appriciated.
I used the GUI to manualy define a chart template for Histograms. Those are simple definitions:
1) set the x axis between 0 to 100.
2) set the y axis as percent and not as actual number of examples within each bin.
3) set the bin sizes to 5.
4) set the maximal value of the y axis to 20.
I saved the template using the File->Save ChartTemplate option after changing the definitions of one histogram.
Oddly, when I implement the template on a new histogram, only definitions 1,3,4 are generated while 2 is omitted. I searched for a solution and did not find any. This is extremly frustrating since I need to waste time and effort to manualy reset the axis to the right definition over any new histogram I make (which is a lot :/ ).
There might be a way to hack the template code using notepad but I did not see any mention of the Y axis there.
Any help and comment would be much appriciated.

I can't say offhand how to set up a template to do any of those aspects, but here is an example using syntax to specify those four options.
SET SEED 10.
INPUT PROGRAM.
LOOP #i = 1 TO 500.
COMPUTE Var = RV.UNIFORM(0,90).
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
DATASET NAME Sim.
FORMATS Var (F3.0).
EXECUTE.
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=Var MISSING=LISTWISE REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: Var=col(source(s), name("Var"))
GUIDE: axis(dim(1), label("Var"), delta(5))
GUIDE: axis(dim(2), label("Percent in Bin"))
SCALE: linear(dim(1), min(0), max(100))
SCALE: linear(dim(2), max(20))
ELEMENT: interval(position(summary.percent.count(bin.rect(Var, binWidth(5)), base.all(acrossPanels()))))
END GPL.
And this is what the graph looks like for me (with my default chart template) in V25.

Related

How to get y axis range in Stata

Suppose I am using some twoway graph command in Stata. Without any action on my part Stata will choose some reasonable values for the ranges of both y and x axes, based both upon the minimum and maximum y and x values in my data, but also upon some algorithm that decides when it would be prettier for the range to extend instead to a number like '0' instead of '0.0139'. Wonderful! Great.
Now suppose that after (or while) I draw my graph, I want to slap some very important text onto it, and I want to be choosy about precisely where the text appears. Having the minimum and maximum values of the displayed axes would be useful: how can I get these min and max numbers? (Either before or while calling the graph command.)
NB: I am not asking how to set the y or x axis ranges.
Since this issue has been a bit of a headache for me for quite some time and I believe there is no good solution out there yet I wanted to write up two ways in which I was able to solve a similar problem to the one described in the post. Specifically, I was able to solve the issue of gray shading for part of the graph using these.
Define a global macro in the code generating the axis labels This is the less elegant way to do it but it works well. Locate the tickset_g.class file in your ado path. The graph twoway command uses this to draw the axes of any graph. There, I defined a global macro in the draw program that takes the value of the omin and omax locals after they have been set to the minimum between the axis range and data range (the command that does this is local omin = min(.scale.min,omin) and analogously for the max), since the latter sometimes exceeds the former. You could also define the global further up in that code block to only get the axis extent. You can then access the axis range using the globals after the graph command (and use something like addplot to add to the previously drawn graph). Two caveats for this approach: using global macros is, as far as I understand, bad practice and can be dangerous. I used names I was sure wouldn't be included in any program with the prefix userwritten. Also, you may not have administrator privileges that allow you to alter this file based on your organization's decisions. However, it is the simpler way. If you prefer a more elegant approach along the lines of what Nick Cox suggested, then you can:
Use the undocumented gdi natscale command to define your own axis labels The gdi commands are the internal commands that are used to generate what you see as graph output (cf. https://www.stata.com/meeting/dcconf09/dc09_radyakin.pdf). The tickset_g.class uses the gdi natscale command to generate the nice numbers of the axes. Basic documentation is available with help _natscale, basically you enter the minimum and maximum, e.g. from a summarize return, and a suggested number of steps and the command returns a min, max, and delta to be used in the x|ylabel option (several possible ways, all rather straightforward once you have those numbers so I won't spell them out for brevity). You'd have to adjust this approach in case you use some scale transformation.
Hope this helps!
I like Nick's suggestion, but if you're really determined, it seems that you can find these values by inspecting the output after you set trace on. Here's some inefficient code that seems to do exactly what you want. Three notes:
when I import the log file I get this message:
Note: Unmatched quote while processing row XXXX; this can be due to a formatting problem in the file or because a quoted data element spans multiple lines. You should carefully inspect your data after importing. Consider using option bindquote(strict) if quoted data spans multiple lines or option bindquote(nobind) if quotes are not used for binding data.
Sometimes the data fall outside of the min and max range values that are chosen for the graph's axis labels (but you can easily test for this).
The log linesize is actually important to my code below because the key values must fall on the same line as the strings that I use to identify the helpful rows.
* start a log (critical step for my solution)
cap log close _all
set linesize 255
log using "log", replace text
* make up some data:
clear
set obs 3
gen xvar = rnormal(0,10)
gen yvar = rnormal(0,.01)
* turn trace on, run the -twoway- call, and then turn trace off
set trace on
twoway scatter yvar xvar
set trace off
cap log close _all
* now read the log file in and find the desired info
import delimited "log.log", clear
egen my_string = concat(v*)
keep if regexm(my_string,"forvalues yf") | regexm(my_string,"forvalues xf")
drop if regexm(my_string,"delta")
split my_string, parse("=") gen(new)
gen axis = "vertical" if regexm(my_string,"yf")
replace axis = "horizontal" if regexm(my_string,"xf")
keep axis new*
duplicates drop
loc my_regex = "(.*[0-9]+)\((.*[0-9]+)\)(.*[0-9]+)"
gen min = regexs(1) if regexm(new3,"`my_regex'")
gen delta = regexs(2) if regexm(new3,"`my_regex'")
gen max_temp= regexs(3) if regexm(new3,"`my_regex'")
destring min max delta , replace
gen max = min + delta* int((max_temp-min)/delta)
*here is the info you want:
list axis min delta max

SegNet results of train set (test via test_segmentation.py)

I run SegNet on my own dataset (by Segnet tutorial). I see great results via test_segmentation.py.
my problem is that I want to see the real net results and not test_segmentation own colorisation (via classes).
for example, if I have trained net with 2 classes, so after the train I will see not only 2 colors (as we see with the classes), but we will see the real net color segmentation ([0.22,0.19,0.3....) lighter and darker as the net see it]
I hope that I explained myself well. thanks for helping.
You could use a python script to achieve what you want. Take a look at this script.
The command out = out['argmax'], extracts the raw output, so you can get a segmentation map with 'lighter and darker' values as you wanted.
When you say the 'real' net color segmentation I will assume that you mean the probability maps. Effectively the last layer will have one map for every class; and if you check the function predict in inference.py, they take the argmax; that is the channel (which represents the class) with the highest probability. If you want to get these maps, you just have to get the data without computing the argmax; something like:
predicted = net.blobs['prob'].data
I solve it. the solution is to range cmin and cmax from 0 to 1 in the scipy saving method. for example: scipy.misc.toimage(output, cmin=0.0, amax=1).save(/path/.../image.png)

Fixed Step in Chart in C++ Builder

There is a TChart component in C++ Builde with one serie.
I add the data using AddXY method but I want the Y-Axis to have fixed minimum and maximum values and fixed step. I've managed to understand how the first two things are done.
So my question is: How can I define a fixed step for the Y-Axis in TChart component.
Important: I've tried using Increment property but it gives me distance from the origin and that's not what I want.
Chart1->LeftAxis->Automatic = false;
Chart1->LeftAxis->Minimum = M - 2 * S;
Chart1->LeftAxis->Maximum = M + 2 * S;
Chart1->LeftAxis->Increment = S;
Update: I'll try to explain more clearly what I want to be. After I defined the minimum and maximum for the chart, I want to make a fixed step for this. The code I posted above doesn't work properly because I need a fixed step beginning from Minimum value and not from zero value as the code in question does.
I've found the answer to my question. I appreciate that you were helping me. Thank you.
I just needed to change the Items propery of the axis.
Instead of Increment one should use
Chart1->LeftAxis->Items->Clear();
Chart1->LeftAxis->Items->Add(double Value);

Stata seems to be ignoring my starting values in maximum likelihood estimation

I am trying to estimate a maximum likelihood model and it is running into convergence problems in Stata. The actual model is quite complicated, but it converges with no troubles in R when it is supplied with appropriate starting values. I however cannot seem to get Stata to accept the starting values I provide.
I have included a simple example below estimating the mean of a poisson distribution. This is not the actual model I am trying to estimate, but it demonstrates my problem. I set the trace variable, which allows you to see the parameters as Stata searches the likelihood surface.
Although I use init to set a starting value of 0.5, the first iteration still shows that Stata is trying a coefficient of 4.
Why is this? How can I force the estimation procedure to use my starting values?
Thanks!
generate y = rpoisson(4)
capture program drop mypoisson
program define mypoisson
args lnf mu
quietly replace `lnf' = $ML_y1*ln(`mu') - `mu' - lnfactorial($ML_y1)
end
ml model lf mypoisson (mean:y=)
ml init 0.5, copy
ml maximize, iterations(2) trace
Output:
Iteration 0:
Parameter vector:
mean:
_cons
r1 4
Added: Stata doesn't ignore the initial value. If you look at the output of the ml maximize command, the first line in the listing will be titled
initial: log likelihood =
Following the equal sign is the value of the likelihood for the parameter value set in the init statement.
I don't know how the search(off) or search(norescale) solutions affect the subsequent likelihood calculations, so these solution might still be worthwhile.
Original "solutions":
To force a start at your initial value, add the search(off) option to ml maximize:
ml maximize, iterate(2) trace search(off)
You can also force a use of the initial value with search(norescale). See Jeff Pitblado's post at http://www.stata.com/statalist/archive/2006-07/msg00499.html.

Excel Formula Calculations

I'm trying to add a spreadsheet editing function in my iOS app. I am using a gridview to display (not relevant to the question) and I am using LibXL to load the data into the view. That part all works very well but I have no way to calculate the formulas after a cell has been modified.
It appears that when I write a formula with LibXL it is not calculating the new value, just setting the formula value (a string). So when I try to read the number value from that cell it is still set to the last computed number (from excel).
Likewise, if I create cells with numbers and a formula cell to SUM them, it is never actually computed which reads a 0 number value until it's opened in Excel.
I was hoping LibXL was the silver bullet to my problem, but now I'm stuck with just the formula string value (i.e. "SUM(A1:b2)" ) and the last computed value.
I would love it if LibXL simply DID compute values and I just have it all wrong, but I can't see any documentation that says otherwise. If that's not the case are there any Obj-C, C, or C++ libraries that I can use to match the Excel Formula syntax and compute these values?
Just adding my previous comment as an answer:
Dave Delong's DDMathParser has the option to add custom functions, check it out here: http://github.com/davedelong/DDMathParser