Category Archives: LaTex

Designing a questionnaire for school staff (UK Governors/ School leaders)

UPDATE: This School staff questionnaire can be downloaded as a word document here. Feel free to adapt and share as you wish.

This post may interest:

  • School governors/ leaders planning a staff questionnaire
  • Any seeking a (very) brief introduction to the options of designing any pencil and paper questionnaire.
  • Anyone looking for a LaTeX template for questionnaire design (this questionnaire is based on my slight adaptation of the paperandpencil.sty by Miriam Dieter & Anja Zwingenberger)

First thing: the actual questionnaire I designed

In my capacity as a school governor I designed a staff questionnaire last summer. I've made this available for anyone to use or adapt as they see fit. (Some of these questions are based on ones OFSTED ask teachers).

A basic consideration of options

There are many ways to do a staff questionnaire. Naturally online is fairly straightforward using third party software such as surveymonkey (free basic service, then £), or if you are more technically minded using various polling software and plugins in your own website (e.g. for wordpress). However in terms of online security paper and pencil questionnaires remain useful, and in a small(ish) school where everyone is in one place the benefits of setting up, administering and analysing an online questionnaire are probably not as great as for a larger organisation.

You may or may not be particularly worried about the presentation of your questionnaire. However, using your regular word-processing package (e.g. MSWord (£), LibreOffice writer (free and open source) etc.) will usually turn out to be more hassle than it's worth. Every time you try to move a box to a different place it ends up moving a whole load of other text (you've probably have experienced this behaviour when trying to put a photograph into a Word document).

If you wish to stick with a WYSIWYG (What You See Is What You Get) a publishing tool such as MSPublisher (£) or Scribus (free and open source) are likely to yield better results than word processing software. These will enable you to have more control over the page layout.

A bit more technical: using LaTeX

The questionnaire I designed is built in LaTeX and I've made the source code available in github. The key advantage of LaTeX (more about LaTeX here) is that you can have complete control over the layout with a combination of standard commands and some stylesheets. The .tex code can then be exported to .pdf leading to a document which can be printed off.

Link summary

.pdf version of the questionnaire we used at our school.  There are online services which can covert .pdf to Word (.doc/ .docx) though your mileage may vary.

Github access to the source code.

Further help

I'm happy to provide a small amount of free help (subject to my availability) to UK schools wishing to use the questionnaire (e.g. add school name/ logo, remove questions or make relatively minor amendments).

  • Twitter
  • del.icio.us
  • Digg
  • Facebook
  • Technorati
  • Reddit
  • Yahoo Buzz
  • StumbleUpon

Questionnaires in LaTeX using the paperandpencil package

I've been using the paperandpencil (.pdf document) package for creating questionnaires in LaTeX. 1 I thought the package worked very well, but just a couple of notes to myself which others may find useful. I've found it works well, but a couple of things were unclear. The .pdf version of the manual displays but the homepage linked from other sites no longer appears to work. However I have just found a download page on the QDDS website.

  1. The file paperandpencil.sty needs to place in the same directory as the .tex file. I had trouble finding it, but found the code over on Github. I pasted this into a text editor, saved it as paperandpencil.sty, and put it in the same directory as my .tex file.
  2. The document class needs to be {scrreprt}. This is in the first page documentation, but I managed to miss it.
  3. To set page numbers \pagestyle{plain} is required and the \pagenumbering and \setcounter options need to be set.

A minimal code example here:

\documentclass[a4paper, 11pt]{scrreprt}
\usepackage{paperandpencil}
\usepackage[top=2.5cm,bottom=2.5cm,left=2cm,right=2cm]{geometry}
\pagestyle{plain}
\begin{document}
  \pagenumbering{arabic}
  \setcounter{page}{1}
  \section*{Title goes here}
\end{document}
  • Twitter
  • del.icio.us
  • Digg
  • Facebook
  • Technorati
  • Reddit
  • Yahoo Buzz
  • StumbleUpon

Notes:

  1. Produced by the Questionnaire Development Documentation System, based at the University of Duisburg-Essen

Statistics for Humanities now in PDF format plus some reflections

