• Home
  • Blog
  • Resume
  • Contact
  • Projects
  • Gallery
  • Amit’s Resume
  • About Nagpur
KEEP IN TOUCH

Student’s t-test for equal means

Oct29
2008
Leave a Comment Written by admin

If you do not wish to enter complex formula in Excel and you already have calculated average, count, and variance for your samples(Tip:use a PivotTable), then you can use these user-defined functions to calculate the t-test stat value and degrees of freedom required to do hypothesis testing. Both the functions provide an optional argument for the assumption of equal variances; by default it is set to false.

Here’s the code for t-test:

'---------------------------------------------------------------------------------------
' Procedure : TTESTM
' DateTime  : 10/29/2008 08:35
' Author    :
' Purpose   : To get the t-stat value when comparing two means with an optional input
'               for equal or unequal variances
'               by default the function assumes that the user is comparing means with unequal variances
' davg1 is the mean of first sample
' dcnt1 is the sample size of sample 1 
' dvar1 is the variance of first samaple 
' davg2 is the mean of second sample
' dcnt2 is the sample size of sample 2 
' dvar2 is the variance of second samaple 
' blnEqVar set TRUE to assume equal variance for the test
'---------------------------------------------------------------------------------------

Public Function TTESTM(davg1 As Double, dcnt1 As Double, dvar1 As Double, davg2 As Double, dcnt2 As Double, dvar2 As Double, Optional blnEqVar As Boolean = False) As Double
 
On Error GoTo TTESTM_Error
Dim dResult As Double, dNumer As Double, dDenon As Double, dPooledVar As Double
 
dNumer = davg1 - davg2
 
'if equal variances are not assumed
'http://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm
If Not blnEqVar Then
	dDenon = Sqr((dvar1 ^ 2 / dcnt1) + (dvar2 ^ 2 / dcnt2))
Else
'if equal variances are assumed, then calculated the pooled variance
	dPooledVar = Sqr((((dcnt1 - 1) * dvar1 ^ 2) + ((dcnt2 - 1) * dvar2 ^ 2)) / (dcnt1 + dcnt2 - 2))
	dDenon = dPooledVar * Sqr((1 / dcnt1) + (1 / dcnt2))
End If
 
dResult = dNumer / dDenon
 
TTESTM = dResult
Exit Function
 
TTESTM_Error:
	TTESTM = Null
 
End Function

Code for degrees of freedom

'---------------------------------------------------------------------------------------
' Procedure : DOFTTESTM
' DateTime  : 10/29/2008 08:50
' Author    :
' Purpose   : To get the degrees of freedom for the t-test when comparing two means with an optional input
'               for equal or unequal variances
'               by default the function assumes that the user is comparing means with unequal variances

' dcnt1 is the sample size of sample 1 
' dvar1 is the variance of first samaple 
' dcnt2 is the sample size of sample 2 
' dvar2 is the variance of second samaple 
' blnEqVar set TRUE to assume equal variance for the test
'---------------------------------------------------------------------------------------
'
Public Function DOFTTESTM(dcnt1 As Double, dvar1 As Double, dcnt2 As Double, dvar2 As Double, Optional blnEqVar As Boolean = False) As Double
 
Dim dResult As Double, dNumer As Double, dDenon As Double
 
On Error GoTo DOFTTESTM_Error
'if equal variances are not assumed, then use a complicated formula to compute degrees of freedom
'http://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm
If Not blnEqVar Then
	dNumer = ((dvar1 ^ 2 / dcnt1) + (dvar2 ^ 2 / dcnt2)) ^ 2
	dDenon = ((dvar1 ^ 2 / dcnt1) ^ 2 / (dcnt1 - 1)) + ((dvar2 ^ 2 / dcnt2) ^ 2 / (dcnt2 - 1))
	dResult = dNumer / dDenon
Else
	dResult = dcnt1 + dcnt2 - 2
End If
 
DOFTTESTM = dResult
 
Exit Function
 
DOFTTESTM_Error:
	DOFTTESTM = Null
 
End Function
Posted in String Operations, Uncategorized, Useful Procedures - Tagged excel, UDF, VBA

Excel Training Handout

Oct23
2007
1 Comment Written by admin

Recently, I conducted a training session for Ohio Association for Institutional Research and Planning (OAIRP). Here are the files that I used for the training:

  • handout.pdf
  • Excercise.xls
  • Formulae.xls
Posted in Uncategorized

Convert Text to Uppercase

Sep17
2007
2 Comments Written by admin

If you want to convert the text to uppercase, use the following code; however, I recommend downloading ASAP Utilities, it has many functionalities, including text conversion. It doesn’t offer source code though.

Here’s my code for uppercase conversion:
(If you want to convert your text to lowercase, replace Ucase with Lcase function in the code)

