Archive for the 'Python snakery' Category

Run R code in Python

Sunday, August 22nd, 2010

There is Rpy. The only reason why we prefer to run R by calling it as a separate process is for increased reliability. ?Download runrcode.py""" file runcode.py author Ernesto P. Adorio ernesto.adorio@gmail.com   version 0.0.1 August 22, 2010 """   import tempfile,os, commands   def runRcode(code, tempdir= "./"): # Write to temporary file. (f, name) [...]

  • Share/Bookmark

Dataframes in Python

Sunday, August 22nd, 2010

Here is our updated dataframe class in Python.It is a revision of our old dataframe code in /?p=7834. It now collects the row labels and column labels. ?Download dataframe.py  """ file dataframe.py   version 0.0.2 2010.08.22 author Dr. Ernesto P. Adorio ernesto.adorio@gmail.com """   class dataframe: def __init__(self, s, header=True, commentchar="#", numericdata=False): self.data = [] [...]

  • Share/Bookmark

New Statistics-Python articles in our Doc Ernie’s Adventures in the Web blog

Monday, August 16th, 2010

Statistics and Python: Creating a frequency counts array for data Python, Statistics: Stem and Leaf Part 4, a mirrored article Descriptive Statistics for Sample with Frequency Data” Python, Statistics: Computing the lower, mid and upper “hinges” of a sample Descriptive Statistics in Python

  • Share/Bookmark

Stem Leaf Part 4, with counts.

Monday, August 16th, 2010

Our old stem and leaf code has been updated to include frequency counts. Here is the latest incarnation, following or last past discussion in Part 3 What gives??? The lines following the paragraph above are not displayed! Readers, visit Doc Ernie’s Adventures for the full article. Seems an HTML block error. Seems WordPress does not [...]

  • Share/Bookmark

Crontab file problem:why is the last command not executed?

Tuesday, July 27th, 2010

I got weather pages displayed in my blogs which are updated at the adorio-research.org site. The data is obtained automatically by a cronjob and the command to get the Japan Meteorological Agency (JMA) analysis chart has the line entry in the cron list as 5 0,6,12,18 * * * getjmachart.py meaning every 5 minutes after [...]

  • Share/Bookmark

Python: A cure for “list assignment index out of range” error

Saturday, July 3rd, 2010

Here is a quickie function for safely storing values in an array. ?View Code PYTHONdef safestore(alist, index, value): n = len(alist) iindex = index print "iindex=", iindex if iindex < 0: iindex = -iindex alist.extend([None] * (iindex-n)) elif iindex >= n: alist.extend([None] * (iindex-n+1)) print alist   alist[index] = value Here are some examples: a [...]

  • Share/Bookmark

A common Python error: Illegal character at position XX, no encoding declared?

Sunday, June 27th, 2010

You get something like this when running a script with the code or data copied from the Internet: SyntaxError: Non-ASCII character ‘\xc2′ in file getbspstats.py on line 11, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details You can easily fix the recurring and common problem by inserting the following line on top of your Python [...]

  • Share/Bookmark

Python, Simple dataframe class for matrices inspired by R.

Sunday, June 20th, 2010

A matrix in our Python work is simply an array of arrays with same number of elements(columns). R has a reputation for ease of use with statisticians. Up to now, I am still wondering why Python programmers have not taken advantage of the rich bag of ideas in the R statistical language. Enough… let us [...]

  • Share/Bookmark

New and updated blog entries for econometrics in our alternate blog site.

Sunday, June 6th, 2010

The Granger causality test is treated in Granger test The Koyck geometrically distributed lag model is updated to include the Leviatan instrumental variable technique. Koyck lag model The Burg algorithm is the recommended way of computing the autoregressive model coefficients. Here is an implementation in Python: Burg algorithm In Python

  • Share/Bookmark

Python, econometrics: Almon distributed polynomial lag models time series procedures.

Monday, May 31st, 2010

The Almon polynomial lag model is based on the model formula where the $\beta_i$’s are approximated by a polynomial in $i$, the lag length.For a quadratic, these coefficients can be written as and substitution of this formula results in the following linear modelng this formula, we may obtain the following linear model (See p 689 [...]

  • Share/Bookmark

Digital explorations is Digg proof thanks to caching by WP Super Cache