The Statistics for Hcoverumanities book is now available in a much nicer PDF format. The mediawiki built website is still up there though it doesn't look great. The PDF is not perfect by any means but it’s time to move onto other projects now.

The book is published under a non-commercial Sharealike Creative Commons licence. I am thinking of trying an e-book version (I have software which technically supports this)  but I fear that with all the images and mathematics this could end up being a big mess.

The first versions of the book (previously available for public consultation and rejected by the British Academy on the advice of their reviewers) were written in LaTeX. I actually learnt LaTeX for the specific purpose of producing the book. I liked the idea of programmatic control but it all got a bit difficult to control where graphs and images landed. GNU plot which integrates with LaTeX was great for making the graphs and I'll continue to use it in the future if and when the need arises.

The first website version has been written using mediawiki software (the same software behind wikipedia). Wiki markup is easy to learn and plugins mean that LaTeX can be integrated for the mathematical parts. One of the issues with websites is that appearance in browsers can vary, but it is still not as nice looking as wikipedia.  The great advantage of wikis of course is that they are social tools in which people can collaborate to produce a finished product. I floated the idea with a couple of others of making this an open wiki, but was advised I could face problems of vandalism and spam. Although I like running websites it’s not a big part of my 'day job' and I don't want a troublesome hobby.

As I mentioned before the PDF version is available under a creative commons licence which allows people to modify it. This is all very well, but modifying a pdf document is not easy (that is sometimes the actual point), so I do need to think about whether I want to make the source files available. The book was produced using a combination of Serif Page Plus X7 (the full version) and MathType V6.9.