‘Will convert selected range to Upper case, using array
Sub Conv2UCase()
On Error GoTo Conv2UCase_Error

Dim vDataArr As Variant
Dim lUpperBndRow As Long, lUpperBndCol As Long
Dim lRow As Long, lCol As Long

‘store selected values in an array
vDataArr = Selection
‘get the upper bound of rows
lUpperBndRow = UBound(vDataArr, 1)
‘get the upper bound of cols
lUpperBndCol = UBound(vDataArr, 2)

‘Start a loop to go through all the elements of the array
For lRow = 1 To lUpperBndRow
    For lCol = 1 To lUpperBndCol
        ‘Check if the value is text, if not don’t convert
        If WorksheetFunction.IsText(vDataArr(lRow, lCol)) Then
            ‘Convert values to upper case
            vDataArr(lRow, lCol) = UCase(vDataArr(lRow, lCol))
        End If
    Next lCol
Next lRow
‘Return the converted values to the range
Selection = vDataArr
Exit Sub

Conv2UCase_Error:
    MsgBox “Error ” & Err.Number & ” (” & Err.Description & “) in Sub:Conv2UCase”
End Sub

Posted in String Operations, Uncategorized, Useful Procedures - Tagged excel, UDF, VBA

Excel Books

Sep06
2007
Leave a Comment Written by admin

Books on my shelf:
Professional Excel Development by Stephen Bullen, Rob Bovey

This is by far the most authoritative book on Excel development from Add-ins to APIs. A word of caution though, it is not for the beginners.

Excel Advanced Report Development by Timothy Zapawa

Ever wondered on using Excel as a report development tool? This might be an answer to it; however, my problem with this book is that it focuses too much on pivottables, and because of that it doesn?t do justification to the name of the book. At any rate, this is very good book to exploit pivottable to its limits.

Excel 2007 Power Programming with VBA by John Walkenbach

Of course, it cannot happen that you talk about Excel books and don?t mention Mr. Spreadsheet himself. I am his fan on personal and professional level. On personal level, I love his blog, and on professional level, I like his lucid language in his books. I recommend reading his books and blog both.
Excel 2003 Formulas by John Walkenbach

You thought you knew formulas? Just read this book and you?ll realize, which I do almost every day, that there just so much about Excel that we don?t know. John uses simple language, and introduces the readers from basic to advanced formulas. How advance you might ask, well, here is an example, which uses a formula similar to this:

Excel 2007 Formulas by John Walkenbach
Books I have Read:
Data Analysis and Decision Making with Microsoft Excel by S. Christian Albright

I borrowed this book from the library. It is a very good for beginners.

Excel 2003 Power Programming with VBA by John Walkenbach
Integrating Excel and Access by Michael Schmalz

I borrowed this book from the library too. Excellent reference on developing applications using Access, Excel, and VBA.
Mr Excel ON EXCEL by Bill Jelen

This is my first book I read on Excel, which is written by Bill Jelen aka Mr. Excel. Fantastic book. If you have begun knowing Excel just now, obtain a copy of this book right away. This is the right start for beginners. It uses very simple and clear language, and Bill provides great examples to make the learning useful.

Guerilla Data Analysis Using Microsoft Excel by Bill Jelen

I had an e-version of this book, but for some reason it’s not working anymore. I had chewed on this book a lot. It?s a great book for starters, especially, in data crunching.

Posted in Books - Tagged Access, Bill Jelen, John Walkenbach, VBA

A function to reverse a string

Aug16
2007
1 Comment Written by admin

Very simple, uses the VBA function StrReverse to reverse the input string.

‘A function to reverse a string provided as input
‘For example, the string “abcd” will become “dcba”
‘Uses the VBA function StrReverse
Public Function ReverseString(sInputString As String) As String
On Error GoTo ReverseString_Error
    
ReverseString = StrReverse(sInputString)
    Exit Function

ReverseString_Error:
    ReverseString = “#ERROR#”
End Function

Posted in String Operations, Useful Procedures - Tagged excel, UDF, VBA
« Older Entries Newer Entries »

Tags

Access Alt F8 Books boxplot cells charts count cursor dashboard data mining dbase design error excel excel functions export filter flip LaTex MS query Number Err ODBC pipes Press Alt F11 Public Sub python R random numbers Range Cells report scripting software sparklines SQL SQL server stack columns statistics stemming string tag cloud text mining UDF VBA visualization wildcard

Network

View Ashutosh Nandeshwar's profile on LinkedIn

Recent Comments

  • W. McNabb on The search key was not found in any record in Access
  • Manuel on The search key was not found in any record in Access
  • Wendy Naples on The search key was not found in any record in Access
  • larry on Access Export to Excel (2007)
  • Betty Chou on Projects

EvoLve theme by Blogatize  •  Powered by WordPress nandeshwar.info