Monday, December 29, 2008

Testing my blogposting from iPhone ... Cool

Geolocate this post

Posted with LifeCast

Sunday, October 19, 2008


For more widgets please visit www.yourminis.com Free Stock Quotes

Wednesday, July 02, 2008

SPSS Regression using Matrices

The SPSS syntax below does several linear regression calculations (model parameter values, sum of squares, F value, F test, R, Rsquare, t tests, etc) using matrices ... just change the data file and initialization part as required and off you go ......



/* ####### DATA FILE ################################################################################### */

FILE HANDLE data /NAME='c:\data\ratty2.sav'.


/* ####### INITIALIZATION AND DATA MATRIX ############################################################## */

MATRIX.

COMPUTE N=21. /* no of data rows */
COMPUTE IND_VARS=3. /* no of independet variables */

GET Y /FILE=data /VARIABLES =size. /* puts y-variable into column matrix called Y */
GET X1 /FILE=data /VARIABLES =t,z2,z3 /* put independent variables into a matrix called X1 */

/* ########## MATRIX CALCULATIONS #################################################################### */


COMPUTE j=make(N,1,1). /* Create column vector of 1's */
COMPUTE X={j,X1}. /* joins column of 1's in front of X1 columns */
COMPUTE XT=TRANSPOS(X). /* XT is the transpose of X */
COMPUTE XDX=XT*X. /* X'X */
COMPUTE IXDX=INV(XDX). /* (X'X)^ -1 */
COMPUTE BETA=IXDX*XT*y. /* BETA= ( (X'X) ^ -1)X'y */
COMPUTE BETAT=TRANSPOS(BETA).
COMPUTE YT = TRANSPOS(Y).
COMPUTE JT=TRANSPOS(J).
COMPUTE MODELSS=BETAT*XT*Y-(JT*Y)**2/N.
COMPUTE ERRSS=YT*Y-BETAT*XT*Y.
COMPUTE TOTALSS = YT*Y-(JT*Y)**2/N.
COMPUTE MMS=MODELSS/IND_VARS.
COMPUTE ERRMS=ERRSS/(N-IND_VARS-1).
COMPUTE F=MMS/ERRMS.
COMPUTE FP=1-FCDF(F,IND_VARS,N-IND_VARS-1).
COMPUTE VAR=IXDX*ERRSS.
COMPUTE VAR=VAR/(N-IND_VARS-1).
COMPUTE SE=SQRT(DIAG(VAR)).
COMPUTE TVAL=BETA/SE.
COMPUTE TVALF=TVAL&**2.
COMPUTE PVAL=1-FCDF(TVALF,1,N-IND_VARS-1).
COMPUTE TAB = {BETA,SE,TVAL,PVAL}.

COMPUTE RSQ= MODELSS/TOTALSS.
COMPUTE ADJRSQ=1-ERRMS/TOTALSS*(N-1).

/* ########### OUTPUT ######################################################################################## */

PRINT BETA.
PRINT X.
PRINT Y.
PRINT XT.
PRINT XDX.
PRINT IXDX.
PRINT MODELSS.
PRINT ERRSS.
PRINT TOTALSS.
PRINT MMS.
PRINT ERRMS.
PRINT F.
PRINT FP.
PRINT VAR.
PRINT SE.
PRINT TAB.
PRINT RSQ.
PRINT ADJRSQ.

END MATRIX.

Thursday, June 26, 2008

Java Design Patterns

Today i had the pleasure to present a session at the monthly Java User Group Malta meeting ... its always a pleasure to meet other Java Developers in our community and aspiring students. Click on the post tile to link to the presentation ...


Regards and good luck guys ... hope to meet again for other sessions.

Sunday, June 22, 2008

Java Web Application Properties

One of the most common application requirements is usually to create a central place where to keep application properties or application settings. These properties are normally settings or general properties that are applied to the application during runtime. A number of options exist, including creating string properties on your application server and accessing them as JNDI resources. However one of the still most practical approaches is to keep a properties config file with a simple propertyName=propertyValue type of structure. The example below is an example of an Application Config class that loads the application properties from a file named config.properties which is stored in the root of the source packages (root package) and hence automatically deployed with the application jar file during the build process.

import java.io.IOException;

import java.io.InputStream;

import java.util.Properties;

import java.util.logging.Level;

import java.util.logging.Logger;

public class ApplicationConfig {

    private static Properties properties;

    private static ApplicationConfig config;

    static {

        config = new ApplicationConfig();

    }

    private ApplicationConfig ()  {

        try {

            InputStream in =           this.getClass().getClassLoader().getResourceAsStream("config.properties");

            properties = new Properties();

            properties.load(in);

        } catch (IOException ex) {

            Logger.getLogger(ApplicationConfig.class.getName()).log(Level.SEVERE, null, ex);

        }

    }

    public static ApplicationConfig getApplicationConfig () {

            return config;

    }

    public String getProperty (String propName) {

        return properties.getProperty(propName, "Null");

    }      

}

An example config.properties file might contain something like:

applicationTitle=This is my application

An example test client (which might be a servlet, jsp, etc) can use this class as follows:

ApplicationConfig c = ApplicationConfig.getApplicationConfig();
String title = c.getProperty("applicationTitle");