PagePlusX7 (I paid just under £64 including VAT) is not unlike MS Publisher though I much prefer it. I experimented with other desktop publishing software such as Scribus (free/ open source)*, but felt the learning curve was too steep at the present time. (High level DTPs run into hundreds of pounds so I'm not even going there).

Mathtype 6.9 (£43.20) was a worthwhile investment. I used it to type equations in LaTeX then copy and paste into PagePlus, but it can also be used to 'build' equations like the MS Equation Editor and even has a 'handwriting' feature. It can also be used in hundreds of other software applications. This was not totally plain sailing and for some reason equations using square root signs look a bit strange when posted into PagePlus. (If future editions of PagePlus have LaTeX Math integration that would be delightful).

Despite all the software used to produce the book, no software is necessary to use the book!

*Scribus does have LaTeX integration.

 

  • Twitter
  • del.icio.us
  • Digg
  • Facebook
  • Technorati
  • Reddit
  • Yahoo Buzz
  • StumbleUpon

Making your own e-book from websites using Grabmybooks

Added: 30th October 2013: The failure of the LaTeX rendering mentioned below is because I have been using the mark-up instead of using the tags <math> Latex code </math> .

Yesterday I came across Grabmybooks, a free Firefox plugin that enables the webuser to create ebooks from webpages.

The resulting output is a .epub file which should be useable on most e-readers (This can be converted to .mobi to use on a kindle).

As an experiment I attempted to covert the statistics for humanities website into an ebook. I was very impressed with the plugins rendering of text and tables. The images have not come out that well, but its main drawback from my point of view is that is doesn’t seem to cope with the more complex math code very well, which limits its use ‘out of the box’ for my purposes. However for purely text conversion it is excellent.

It is possible to edit the hard code whilst putting the e-book together. I haven’t tried this out yet.

Conversion to text and tables works well
Conversion to text and tables works well

 

 

Varying success with images, but these have undergone numerous conversions and reformatting over the past few months.
Varying success with images, but these have undergone numerous conversions and reformatting over the past few months.
The conversion from the LaTex plugin in Mediawiki has not worked out.
The conversion from the LaTex plugin in Mediawiki has not worked out.

 

  • Twitter
  • del.icio.us
  • Digg
  • Facebook
  • Technorati
  • Reddit
  • Yahoo Buzz
  • StumbleUpon

The Joy of LaTeX

Over the past year I discovered LaTeX.

As in latex gloves?

No. It's pronounced "Lah-tech" or "Lay-tech". For the uninitiated LaTeX is a programming language used to produce documents. It can be used for books, articles, posters, presentation and many more things.

So a bit like Word then?

Nothing like word or any other word processing programming. Word processing programmes are great when you have nothing but text. However, I'm sure that everyone has experienced the annoyance of trying to put an image into a word document then finding it disappears onto another page or behind your text. Word and similar programmes are "What you see to what you get" (WYWISYG). LaTeX is "What you mean is what you get".

Anscombe quartet: Output in LaTeX
Anscombe's quartet: Output in LaTeX

What do you mean?

Clip from the LaTeX file for my book.
Clip from the LaTeX file for my book.

If in Word I want to put an image 2.54cm from the right hand edge of the paper and 5.53cm from the top I may succeed to start with. However, once I add another image or some text there is no knowing whether it will stay there or not. In LaTeX it will stay exactly where I told it to.

Who should use LaTeX?

The great thing about LaTeX is that you can add packages to the basic installation. Packages can deal with mathematics, make graphs, posters, define colours, make books. If you use equations, graphs etc. you may find it worthwhile. also great for phonetics, ancient languages and languages using less commonly used alphabets.

Sounds a bit complicated...

Yes it is. I had a few false starts. There is quite a good introduction on wikibooks. At some point I plan to write a very basic introduction myself. The LaTeX project page is also a good place to start.

So everyone loves it then?

No, but I think its beautiful.

Show me an example.

See my online statistics book (preview).

How much does it cost?

Nothing

  • Twitter
  • del.icio.us
  • Digg
  • Facebook
  • Technorati
  • Reddit
  • Yahoo Buzz
  • StumbleUpon

Why you should graph data

Amended 10 March 2016 (corrections/ update made)

Anscombe's Quartet: Click to enlarge
Click to enlarge

I came across Anscombe’s Quartet on Wikipedia recently. I must confess to not having seen it before and don’t recall seeing it in any introductory statistics books.

The Anscombe’s Quartet is a conceptually and graphically clear way of showing the importance of graphs in statistical analysis. Each of the 11 pairs of observations have the same, x mean, y mean, x variance, y variance, correlation co-efficient and regression equation, though each have very different distributions. They clearly demonstrate the impact of outliers and how non-linear relationships can be identified.

Citation:

F. J. Anscombe (1973) Graphs in Statistical Analysis The American Statistician , Vol. 27, No. 1 (Feb., 1973), pp. 17-21

Article Stable URL: http://www.jstor.org/stable/2682899 (Not open access)

 

LaTeX code below.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.7}
\usepackage{amssymb, amsmath}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\caption{Anscombe's quartet is a good demonstration why a scatterplot is so valuable, prior to calculating regression equations and correlation co-efficients. In all four cases the $x's$ have a mean of 9, and variance of 11. The mean of all the $y's$ is 7.5, and a variance 4.125. The correlation co-efficient of each is 0.816 and the linear regression line is $y=3+0.5x $}
\begin{subfigure}{.45 \textwidth}
\centering
\caption{Normal linear relationship}
\begin{tikzpicture}
\begin{axis} [width=5cm, height=5cm, xlabel=X1, ylabel=Y1]
\addplot[scatter, only marks, mark=x, mark size=4pt]
coordinates
{
(10, 8.04)
(8.0, 6.95)
(13, 7.58)
(9, 8.81)
(11, 8.33)
(14, 9.96)
(6, 7.24)
(4, 4.26)
(12, 10.84)
(7, 4.82)
(5, 5.68)
};
\addplot[scatter, mark=.]
coordinates
{
(0, 4.1)
(20, 12.5)
};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}{.45 \textwidth}
\centering
\caption{Relationship clear, but not linear}
\begin{tikzpicture}
\begin{axis}[width=5cm, height=5cm, xlabel=X2, ylabel=Y2]
\addplot[scatter, only marks, mark=x, mark size=4pt]
coordinates
{
(10, 9.14)
(8.0, 8.14)
(13, 8.74)
(9, 8.77)
(11, 9.26)
(14, 8.10)
(6, 6.13)
(4, 3.1)
(12, 9.13)
(7, 7.26)
(5, 4.74)
};
\addplot[scatter, mark=.]
coordinates
{
(0, 4.1)
(20, 12.5)
};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\
\begin{subfigure}{.45 \textwidth}
\centering
\caption{Clear linear relationship, but one outlier offsets the regression line}
\begin{tikzpicture}
\begin{axis} [width=5cm, height=5cm, xlabel=X3, ylabel=Y3]
\addplot[scatter, only marks, mark=x, mark size=4pt]
coordinates
{
(10, 7.46)
(8.0, 6.77)
(13, 12.74)
(9, 7.11)
(11, 7.81)
(14, 8.84)
(6, 6.08)
(4, 5.39)
(12, 8.15)
(7, 6.42)
(5, 5.73)
};
\addplot[scatter, mark=.]
coordinates
{
(0, 4.1)
(20, 12.5)
};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}{.45 \textwidth}
\centering
\caption{Clear relationship, but one outlier puts the regression line at 45 degrees to the other 10 observations}
\begin{tikzpicture}
\begin{axis} [width=5cm, height=5cm, xlabel=X4, ylabel=Y4]
\addplot[scatter, only marks, mark=x, mark size=4pt]
coordinates
{
(8, 6.58)
(8.0, 5.76)
(8, 7.71)
(8, 8.84)
(8, 7.04)
(8, 5.26)
(19, 12.5)
(8, 5.56)
(8, 7.91)
(8, 6.89)
(8, 6.89)
};
\addplot[scatter, mark=.]
coordinates
{
(0, 4.1)
(20, 12.5)
};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\end{figure}
\end{document}

  • Twitter
  • del.icio.us
  • Digg
  • Facebook
  • Technorati
  • Reddit
  • Yahoo Buzz
  • StumbleUpon

Normal distribution curve in LaTeX

Amended: 22 February 2016: There were a couple of errors in the code which I have now fixed. The previous code omitted the need for the xcolor package and the some coding items symbols (notably '\' were missing).
I have been searching the internet on how to produce a normal distribution curve in LaTeX with the standard deviations marked. I wasn't able to find exactly what I wanted, but got some good clues here.  This code uses the pgfplots package. The code should work 'as is'.

Normal distribution diagram in LaTeX (Using Pgfplots package)


\documentclass{article}
\usepackage{pgfplots}
\usepackage{amssymb, amsmath}
\usepackage{tikz}
\usepackage{xcolor}
\pgfplotsset{compat=1.7}
\begin{document}
\pgfmathdeclarefunction{gauss}{2}{\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{tikzpicture}
\begin{axis}[no markers, domain=0:10, samples=100,
axis lines*=left, xlabel=Standard deviations, ylabel=Frequency,,
height=6cm, width=10cm,
xtick={-3, -2, -1, 0, 1, 2, 3}, ytick=\empty,
enlargelimits=false, clip=false, axis on top,
grid = major]
\addplot [fill=cyan!20, draw=none, domain=-3:3] {gauss(0,1)} \closedcycle;
\addplot [fill=orange!20, draw=none, domain=-3:-2] {gauss(0,1)} \closedcycle;
\addplot [fill=orange!20, draw=none, domain=2:3] {gauss(0,1)} \closedcycle;
\addplot [fill=blue!20, draw=none, domain=-2:-1] {gauss(0,1)} \closedcycle;
\addplot [fill=blue!20, draw=none, domain=1:2] {gauss(0,1)} \closedcycle;
\addplot[] coordinates {(-1,0.4) (1,0.4)};
\addplot[] coordinates {(-2,0.3) (2,0.3)};
\addplot[] coordinates {(-3,0.2) (3,0.2)};
\node[coordinate, pin={68.2\%}] at (axis cs: 0, 0.4){};
\node[coordinate, pin={95\%}] at (axis cs: 0, 0.3){};
\node[coordinate, pin={99.7\%}] at (axis cs: 0, 0.2){};
\node[coordinate, pin={34.1\%}] at (axis cs: -0.5, 0){};
\node[coordinate, pin={34.1\%}] at (axis cs: 0.5, 0){};
\node[coordinate, pin={13.6\%}] at (axis cs: 1.5, 0){};
\node[coordinate, pin={13.6\%}] at (axis cs: -1.5, 0){};
\node[coordinate, pin={2.1\%}] at (axis cs: 2.5, 0){};
\node[coordinate, pin={2.1\%}] at (axis cs: -2.5, 0){};
\end{axis}
\end{tikzpicture}
\end{document}

  • Twitter
  • del.icio.us
  • Digg
  • Facebook
  • Technorati
  • Reddit
  • Yahoo Buzz
  • StumbleUpon

Using pgfplot LaTeX package for basic dotplots.

Amended 11 March 2016

I wanted to produce a basic dotplot using the LaTeX pgfplot package. I looked for guidance in the extensive manual but didn't find what I wanted (that is not to say it's not there). I managed to find a workaround, which I have shared here. The results are not perfect, but will do for now.

This is the table containing my data:

Subject Marks out of ten Mean Average Median average
French 2, 4, 5, 7, 7 5 5
Religious Studies 0, 5, 10, 7, 3 5 5
History 5, 5, 4, 6, 5 5 5

I used the scatterplot as the basis for the dotplot and worked out this code.

I did three of these. Here are the results. Not too bad.


\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{figure}
\centering
\caption{Dotplot: French}
\begin{tikzpicture}
\begin{axis}[
xlabel={Marks out of ten},
ylabel={},%no label for the y axis
yticklabels={}, %no numbers displayed on the y
ymin=0,
ymax=10,
xline,
xmin=0, %sets the minimum of the x axis
xmax=10, %sets the max of the x axis.
%As the test was out of ten I have set max to 10.
]
\addplot[scatter,only marks,
scatter src=explicit symbolic]
coordinates
{
(2,0) %the first number is the marks out of ten (the x axis).
% Use 0 for the y axis until the second occurrence.
(4,0)
(5,0)
(7,0)
(7,1) %the second number here is 1 because we have already used 7,0.
%This is because 2 people got 7 out of 10.
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

Dotplot output from pgfplot package

 

  • Twitter
  • del.icio.us
  • Digg
  • Facebook
  • Technorati
  • Reddit
  • Yahoo Buzz
  • StumbleUpon

Converting tables from Excel 2010 to LaTeX using excel2latex add-in

Orginal Excel 2010 table
Orginal Excel 2010 table

Building all but the simplest tables in LaTeX is not a particularly intuitive process. I’ve just been trying out the Excel2Latex add-in for converting tables from Excel (2010) into LaTeX. I eventually got it to work, but it look a lot of on-line detective work to work it all out. It appears that it was easier to use in Excel 2003.

  1. First of all you need to download the add in file  The file has the extension .xla
  2. It will tell you to open the file in excel. When I tried to open the file in Excel nothing happened, but the file got saved under username/temp rather than in username/downloads. (as I was opening it up online).
  3. In early versions of excel this might have been enough and the Excel2Latex add-in would appear under the tools menu. This was not the case in Excel 2010.
  4. I then opened Excel and clocked on “File”, then “Options”.
  5. I then selected Add-ins from the left hand side.
  6. A list of available Add-ins came up, but Excel2Latex did not appear.
  7. At the bottom of the dialogue box you should find the word ‘Manage’. Select Add-ins from the drop down menu and click ‘Go’
  8. A list of available add-ins will appear. If Excel2Latex is there select it, but in my case it was not there. If this is the case click ‘Browse’ and find the file excel2Latex.xla. Select it and it should be added to your list of add-ins.
  9. Now close Excel down.
  10. When excel is re-opened a new heading will appear at the top of the Excel window labelled ‘add-ins’ . Click on this menu item and you should see two new buttons. “Convert table to LaTeX” and “Convert all stored tables to LaTeX”.
  11. Open up an excel file (if you have not already done so) and Click on “add-ins”, then “Convert table to LaTeX”. New buttons
  12. Excel will then generate the LaTeX code for your table.LaTeX Code generated  in Excel
  13. Export or copy+paste into your usual .tex/ LaTeX editor
    Code pasted into my LaTeX editor
    Code pasted into my LaTeX editor

  14. The final result in my .pdf file! Looks nice I think.

    PDF screenshot
    PDF screenshot

Notes

Excel2latex can cope with formats such as italic and bold,but not colour at present.

  • Twitter
  • del.icio.us
  • Digg
  • Facebook
  • Technorati
  • Reddit
  • Yahoo Buzz
  • StumbleUpon