commit 66aaf665cb262054fbe135e5a3de4b9642fe9358 Author: 依瑪貓 Date: Mon Sep 5 16:05:19 2016 +0800 Initial commit, with Pearson's correlation coefficient, paired samples T-test, independent samples T-Test and ANOVA. diff --git a/_0Main.vb b/_0Main.vb new file mode 100644 index 0000000..1ddca66 --- /dev/null +++ b/_0Main.vb @@ -0,0 +1,56 @@ +' _0Main: The main module for the statistics macros +' by imacat , 2016-08-10 + +Option Explicit + +' subMain: The main program +Sub subMain + BasicLibraries.loadLibrary "XrayTool" + Dim dStart As Date + dStart = Now + + 'MsgBox InStr (1, "abca", "ad") + 'Xray ThisComponent.getSheets.getByIndex (0).getCellByPosition (0, 0) + 'subTestCorrelation + + MsgBox "Done. " & Format (Now - dStart, "mm:ss") & " elapsed." +End Sub + +' fnQueryFormat: Returns the index of the number format, and creates the number format if required. +Function fnQueryFormat (oDoc As Object, sFormat As String) As Integer + Dim oFormats As Object, nIndex As Integer + Dim aLocale As New com.sun.star.lang.Locale + + oFormats = oDoc.getNumberFormats + nIndex = oFormats.queryKey (sFormat, aLocale, True) + If nIndex = -1 Then + oFormats.addNew (sFormat, aLocale) + nIndex = oFormats.queryKey (sFormat, aLocale, True) + End If + fnQueryFormat = nIndex +End Function + +' fnGetRangeName: Obtains the name of a spreadsheet cell range +Function fnGetRangeName (oRange As Object) As String + Dim nPos As Integer, sName As String + + sName = oRange.getPropertyValue ("AbsoluteName") + nPos = InStr (sName, "$") + Do While nPos <> 0 + sName = Left (sName, nPos - 1) & Right (sName, Len (sName) - nPos) + nPos = InStr (sName, "$") + Loop + fnGetRangeName = sName +End Function + +' fnGetLocalRangeName: Obtains the name of a local spreadsheet cell range +Function fnGetLocalRangeName (oRange As Object) As String + Dim nPos As Integer, sName As String + + sName = fnGetRangeName (oRange) + nPos = InStr (sName, ".") + If nPos <> 0 Then + sName = Right (sName, Len (sName) - nPos) + End If + fnGetLocalRangeName = sName +End Function diff --git a/_1CorRel.vb b/_1CorRel.vb new file mode 100644 index 0000000..2b05f0e --- /dev/null +++ b/_1CorRel.vb @@ -0,0 +1,231 @@ +' _1CorRel: The macros to for generating the report of the Pearson’s correlation coefficient +' by imacat , 2016-08-10 + +Option Explicit + +' subTestCorrelation: Tests the Pearson’s correlation coefficient report +Sub subTestCorrelation + Dim oSheets As Object, sSheetName As String + Dim oSheet As Object, oRange As Object + + sSheetName = "correl" + oSheets = ThisComponent.getSheets + If Not oSheets.hasByName (sSheetName) Then + MsgBox "Data sheet """ & sSheetName & """ not found" + Exit Sub + End If + If oSheets.hasByName (sSheetName & "_correl") Then + oSheets.removeByName (sSheetName & "_correl") + End If + oSheet = ThisComponent.getSheets.getByName (sSheetName) + oRange = oSheet.getCellRangeByName ("B3:C13") + subReportCorrelation (ThisComponent, oRange) +End Sub + +' subReportCorrelation: Reports the Pearson’s correlation coefficient +Sub subReportCorrelation (oDoc As Object, oDataRange As Object) + Dim oSheets As Object, sSheetName As String + Dim mNames () As String, nI As Integer, nSheetIndex As Integer + Dim oSheet As Object, oColumns As Object, nRow As Integer + Dim oCell As Object, oCells As Object, oCursor As Object + Dim nN As Integer, sFormula As String + Dim nFormatN As Integer, nFormatF As Integer, nFormatP As Integer + Dim aBorderSingle As New com.sun.star.table.BorderLine + Dim aBorderDouble As New com.sun.star.table.BorderLine + Dim sCellXLabel As String, sCellsXData As String + Dim sCellYLabel As String, sCellsYData As String + Dim sCellN As String, sCellR As String + Dim sNotes As String, nPos As Integer + + oSheets = oDoc.getSheets + sSheetName = oDataRange.getSpreadsheet.getName + mNames = oSheets.getElementNames + For nI = 0 To UBound (mNames) + If mNames (nI) = sSheetName Then + nSheetIndex = nI + End If + Next nI + oSheets.insertNewByName (sSheetName & "_correl", nSheetIndex + 1) + oSheet = oSheets.getByName (sSheetName & "_correl") + + nN = oDataRange.getRows.getCount - 1 + sCellXLabel = fnGetRangeName (oDataRange.getCellByPosition (0, 0)) + sCellsXData = fnGetRangeName (oDataRange.getCellRangeByPosition (0, 1, 0, nN)) + sCellYLabel = fnGetRangeName (oDataRange.getCellByPosition (1, 0)) + sCellsYData = fnGetRangeName (oDataRange.getCellRangeByPosition (1, 1, 1, nN)) + + ' Obtains the format parameters for the report. + nFormatN = fnQueryFormat (oDoc, "#,##0") + nFormatF = fnQueryFormat (oDoc, "#,###.000") + nFormatP = fnQueryFormat (oDoc, "[<0.01]#.000""**"";[<0.05]#.000""*"";#.000") + + aBorderSingle.OuterLineWidth = 2 + aBorderDouble.OuterLineWidth = 2 + aBorderDouble.InnerLineWidth = 2 + aBorderDouble.LineDistance = 2 + + ' Sets the column widths of the report. + oColumns = oSheet.getColumns + oColumns.getByIndex (0).setPropertyValue ("Width", 3060) + oColumns.getByIndex (1).setPropertyValue ("Width", 3060) + oColumns.getByIndex (2).setPropertyValue ("Width", 2080) + oColumns.getByIndex (3).setPropertyValue ("Width", 2080) + oColumns.getByIndex (4).setPropertyValue ("Width", 2080) + + nRow = -2 + + ' Correlation + nRow = nRow + 2 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Pearson’s Correlation") + oCell.setPropertyValue ("CellStyle", "Result2") + oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow) + oCells.merge (True) + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("X") + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (1, nRow) + oCell.setString ("Y") + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (2, nRow) + oCell.setString ("N") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (3, nRow) + oCell.setString ("r") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (4, nRow) + oCell.setString ("p") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + + ' The test result. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + sFormula = "=" & sCellXLabel + oCell.setFormula (sFormula) + oCell = oSheet.getCellByPosition (1, nRow) + sFormula = "=" & sCellYLabel + oCell.setFormula (sFormula) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=COUNT(" & sCellsXData & ")" + oCell.setFormula (sFormula) + sCellN = fnGetLocalRangeName (oCell) + oCell.setPropertyValue ("NumberFormat", nFormatN) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=CORREL(" & sCellsXData & ";" & sCellsYData & ")" + oCell.setFormula (sFormula) + sCellR = fnGetLocalRangeName (oCell) + oCell.setPropertyValue ("NumberFormat", nFormatF) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=TDIST(" & sCellR & "*SQRT((" & sCellN & "-2)/(1-" & sCellR & "*" & sCellR & "))" & ";" & sCellN & "-2;2)" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatP) + + ' The foot notes of the test. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _ + "H0: ρ=0 (the populations of the two groups are irrelavent)." & Chr (10) & _ + "H1: ρ≠0 (the populations of the two groups are relevant) if the probability (p) is small enough.") + oCell.setPropertyValue ("IsTextWrapped", True) + oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow) + oCells.merge (True) + sNotes = oCell.getString + oCursor = oCell.createTextCursor + nPos = InStr (sNotes, "p<") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (nPos + 1, sNotes, "p<") + Loop + nPos = InStr (sNotes, "(p)") + oCursor.gotoStart (False) + oCursor.goRight (nPos, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (sNotes, "ρ") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (nPos + 1, sNotes, "ρ") + Loop + nPos = InStr (sNotes, "H0") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + nPos = InStr (sNotes, "H1") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + + ' Draws the table borders. + oCells = oSheet.getCellByPosition (0, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (1, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (2, nRow - 2, 4, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow - 1) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellByPosition (1, nRow - 1) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellRangeByPosition (2, nRow - 1, 4, nRow - 1) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) +End Sub diff --git a/_2PTTest.vb b/_2PTTest.vb new file mode 100644 index 0000000..1bd7000 --- /dev/null +++ b/_2PTTest.vb @@ -0,0 +1,544 @@ +' _2PTTest: The macros to for generating the report of paired T-Test +' by imacat , 2016-08-11 +Option Explicit + +' subTestPairedTTest: Tests the paired T-test report +Sub subTestPairedTTest + Dim oSheets As Object, sSheetName As String + Dim oSheet As Object, oRange As Object + + sSheetName = "pttest" + oSheets = ThisComponent.getSheets + If Not oSheets.hasByName (sSheetName) Then + MsgBox "Data sheet """ & sSheetName & """ not found" + Exit Sub + End If + If oSheets.hasByName (sSheetName & "_ttest") Then + oSheets.removeByName (sSheetName & "_ttest") + End If + oSheet = ThisComponent.getSheets.getByName (sSheetName) + oRange = oSheet.getCellRangeByName ("B3:C15") + subReportPairedTTest (ThisComponent, oRange) +End Sub + +' subReportPairedTTest: Reports the paired T-test +Sub subReportPairedTTest (oDoc As Object, oDataRange As Object) + Dim oSheets As Object, sSheetName As String + Dim mNames () As String, nI As Integer, nSheetIndex As Integer + Dim oSheet As Object, oColumns As Object, nRow As Integer + Dim oCell As Object, oCells As Object, oCursor As Object + Dim nN As Integer, sFormula As String + Dim nFormatN As Integer, nFormatF As Integer, nFormatP As Integer + Dim aBorderSingle As New com.sun.star.table.BorderLine + Dim aBorderDouble As New com.sun.star.table.BorderLine + Dim sCellXLabel As String, sCellsXData As String + Dim sCellXN As String, sCellXMean As String, sCellXS As String + Dim sCellYLabel As String, sCellsYData As String + Dim sCellYN As String, sCellYMean As String, sCellYS As String + Dim sCellN As String, sCellXYS As String, sCellR As String + Dim sNotes As String, nPos As Integer + + oSheets = oDoc.getSheets + sSheetName = oDataRange.getSpreadsheet.getName + mNames = oSheets.getElementNames + For nI = 0 To UBound (mNames) + If mNames (nI) = sSheetName Then + nSheetIndex = nI + End If + Next nI + oSheets.insertNewByName (sSheetName & "_ttest", nSheetIndex + 1) + oSheet = oSheets.getByName (sSheetName & "_ttest") + + nN = oDataRange.getRows.getCount - 1 + sCellXLabel = fnGetRangeName (oDataRange.getCellByPosition (0, 0)) + sCellsXData = fnGetRangeName (oDataRange.getCellRangeByPosition (0, 1, 0, nN)) + sCellYLabel = fnGetRangeName (oDataRange.getCellByPosition (1, 0)) + sCellsYData = fnGetRangeName (oDataRange.getCellRangeByPosition (1, 1, 1, nN)) + + ' Obtains the format parameters for the report. + nFormatN = fnQueryFormat (oDoc, "#,##0") + nFormatF = fnQueryFormat (oDoc, "#,###.000") + nFormatP = fnQueryFormat (oDoc, "[<0.01]#.000""**"";[<0.05]#.000""*"";#.000") + + aBorderSingle.OuterLineWidth = 2 + aBorderDouble.OuterLineWidth = 2 + aBorderDouble.InnerLineWidth = 2 + aBorderDouble.LineDistance = 2 + + ' Sets the column widths of the report. + oColumns = oSheet.getColumns + oColumns.getByIndex (0).setPropertyValue ("Width", 3060) + oColumns.getByIndex (1).setPropertyValue ("Width", 3060) + oColumns.getByIndex (2).setPropertyValue ("Width", 2080) + oColumns.getByIndex (3).setPropertyValue ("Width", 2080) + oColumns.getByIndex (4).setPropertyValue ("Width", 2080) + + nRow = -2 + ' Group description + nRow = nRow + 2 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Sample Description") + oCell.setPropertyValue ("CellStyle", "Result2") + oCells = oSheet.getCellRangeByPosition (0, nRow, 5, nRow) + oCells.merge (True) + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Sample") + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + oCell.setString ("N") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (3, nRow) + oCell.setString ("X") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE) + oCell = oSheet.getCellByPosition (4, nRow) + oCell.setString ("s") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (5, nRow) + oCell.setString ("sX") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE) + + ' The first group + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + sFormula = "=" & sCellXLabel + oCell.setFormula (sFormula) + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=COUNT(" & sCellsXData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + sCellXN = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=AVERAGE(" & sCellsXData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellXMean = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=STDEV(" & sCellsXData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellXS = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (5, nRow) + sFormula = "=" & sCellXS & "/SQRT(" & sCellXN & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + + ' The second group + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + sFormula = "=" & sCellYLabel + oCell.setFormula (sFormula) + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=COUNT(" & sCellsYData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + sCellYN = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=AVERAGE(" & sCellsYData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellYMean = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=STDEV(" & sCellsYData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellYS = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (5, nRow) + sFormula = "=" & sCellYS & "/SQRT(" & sCellYN & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + + ' The difference between the two groups + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + sFormula = "=""(""&" & sCellXLabel & "&""-""&" & sCellYLabel & "&"")""" + oCell.setFormula (sFormula) + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=" & sCellXN + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + sCellN = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=" & sCellXMean & "-" & sCellYMean + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=SQRT(" & sCellXS & "*" & sCellXS & "-2*SUMPRODUCT(" & sCellsXData & ";" & sCellsYData & ")/(" & sCellN & "-1)+2*" & sCellXMean & "*" & sCellYMean & "*" & sCellN & "/(" & sCellN & "-1)+" & sCellYS & "*" & sCellYS & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellXYS = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (5, nRow) + sFormula = "=" & sCellXYS & "/SQRT(" & sCellN & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + + ' Draws the table borders. + oCells = oSheet.getCellByPosition (0, nRow - 3) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (1, nRow - 3, 5, nRow - 3) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (0, nRow - 2, 0, nRow - 1) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellRangeByPosition (1, nRow, 5, nRow) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + + ' Correlation + nRow = nRow + 2 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Pearson’s Correlation") + oCell.setPropertyValue ("CellStyle", "Result2") + oCells = oSheet.getCellRangeByPosition (0, nRow, 3, nRow) + oCells.merge (True) + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("X1") + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCell = oSheet.getCellByPosition (1, nRow) + oCell.setString ("X2") + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCell = oSheet.getCellByPosition (2, nRow) + oCell.setString ("r") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (3, nRow) + oCell.setString ("p") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + + ' The test result. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + sFormula = "=" & sCellXLabel + oCell.setFormula (sFormula) + oCell = oSheet.getCellByPosition (1, nRow) + sFormula = "=" & sCellYLabel + oCell.setFormula (sFormula) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=CORREL(" & sCellsXData & ";" & sCellsYData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellR = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=TDIST(ABS(" & sCellR & ")*SQRT((" & sCellN & "-2)/(1-" & sCellR & "*" & sCellR & "))" & ";" & sCellN & "-2;2)" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatP) + + ' The foot notes of the test. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _ + "H0: ρ=0 (the populations of the two samples are irrelavent)." & Chr (10) & _ + "H1: ρ≠0 (the populations of the two samples are relevant) if the probability (p) is small enough.") + oCell.setPropertyValue ("IsTextWrapped", True) + oCells = oSheet.getCellRangeByPosition (0, nRow, 3, nRow) + oCells.merge (True) + sNotes = oCell.getString + oCursor = oCell.createTextCursor + nPos = InStr (sNotes, "p<") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (nPos + 1, sNotes, "p<") + Loop + nPos = InStr (sNotes, "(p)") + oCursor.gotoStart (False) + oCursor.goRight (nPos, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (sNotes, "ρ") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (nPos + 1, sNotes, "p<") + Loop + nPos = InStr (sNotes, "H0") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + nPos = InStr (sNotes, "H1") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + + ' Draws the table borders. + oCells = oSheet.getCellByPosition (0, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (1, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (2, nRow - 2, 3, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow - 1) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellByPosition (1, nRow - 1) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellRangeByPosition (2, nRow - 1, 3, nRow - 1) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + + ' Paired-samples T-test + nRow = nRow + 2 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Paired-Samples T-test") + oCell.setPropertyValue ("CellStyle", "Result2") + oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow) + oCells.merge (True) + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("X1") + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCell = oSheet.getCellByPosition (1, nRow) + oCell.setString ("X2") + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCell = oSheet.getCellByPosition (2, nRow) + oCell.setString ("t") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (3, nRow) + oCell.setString ("df") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (4, nRow) + oCell.setString ("p") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + + ' The test result. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + sFormula = "=" & sCellXLabel + oCell.setFormula (sFormula) + oCell = oSheet.getCellByPosition (1, nRow) + sFormula = "=" & sCellYLabel + oCell.setFormula (sFormula) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=(" & sCellXMean & "-" & sCellYMean & ")/SQRT((" & sCellXS & "*" & sCellXS & "+" & sCellYS & "*" & sCellYS & "-2*" & sCellR & "*" & sCellXS & "*" & sCellYS & ")/" & sCellN & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=" & sCellN & "-1" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=TTEST(" & sCellsXData & ";" & sCellsYData & ";2;1)" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatP) + + ' The foot notes of the test. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _ + "H0: μ1=μ2 (the populations of the two samples have the same means)." & Chr (10) & _ + "H1: μ1≠μ2 (the populations of the two samples have different means) if the probability (p) is small enough.") + oCell.setPropertyValue ("IsTextWrapped", True) + oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow) + oCells.merge (True) + sNotes = oCell.getString + oCursor = oCell.createTextCursor + nPos = InStr (sNotes, "p<") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (nPos + 1, sNotes, "p<") + Loop + nPos = InStr (sNotes, "(p)") + oCursor.gotoStart (False) + oCursor.goRight (nPos, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (sNotes, "μ") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + nPos = InStr (nPos + 1, sNotes, "μ") + Loop + nPos = InStr (sNotes, "H0") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + nPos = InStr (sNotes, "H1") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + + ' Draws the table borders. + oCells = oSheet.getCellByPosition (0, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (1, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (2, nRow - 2, 4, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow - 1) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellByPosition (1, nRow - 1) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellRangeByPosition (2, nRow - 1, 4, nRow - 1) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) +End Sub diff --git a/_3ITTest.vb b/_3ITTest.vb new file mode 100644 index 0000000..d398365 --- /dev/null +++ b/_3ITTest.vb @@ -0,0 +1,754 @@ +' _3ITTest: The macros to for generating the report of independent T-Test +' by imacat , 2016-08-24 +Option Explicit + +' subTestIndependentTTest: Tests the independent T-test report +Sub subTestIndependentTTest + Dim oSheets As Object, sSheetName As String + Dim oSheet As Object, oRange As Object + + sSheetName = "ittest" + oSheets = ThisComponent.getSheets + If Not oSheets.hasByName (sSheetName) Then + MsgBox "Data sheet """ & sSheetName & """ not found" + Exit Sub + End If + If oSheets.hasByName (sSheetName & "_ttest") Then + oSheets.removeByName (sSheetName & "_ttest") + End If + If oSheets.hasByName (sSheetName & "_ttesttmp") Then + oSheets.removeByName (sSheetName & "_ttesttmp") + End If + oSheet = ThisComponent.getSheets.getByName (sSheetName) + oRange = oSheet.getCellRangeByName ("A15:B34") + subReportIndependentTTest (ThisComponent, oRange) +End Sub + +' subReportIndependentTTest: Reports the independent T-test +Sub subReportIndependentTTest (oDoc As Object, oDataRange As Object) + Dim oSheets As Object, sSheetName As String + Dim mNames () As String, nI As Integer, nSheetIndex As Integer + Dim oSheet As Object, oColumns As Object, nRow As Integer + Dim oCell As Object, oCells As Object, oCursor As Object, oTempDataRange As Object + Dim nN As Integer, sFormula As String, sSP2 As String + Dim nFormatN As Integer, nFormatF As Integer, nFormatP As Integer + Dim aBorderSingle As New com.sun.star.table.BorderLine + Dim aBorderDouble As New com.sun.star.table.BorderLine + Dim sCellXLabel As String, sCellsXData As String + Dim sCellXN As String, sCellXMean As String, sCellXS As String + Dim sCellYLabel As String, sCellsYData As String + Dim sCellYN As String, sCellYMean As String, sCellYS As String + Dim sCellF As String, sCellsN As String, sCellN As String + Dim sNotes As String, nPos As Integer + + oSheets = oDoc.getSheets + sSheetName = oDataRange.getSpreadsheet.getName + mNames = oSheets.getElementNames + For nI = 0 To UBound (mNames) + If mNames (nI) = sSheetName Then + nSheetIndex = nI + End If + Next nI + + oSheets.insertNewByName (sSheetName & "_ttesttmp", nSheetIndex + 1) + oSheet = oSheets.getByName (sSheetName & "_ttesttmp") + oTempDataRange = fnCollectIndependentTTestData (oDataRange, oSheet) + + oSheets.insertNewByName (sSheetName & "_ttest", nSheetIndex + 1) + oSheet = oSheets.getByName (sSheetName & "_ttest") + + sCellXLabel = fnGetRangeName (oTempDataRange.getCellByPosition (0, 0)) + nN = oTempDataRange.getCellByPosition (0, oTempDataRange.getRows.getCount - 3).getValue + oCells = oTempDataRange.getCellRangeByPosition (0, 1, 0, nN) + sCellsXData = fnGetRangeName (oCells) + sCellYLabel = fnGetRangeName (oTempDataRange.getCellByPosition (1, 0)) + nN = oTempDataRange.getCellByPosition (1, oTempDataRange.getRows.getCount - 3).getValue + oCells = oTempDataRange.getCellRangeByPosition (1, 1, 1, nN) + sCellsYData = fnGetRangeName (oCells) + + ' Obtains the format parameters for the report. + nFormatN = fnQueryFormat (oDoc, "#,##0") + nFormatF = fnQueryFormat (oDoc, "#,###.000") + nFormatP = fnQueryFormat (oDoc, "[<0.01]#.000""**"";[<0.05]#.000""*"";#.000") + + aBorderSingle.OuterLineWidth = 2 + aBorderDouble.OuterLineWidth = 2 + aBorderDouble.InnerLineWidth = 2 + aBorderDouble.LineDistance = 2 + + ' Sets the column widths of the report. + oColumns = oSheet.getColumns + oColumns.getByIndex (0).setPropertyValue ("Width", 3060) + oColumns.getByIndex (1).setPropertyValue ("Width", 2080) + oColumns.getByIndex (2).setPropertyValue ("Width", 2080) + oColumns.getByIndex (3).setPropertyValue ("Width", 2080) + oColumns.getByIndex (4).setPropertyValue ("Width", 2080) + + nRow = -2 + + ' Group description + nRow = nRow + 2 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Group Description") + oCell.setPropertyValue ("CellStyle", "Result2") + oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow) + oCells.merge (True) + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Group") + oCell = oSheet.getCellByPosition (1, nRow) + oCell.setString ("N") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (2, nRow) + oCell.setString ("X") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE) + oCell = oSheet.getCellByPosition (3, nRow) + oCell.setString ("s") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (4, nRow) + oCell.setString ("sX") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE) + + ' The first group + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + sFormula = "=" & sCellXLabel + oCell.setFormula (sFormula) + oCell = oSheet.getCellByPosition (1, nRow) + sFormula = "=COUNT(" & sCellsXData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + sCellXN = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=AVERAGE(" & sCellsXData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellXMean = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=STDEV(" & sCellsXData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellXS = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=" & sCellXS & "/SQRT(" & sCellXN & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + + ' The second group + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + sFormula = "=" & sCellYLabel + oCell.setFormula (sFormula) + oCell = oSheet.getCellByPosition (1, nRow) + sFormula = "=COUNT(" & sCellsYData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + sCellYN = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=AVERAGE(" & sCellsYData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellYMean = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=STDEV(" & sCellsYData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellYS = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=" & sCellYS & "/SQRT(" & sCellYN & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + + ' Draws the table borders. + oCells = oSheet.getCellByPosition (0, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (1, nRow - 2, 4, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow - 1) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellRangeByPosition (1, nRow, 4, nRow) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + + ' Levene's test for homogeneity of variances + nRow = nRow + 2 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Test for Homogeneity of Variances") + oCell.setPropertyValue ("CellStyle", "Result2") + oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow) + oCells.merge (True) + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Test") + oCell = oSheet.getCellByPosition (1, nRow) + oCell.setString ("F") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (2, nRow) + oCell.setString ("p") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + + ' The test result. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Levene’s Test") + oCell = oSheet.getCellByPosition (1, nRow) + sFormula = "=" & fnGetLeveneTest (oTempDataRange) + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellF = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (2, nRow) + sCellsN = fnGetRangeName (oTempDataRange.getCellRangeByPosition (0, oTempDataRange.getRows.getCount - 3, 1, oTempDataRange.getRows.getCount - 3)) + sCellN = fnGetRangeName (oTempDataRange.getCellByPosition (4, oTempDataRange.getRows.getCount - 3)) + sFormula = "=FDIST(" & sCellF & ";COUNT(" & sCellsN & ")-1;" & sCellN & "-COUNT(" & sCellsN & "))" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatP) + + ' The foot notes of the test. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _ + "H0: σ1=σ2 (homogeneity; the populations of the two groups have the same variances)." & Chr (10) & _ + "H1: σ1≠σ2 (heterogeneity; the populations of the two groups have different variances) if the probability (p) is small enough.") + oCell.setPropertyValue ("IsTextWrapped", True) + oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow) + oCells.merge (True) + sNotes = oCell.getString + oCursor = oCell.createTextCursor + nPos = InStr (sNotes, "p<") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (nPos + 1, sNotes, "p<") + Loop + nPos = InStr (sNotes, "(p)") + oCursor.gotoStart (False) + oCursor.goRight (nPos, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (sNotes, "σ") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + nPos = InStr (nPos + 1, sNotes, "σ") + Loop + nPos = InStr (sNotes, "H0") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + nPos = InStr (sNotes, "H1") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + + ' Draws the table borders. + oCells = oSheet.getCellByPosition (0, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (1, nRow - 2, 2, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow - 1) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellRangeByPosition (1, nRow - 1, 2, nRow - 1) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + + ' The independent samples T-test + nRow = nRow + 2 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Independent Samples T-Test") + oCell.setPropertyValue ("CellStyle", "Result2") + oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow) + oCells.merge (True) + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Type") + oCell = oSheet.getCellByPosition (1, nRow) + oCell.setString ("t") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (2, nRow) + oCell.setString ("df") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (3, nRow) + oCell.setString ("p") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (4, nRow) + oCell.setString ("X1-X2") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCursor.collapseToEnd + oCursor.goRight (1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + + ' The test of the homogeneity of variances. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Homogeneity") + oCell = oSheet.getCellByPosition (1, nRow) + sSP2 = "((SUMPRODUCT(" & sCellsXData & ";" & sCellsXData & ")-POWER(SUM(" & sCellsXData & ");2)/" & sCellXN & "+SUMPRODUCT(" & sCellsYData & ";" & sCellsYData & ")-POWER(SUM(" & sCellsYData & ");2)/" & sCellYN & ")/(" & sCellXN & "+" & sCellYN & "-2))" + sFormula = "=(" & sCellXMean & "-" & sCellYMean & ")/SQRT(" & sSP2 & "*(1/" & sCellXN & "+1/" & sCellYN & "))" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=" & sCellXN & "+" & sCellYN & "-2" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=TTEST(" & sCellsXData & ";" & sCellsYData & ";2;2)" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatP) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=" & sCellXMean & "-" & sCellYMean + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + + ' The test of the heterogeneity of variances. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Heterogeneity") + oCell = oSheet.getCellByPosition (1, nRow) + sFormula = "=(" & sCellXMean & "-" & sCellYMean & ")/SQRT(POWER(" & sCellXS & ";2)/" & sCellXN & "+POWER(" & sCellYS & ";2)/" & sCellYN & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=POWER(POWER(" & sCellXS & ";2)/" & sCellXN & "+POWER(" & sCellYS & ";2)/" & sCellYN & ";2)/(POWER(" & sCellXS & ";4)/(POWER(" & sCellXN & ";2)*(" & sCellXN & "-1))+POWER(" & sCellYS & ";4)/(POWER(" & sCellYN & ";2)*(" & sCellYN & "-1)))" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=TTEST(" & sCellsXData & ";" & sCellsYData & ";2;3)" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatP) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=" & sCellXMean & "-" & sCellYMean + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + + ' The foot notes of the test. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _ + "H0: μ1=μ2 (the populations of the two groups have the same means)." & Chr (10) & _ + "H1: μ1≠μ2 (the populations of the two groups have different means) if the probability (p) is small enough.") + oCell.setPropertyValue ("IsTextWrapped", True) + oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow) + oCells.merge (True) + sNotes = oCell.getString + oCursor = oCell.createTextCursor + nPos = InStr (sNotes, "p<") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (nPos + 1, sNotes, "p<") + Loop + nPos = InStr (sNotes, "(p)") + oCursor.gotoStart (False) + oCursor.goRight (nPos, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (sNotes, "μ") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + nPos = InStr (nPos + 1, sNotes, "μ") + Loop + nPos = InStr (sNotes, "H0") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + nPos = InStr (sNotes, "H1") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + + ' Draws the table borders. + oCells = oSheet.getCellByPosition (0, nRow - 3) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (1, nRow - 3, 4, nRow - 3) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow - 2) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow - 1) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellRangeByPosition (1, nRow - 1, 4, nRow - 1) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) +End Sub + +' fnCollectIndependentTTestData: Collects the data for the independent T-test. +Function fnCollectIndependentTTestData (oDataRange As Object, oReportSheet As Object) As Object + Dim nRow As Integer, nNRow As Integer, sCellZMean As String, sCellsN As String + Dim oCell As Object, oCells As Object, oCursor As Object + Dim sCell As String, sLabel As String, sFormula As String + Dim sCellXLabel As String, sCellsXData As String, sCellXMean As String + Dim sXLabel As String, nNX As Integer + Dim sCellsXZData As String, sCellXZMean As String + Dim sCellYLabel As String, sCellsYData As String, sCellYMean As String + Dim sYLabel As String, nNY As Integer + Dim sCellsYZData As String, sCellYZMean As String + + sCellXLabel = "" + sCellYLabel = "" + For nRow = 1 To oDataRange.getRows.getCount - 1 + oCell = oDataRange.getCellByPosition (0, nRow) + sLabel = oCell.getString + If sLabel <> "" Then + If sCellXLabel = "" Then + sCellXLabel = fnGetRangeName (oCell) + sXLabel = sLabel + Else + If sLabel <> sXLabel And sCellYLabel = "" Then + sCellYLabel = fnGetRangeName (oCell) + sYLabel = sLabel + nRow = oDataRange.getRows.getCount - 1 + End If + End If + End If + Next nRow + + ' The data labels + oCell = oReportSheet.getCellByPosition (0, 0) + sFormula = "=" & sCellXLabel + oCell.setFormula (sFormula) + oCell = oReportSheet.getCellByPosition (1, 0) + sFormula = "=" & sCellYLabel + oCell.setFormula (sFormula) + + ' The data + nNX = 0 + nNY = 0 + For nRow = 1 To oDataRange.getRows.getCount - 1 + If oDataRange.getCellByPosition (0, nRow).getString = sXLabel Then + nNX = nNX + 1 + sFormula = "=" & fnGetRangeName (oDataRange.getCellByPosition (1, nRow)) + oReportSheet.getCellByPosition (0, nNX).setFormula (sFormula) + Else + If oDataRange.getCellByPosition (0, nRow).getString = sYLabel Then + nNY = nNY + 1 + sFormula = "=" & fnGetRangeName (oDataRange.getCellByPosition (1, nRow)) + oReportSheet.getCellByPosition (1, nNY).setFormula (sFormula) + End If + End If + Next nRow + + ' Collects the data + sCellsXData = fnGetLocalRangeName (oReportSheet.getCellRangeByPosition (0, 1, 0, nNX)) + sCellsYData = fnGetLocalRangeName (oReportSheet.getCellRangeByPosition (1, 1, 1, nNY)) + If nNX > nNY Then + nNRow = nNX + 1 + Else + nNRow = nNY + 1 + End If + oCell = oReportSheet.getCellByPosition (0, nNRow) + sFormula = "=COUNT(" & sCellsXData & ")" + oCell.setFormula (sFormula) + oCell = oReportSheet.getCellByPosition (1, nNRow) + sFormula = "=COUNT(" & sCellsYData & ")" + oCell.setFormula (sFormula) + oCell = oReportSheet.getCellByPosition (0, nNRow + 1) + sFormula = "=AVERAGE(" & sCellsXData & ")" + oCell.setFormula (sFormula) + sCellXMean = fnGetLocalRangeName (oCell) + oCell = oReportSheet.getCellByPosition (1, nNRow + 1) + sFormula = "=AVERAGE(" & sCellsYData & ")" + oCell.setFormula (sFormula) + sCellYMean = fnGetLocalRangeName (oCell) + oCells = oReportSheet.getCellRangeByPosition (0, nNRow, 1, nNRow) + sCellsN = fnGetLocalRangeName (oCells) + + ' Calculates the Z values + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (0, 0)) + sFormula = "=""Z""&" & sCell + oCell = oReportSheet.getCellByPosition (2, 0) + oCell.setFormula (sFormula) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + For nRow = 1 To nNX + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (0, nRow)) + sFormula = "=ABS(" & sCell & "-" & sCellXMean & ")" + oCell = oReportSheet.getCellByPosition (2, nRow) + oCell.setFormula (sFormula) + Next nRow + sCellsXZData = fnGetLocalRangeName (oReportSheet.getCellRangeByPosition (2, 1, 2, nNX)) + oCell = oReportSheet.getCellByPosition (2, nNRow + 1) + sFormula = "=AVERAGE(" & sCellsXZData & ")" + oCell.setFormula (sFormula) + sCellXZMean = fnGetLocalRangeName (oCell) + + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (1, 0)) + sFormula = "=""Z""&" & sCell + oCell = oReportSheet.getCellByPosition (3, 0) + oCell.setFormula (sFormula) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + For nRow = 1 To nNY + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (1, nRow)) + sFormula = "=ABS(" & sCell & "-" & sCellYMean & ")" + oCell = oReportSheet.getCellByPosition (3, nRow) + oCell.setFormula (sFormula) + Next nRow + sCellsYZData = fnGetLocalRangeName (oReportSheet.getCellRangeByPosition (3, 1, 3, nNY)) + oCell = oReportSheet.getCellByPosition (3, nNRow + 1) + sFormula = "=AVERAGE(" & sCellsYZData & ")" + oCell.setFormula (sFormula) + sCellYZMean = fnGetLocalRangeName (oCell) + + ' Calculates the total average + oCell = oReportSheet.getCellByPosition (4, nNRow) + sFormula = "=SUM(" & sCellsN & ")" + oCell.setFormula (sFormula) + oCell = oReportSheet.getCellByPosition (4, nNRow + 1) + sFormula = "=AVERAGE(" & sCellsXZData & ";" & sCellsYZData & ")" + oCell.setFormula (sFormula) + sCellZMean = fnGetLocalRangeName (oCell) + + ' Calculates the difference of the Z values to their means + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (0, 0)) + sFormula = "=""dZ""&" & sCell + oCell = oReportSheet.getCellByPosition (4, 0) + oCell.setFormula (sFormula) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -44) + oCursor.setPropertyValue ("CharEscapementHeight", 34) + For nRow = 1 To nNX + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (2, nRow)) + sFormula = "=" & sCell & "-" & sCellXZMean + oCell = oReportSheet.getCellByPosition (4, nRow) + oCell.setFormula (sFormula) + Next nRow + + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (1, 0)) + sFormula = "=""dZ""&" & sCell + oCell = oReportSheet.getCellByPosition (5, 0) + oCell.setFormula (sFormula) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -44) + oCursor.setPropertyValue ("CharEscapementHeight", 34) + For nRow = 1 To nNY + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (3, nRow)) + sFormula = "=" & sCell & "-" & sCellYZMean + oCell = oReportSheet.getCellByPosition (5, nRow) + oCell.setFormula (sFormula) + Next nRow + + ' Calculates the difference of the Z means to the total mean + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (2, nNRow + 1)) + sFormula = "=" & sCell & "-" & sCellZMean + oCell = oReportSheet.getCellByPosition (2, nNRow + 2) + oCell.setFormula (sFormula) + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (3, nNRow + 1)) + sFormula = "=" & sCell & "-" & sCellZMean + oCell = oReportSheet.getCellByPosition (3, nNRow + 2) + oCell.setFormula (sFormula) + + fnCollectIndependentTTestData = oReportSheet.getCellRangeByPosition (0, 0, 5, nNRow + 2) +End Function + +' fnGetLeveneTest: Returns the Levene's test result. +Function fnGetLeveneTest (oZDataRange As Object) As String + Dim nK As Integer, nRows As Integer + Dim oCell As Object, oCells As Object + Dim sCellN As String, sCellsN As String + Dim sCellsDZMean As String, sCellsDZData As String + + nRows = oZDataRange.getRows.getCount + nK = oZDataRange.getColumns.getCount / 3 + oCell = oZDataRange.getCellByPosition (nK * 2, nRows - 3) + sCellN = fnGetRangeName (oCell) + oCells = oZDataRange.getCellRangeByPosition (0, nRows - 3, nK - 1, nRows - 3) + sCellsN = fnGetRangeName (oCells) + oCells = oZDataRange.getCellRangeByPosition (nK, nRows - 1, nK * 2 - 1, nRows - 1) + sCellsDZMean = fnGetRangeName (oCells) + oCells = oZDataRange.getCellRangeByPosition (nK * 2, 1, nK * 3 - 1, nRows - 4) + sCellsDZData = fnGetRangeName (oCells) + fnGetLeveneTest = "((" & sCellN & "-COUNT(" & sCellsN & "))/(COUNT(" & sCellsN & ")-1))*(SUMPRODUCT(" & sCellsN & ";" & sCellsDZMean & ";" & sCellsDZMean & ")/SUMPRODUCT(" & sCellsDZData & ";" & sCellsDZData & "))" +End Function diff --git a/_4ANOVA.vb b/_4ANOVA.vb new file mode 100644 index 0000000..49e7004 --- /dev/null +++ b/_4ANOVA.vb @@ -0,0 +1,1018 @@ +' _4ANOVA: The macros to for generating the report of ANOVA (Analyze of Variances) +' by imacat , 2016-08-31 +Option Explicit + +' subTestANOVA: Tests the ANOVA (Analyze of Variances) report +Sub subTestANOVA + Dim oSheets As Object, sSheetName As String + Dim oSheet As Object, oRange As Object + + sSheetName = "anova" + oSheets = ThisComponent.getSheets + If Not oSheets.hasByName (sSheetName) Then + MsgBox "Data sheet """ & sSheetName & """ not found" + Exit Sub + End If + If oSheets.hasByName (sSheetName & "_anova") Then + oSheets.removeByName (sSheetName & "_anova") + End If + If oSheets.hasByName (sSheetName & "_anovatmp") Then + oSheets.removeByName (sSheetName & "_anovatmp") + End If + oSheet = ThisComponent.getSheets.getByName (sSheetName) + oRange = oSheet.getCellRangeByName ("A13:B35") + subReportANOVA (ThisComponent, oRange) +End Sub + +' subReportANOVA: Reports the ANOVA (Analyze of Variances) +Sub subReportANOVA (oDoc As Object, oDataRange As Object) + Dim oSheets As Object, sSheetName As String + Dim nI As Integer, nJ As Integer + Dim mNames () As String, nSheetIndex As Integer + Dim oSheet As Object, oColumns As Object, nRow As Integer, nStartRow As Integer + Dim oCell As Object, oCells As Object, oCursor As Object, oTempDataRange As Object + Dim nN As Integer, sFormula As String + Dim nFormatN As Integer, nFormatF As Integer, nFormatP As Integer + Dim aBorderSingle As New com.sun.star.table.BorderLine + Dim aBorderDouble As New com.sun.star.table.BorderLine + + Dim nGroups As Integer + Dim mCellLabel () As String, mCellsData () As String + Dim mCellN () As String, mCellMean () As String, mCellS () As String + Dim sCellsData As String + Dim sCellF As String, sCellDFB As String, sCellDFW As String + Dim sCellsN As String, sCellN As String, sCellS As String + Dim sCellSSB As String, sCellSSW As String, sCellSST As String + Dim sCellMSB As String, sCellMSW As String + Dim sCellMeanDiff As String + Dim sNotes As String, nPos As Integer + + oSheets = oDoc.getSheets + sSheetName = oDataRange.getSpreadsheet.getName + mNames = oSheets.getElementNames + For nI = 0 To UBound (mNames) + If mNames (nI) = sSheetName Then + nSheetIndex = nI + End If + Next nI + + oSheets.insertNewByName (sSheetName & "_anovatmp", nSheetIndex + 1) + oSheet = oSheets.getByName (sSheetName & "_anovatmp") + oTempDataRange = fnCollectANOVAData (oDataRange, oSheet) + nGroups = oTempDataRange.getColumns.getCount / 3 + + oSheets.insertNewByName (sSheetName & "_anova", nSheetIndex + 1) + oSheet = oSheets.getByName (sSheetName & "_anova") + + ReDim mCellLabel (nGroups - 1) As String, mCellsData (nGroups - 1) As String + ReDim mCellN (nGroups - 1) As String, mCellMean (nGroups - 1) As String + ReDim mCellS (nGroups - 1) As String + + For nI = 0 To nGroups - 1 + mCellLabel (nI) = fnGetRangeName (oTempDataRange.getCellByPosition (nI, 0)) + nN = oTempDataRange.getCellByPosition (nI, oTempDataRange.getRows.getCount - 3).getValue + oCells = oTempDataRange.getCellRangeByPosition (nI, 1, nI, nN) + mCellsData (nI) = fnGetRangeName (oCells) + Next nI + + ' Obtains the format parameters for the report. + nFormatN = fnQueryFormat (oDoc, "#,##0") + nFormatF = fnQueryFormat (oDoc, "#,###.000") + nFormatP = fnQueryFormat (oDoc, "[<0.01]#.000""**"";[<0.05]#.000""*"";#.000") + + aBorderSingle.OuterLineWidth = 2 + aBorderDouble.OuterLineWidth = 2 + aBorderDouble.InnerLineWidth = 2 + aBorderDouble.LineDistance = 2 + + ' Sets the column widths of the report. + oColumns = oSheet.getColumns + oColumns.getByIndex (0).setPropertyValue ("Width", 3060) + oColumns.getByIndex (1).setPropertyValue ("Width", 3060) + oColumns.getByIndex (2).setPropertyValue ("Width", 2080) + oColumns.getByIndex (3).setPropertyValue ("Width", 2080) + oColumns.getByIndex (4).setPropertyValue ("Width", 2080) + oColumns.getByIndex (5).setPropertyValue ("Width", 2080) + oColumns.getByIndex (6).setPropertyValue ("Width", 2080) + + nRow = -2 + + ' Group description + nRow = nRow + 2 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Group Description") + oCell.setPropertyValue ("CellStyle", "Result2") + oCells = oSheet.getCellRangeByPosition (0, nRow, 5, nRow) + oCells.merge (True) + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Group") + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + oCell.setString ("N") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (3, nRow) + oCell.setString ("X") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE) + oCell = oSheet.getCellByPosition (4, nRow) + oCell.setString ("s") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (5, nRow) + oCell.setString ("sX") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE) + + ' Show each group + sCellsData = "" + For nI = 0 To nGroups - 1 + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + sFormula = "=" & mCellLabel (nI) + oCell.setFormula (sFormula) + mCellLabel (nI) = fnGetLocalRangeName (oCell) + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=COUNT(" & mCellsData (nI) & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + mCellN (nI) = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=AVERAGE(" & mCellsData (nI) & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + mCellMean (nI) = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=STDEV(" & mCellsData (nI) & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + mCellS (nI) = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (5, nRow) + sFormula = "=" & mCellS (nI) & "/SQRT(" & mCellN (nI) & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellsData = sCellsData & ";" & mCellsData (nI) + Next nI + sCellsData = Right (sCellsData, Len (sCellsData) - 1) + ' Shows the total + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Total") + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=COUNT(" & sCellsData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + sCellN = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=AVERAGE(" & sCellsData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=STDEV(" & sCellsData & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellS = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (5, nRow) + sFormula = "=" & sCellS & "/SQRT(" & sCellN & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + + ' Draws the table borders. + oCells = oSheet.getCellByPosition (0, nRow - nGroups - 1) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (1, nRow - nGroups - 1, 5, nRow - nGroups - 1) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (0, nRow - nGroups, 0, nRow - 1) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow) + oCells.setPropertyValue ("TopBorder", aBorderSingle) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellRangeByPosition (1, nRow, 5, nRow) + oCells.setPropertyValue ("TopBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + + ' Levene's test for homogeneity of variances + nRow = nRow + 2 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Test for Homogeneity of Variances") + oCell.setPropertyValue ("CellStyle", "Result2") + oCells = oSheet.getCellRangeByPosition (0, nRow, 5, nRow) + oCells.merge (True) + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Test") + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + oCell.setString ("F") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (3, nRow) + oCell.setString ("dfb") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (2, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (4, nRow) + oCell.setString ("dfw") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (2, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (5, nRow) + oCell.setString ("p") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + + ' The test result. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Levene’s Test") + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=" & fnGetLeveneTest (oTempDataRange) + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellF = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (3, nRow) + sCellsN = fnGetRangeName (oTempDataRange.getCellRangeByPosition (0, oTempDataRange.getRows.getCount - 3, nGroups - 1, oTempDataRange.getRows.getCount - 3)) + sFormula = "=COUNT(" & sCellsN & ")-1" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + sCellDFB = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (4, nRow) + sCellN = fnGetRangeName (oTempDataRange.getCellByPosition (nGroups * 2, oTempDataRange.getRows.getCount - 3)) + sFormula = "=" & sCellN & "-COUNT(" & sCellsN & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + sCellDFW = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (5, nRow) + sFormula = "=FDIST(" & sCellF & ";" & sCellDFB & ";" & sCellDFW & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatP) + + ' The foot notes of the test. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _ + "H0: σ1=σ2=…σN (the populations of the groups have the same variances)." & Chr (10) & _ + "H1: ANOVA does not apply (the populations of the groups does not have the same variances) if the probability (p) is small enough.") + oCell.setPropertyValue ("IsTextWrapped", True) + oCells = oSheet.getCellRangeByPosition (0, nRow, 5, nRow) + oCells.merge (True) + sNotes = oCell.getString + oCursor = oCell.createTextCursor + nPos = InStr (sNotes, "p<") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (nPos + 1, sNotes, "p<") + Loop + nPos = InStr (sNotes, "(p)") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (sNotes, "σ") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + nPos = InStr (nPos + 1, sNotes, "σ") + Loop + nPos = InStr (sNotes, "σN") + oCursor.gotoStart (False) + oCursor.goRight (nPos, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (sNotes, "H0") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow) + nPos = InStr (sNotes, "H1") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + + ' Draws the table borders. + oCells = oSheet.getCellByPosition (0, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (1, nRow - 2, 5, nRow - 2) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow - 1) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellRangeByPosition (1, nRow - 1, 5, nRow - 1) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + + ' The ANOVA (analysis of variances) + nRow = nRow + 2 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("One-way ANOVA (Analysis of Variances)") + oCell.setPropertyValue ("CellStyle", "Result2") + oCells = oSheet.getCellRangeByPosition (0, nRow, 6, nRow) + oCells.merge (True) + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Source of Variation") + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + oCell.setString ("SS") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (3, nRow) + oCell.setString ("df") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (4, nRow) + oCell.setString ("MS") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (5, nRow) + oCell.setString ("F") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (6, nRow) + oCell.setString ("p") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + + ' Between groups + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Between Groups") + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=" + For nI = 0 To nGroups - 1 + sFormula = sFormula & "POWER(SUM(" & mCellsData (nI) & ");2)/" & mCellN (nI) & "+" + Next nI + sFormula = Left (sFormula, Len (sFormula) - 1) & "-POWER(SUM(" & sCellsData & ");2)/" & sCellN + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellSSB = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=" & sCellDFB + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + sCellDFB = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=" & sCellSSB & "/" & sCellDFB + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellMSB = fnGetLocalRangeName (oCell) + + ' Within groups + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Within Groups") + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=" + For nI = 0 To nGroups - 1 + sFormula = sFormula & "(SUMPRODUCT(" & mCellsData (nI) & ";" & mCellsData (nI) & ")-POWER(SUM(" & mCellsData (nI) & ");2)/" & mCellN (nI) & ")+" + Next nI + sFormula = Left (sFormula, Len (sFormula) - 1) + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellSSW = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=" & sCellDFW + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + sCellDFW = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=" & sCellSSW & "/" & sCellDFW + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellMSW = fnGetLocalRangeName (oCell) + + nRow = nRow - 1 + oCell = oSheet.getCellByPosition (5, nRow) + sFormula = "=" & sCellMSB & "/" & sCellMSW + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellF = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (6, nRow) + sFormula = "=FDIST(" & sCellF & ";" & sCellDFB & ";" & sCellDFW & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatP) + nRow = nRow + 1 + + ' Total + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Total") + oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow) + oCells.merge (True) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=" & sCellSSB & "+" & sCellSSW + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=" & sCellDFB & "+" & sCellDFW + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatN) + + ' The foot notes of the test. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _ + "H0: μ1=μ2=…μN (the populations of the groups have the same means)." & Chr (10) & _ + "H1: The above is false (the populations of the groups does not have the same means) if the probability (p) is small enough.") + oCell.setPropertyValue ("IsTextWrapped", True) + oCells = oSheet.getCellRangeByPosition (0, nRow, 6, nRow) + oCells.merge (True) + sNotes = oCell.getString + oCursor = oCell.createTextCursor + nPos = InStr (sNotes, "p<") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (nPos + 1, sNotes, "p<") + Loop + nPos = InStr (sNotes, "(p)") + oCursor.gotoStart (False) + oCursor.goRight (nPos, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (sNotes, "μ") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + nPos = InStr (nPos + 1, sNotes, "μ") + Loop + nPos = InStr (sNotes, "μN") + oCursor.gotoStart (False) + oCursor.goRight (nPos, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (sNotes, "H0") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + nPos = InStr (sNotes, "H1") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + + ' Draws the table borders. + oCells = oSheet.getCellByPosition (0, nRow - 4) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (1, nRow - 4, 6, nRow - 4) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (0, nRow - 3, 0, nRow - 2) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow - 1) + oCells.setPropertyValue ("TopBorder", aBorderSingle) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellRangeByPosition (1, nRow - 1, 6, nRow - 1) + oCells.setPropertyValue ("TopBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + + ' The post-hoc test between groups with Scheffé's method + nRow = nRow + 2 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Post-Hoc Test Between Groups with Scheffé's Method") + oCell.setPropertyValue ("CellStyle", "Result2") + oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow) + oCells.merge (True) + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Xi") + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCell = oSheet.getCellByPosition (1, nRow) + oCell.setString ("Xj") + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCell = oSheet.getCellByPosition (2, nRow) + oCell.setString ("Xi-Xj") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCursor.collapseToEnd + oCursor.goRight (1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCell = oSheet.getCellByPosition (3, nRow) + oCell.setString ("F") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCell = oSheet.getCellByPosition (4, nRow) + oCell.setString ("p") + oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + + ' The tests between groups + nRow = nRow + 1 + For nI = 0 To nGroups - 1 + oCell = oSheet.getCellByPosition (0, nRow) + sFormula = "=" & mCellLabel (nI) + oCell.setFormula (sFormula) + For nJ = 0 To nGroups - 1 + If nI <> nJ Then + oCell = oSheet.getCellByPosition (1, nRow) + sFormula = "=" & mCellLabel (nJ) + oCell.setFormula (sFormula) + oCell = oSheet.getCellByPosition (2, nRow) + sFormula = "=" & mCellMean (nI) & "-" & mCellMean (nJ) + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellMeanDiff = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (3, nRow) + sFormula = "=POWER(" & sCellMeanDiff & ";2)/(" & sCellMSW & "*(1/" & mCellN (nI) & "+1/" & mCellN (nJ) & "))" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatF) + sCellF = fnGetLocalRangeName (oCell) + oCell = oSheet.getCellByPosition (4, nRow) + sFormula = "=FDIST(" & sCellF & "/" & sCellDFB & ";" & sCellDFB & ";" & sCellDFW & ")" + oCell.setFormula (sFormula) + oCell.setPropertyValue ("NumberFormat", nFormatP) + nRow = nRow + 1 + End If + Next nJ + Next nI + nRow = nRow - 1 + + ' The foot notes of the test. + nRow = nRow + 1 + oCell = oSheet.getCellByPosition (0, nRow) + oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _ + "H0: μi=μj (the populations of the two groups have the same means)." & Chr (10) & _ + "H1: μi≠μj (the populations of the two groups have different means) if the probability (p) is small enough.") + oCell.setPropertyValue ("IsTextWrapped", True) + oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow) + oCells.merge (True) + sNotes = oCell.getString + oCursor = oCell.createTextCursor + nPos = InStr (sNotes, "p<") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (nPos + 1, sNotes, "p<") + Loop + nPos = InStr (sNotes, "(p)") + oCursor.gotoStart (False) + oCursor.goRight (nPos, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (sNotes, "μ") + Do While nPos <> 0 + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + nPos = InStr (nPos + 1, sNotes, "μ") + Loop + nPos = InStr (sNotes, "H0") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + nPos = InStr (sNotes, "H1") + oCursor.gotoStart (False) + oCursor.goRight (nPos - 1, False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + + ' Draws the table borders. + nStartRow = nRow - (nGroups * (nGroups - 1)) - 1 + oCells = oSheet.getCellByPosition (0, nStartRow) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (1, nStartRow) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (2, nStartRow, 4, nStartRow) + oCells.setPropertyValue ("TopBorder", aBorderDouble) + oCells.setPropertyValue ("BottomBorder", aBorderSingle) + oCells = oSheet.getCellRangeByPosition (1, nStartRow + 1, 1, nRow - 2) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells = oSheet.getCellByPosition (0, nRow - 1) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellByPosition (1, nRow - 1) + oCells.setPropertyValue ("RightBorder", aBorderSingle) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) + oCells = oSheet.getCellRangeByPosition (2, nRow - 1, 4, nRow - 1) + oCells.setPropertyValue ("BottomBorder", aBorderDouble) +End Sub + +' fnCollectANOVAData: Collects the data for the ANOVA (Analyze of Variances). +Function fnCollectANOVAData (oDataRange As Object, oReportSheet As Object) As Object + Dim nRow As Integer, nColumn As Integer, nI As Integer + Dim nNRow As Integer, sCellZMean As String, sCellsN As String + Dim oCell As Object, oCells As Object, oCursor As Object + Dim sCell As String, sLabel As String, sFormula As String + Dim nGroups As Integer, sLabels As String + Dim mLabels () As String, mCellLabel () As String + Dim mCellsData () As String, mCellMean () As String + Dim mN () As Integer, mCellsZData () As String + Dim mCellZMean () As String + + sLabels = " " + nGroups = 0 + For nRow = 1 To oDataRange.getRows.getCount - 1 + sLabel = oDataRange.getCellByPosition (0, nRow).getString + If InStr (sLabels, " " & sLabel & " ") = 0 Then + sLabels = sLabels & sLabel & " " + nGroups = nGroups + 1 + End If + Next nRow + + ReDim mLabels (nGroups - 1) As String, mCellLabel (nGroups - 1) As String + ReDim mCellsData (nGroups - 1) As String, mCellMean (nGroups - 1) As String + ReDim mN (nGroups - 1) As Integer, mCellsZData (nGroups - 1) As String + ReDim mCellZMean (nGroups - 1) As String + + sLabels = " " + nGroups = 0 + For nRow = 1 To oDataRange.getRows.getCount - 1 + oCell = oDataRange.getCellByPosition (0, nRow) + sLabel = oCell.getString + If InStr (sLabels, " " & sLabel & " ") = 0 Then + sLabels = sLabels & sLabel & " " + mLabels (nGroups) = sLabel + mCellLabel (nGroups) = fnGetRangeName (oCell) + nGroups = nGroups + 1 + End If + Next nRow + + ' The data labels + For nI = 0 To nGroups - 1 + oCell = oReportSheet.getCellByPosition (nI, 0) + sFormula = "=" & mCellLabel (nI) + oCell.setFormula (sFormula) + Next nI + + ' The data + For nI = 0 To nGroups - 1 + mN (nI) = 0 + Next nI + For nRow = 1 To oDataRange.getRows.getCount - 1 + sLabel = oDataRange.getCellByPosition (0, nRow).getString + For nI = 0 To nGroups - 1 + If sLabel = mLabels (nI) Then + nColumn = nI + nI = nGroups - 1 + End If + Next nI + mN (nColumn) = mN (nColumn) + 1 + sFormula = "=" & fnGetRangeName (oDataRange.getCellByPosition (1, nRow)) + oCell = oReportSheet.getCellByPosition (nColumn, mN (nColumn)) + oCell.setFormula (sFormula) + Next nRow + + ' Collects the data + For nI = 0 To nGroups - 1 + mCellsData (nI) = fnGetLocalRangeName (oReportSheet.getCellRangeByPosition (nI, 1, nI, mN (nI))) + Next nI + nNRow = 0 + For nI = 0 To nGroups - 1 + If nNRow < mN (nI) Then + nNRow = mN (nI) + End If + Next nI + nNRow = nNRow + 1 + For nI = 0 To nGroups - 1 + oCell = oReportSheet.getCellByPosition (nI, nNRow) + sFormula = "=COUNT(" & mCellsData (nI) & ")" + oCell.setFormula (sFormula) + oCell = oReportSheet.getCellByPosition (nI, nNRow + 1) + sFormula = "=AVERAGE(" & mCellsData (nI) & ")" + oCell.setFormula (sFormula) + mCellMean (nI) = fnGetLocalRangeName (oCell) + Next nI + oCells = oReportSheet.getCellRangeByPosition (0, nNRow, nGroups - 1, nNRow) + sCellsN = fnGetLocalRangeName (oCells) + + ' Calculates the Z values + For nI = 0 To nGroups - 1 + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (nI, 0)) + sFormula = "=""Z""&" & sCell + oCell = oReportSheet.getCellByPosition (nGroups + nI, 0) + oCell.setFormula (sFormula) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + For nRow = 1 To mN (nI) + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (nI, nRow)) + sFormula = "=ABS(" & sCell & "-" & mCellMean (nI) & ")" + oCell = oReportSheet.getCellByPosition (nGroups + nI, nRow) + oCell.setFormula (sFormula) + Next nRow + mCellsZData (nI) = fnGetLocalRangeName (oReportSheet.getCellRangeByPosition (nGroups + nI, 1, nGroups + nI, mN (nI))) + oCell = oReportSheet.getCellByPosition (nGroups + nI, nNRow + 1) + sFormula = "=AVERAGE(" & mCellsZData (nI) & ")" + oCell.setFormula (sFormula) + mCellZMean (nI) = fnGetLocalRangeName (oCell) + Next nI + + ' Calculates the total average + oCell = oReportSheet.getCellByPosition (nGroups * 2, nNRow) + sFormula = "=SUM(" & sCellsN & ")" + oCell.setFormula (sFormula) + oCell = oReportSheet.getCellByPosition (nGroups * 2, nNRow + 1) + sFormula = "" + For nI = 0 To nGroups - 1 + sFormula = sFormula & ";" & mCellsZData (nI) + Next nI + sFormula = "=AVERAGE(" & Right (sFormula, Len (sFormula) - 1) + oCell.setFormula (sFormula) + sCellZMean = fnGetLocalRangeName (oCell) + + ' Calculates the difference of the Z values to their means + For nI = 0 To nGroups - 1 + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (nI, 0)) + sFormula = "=""dZ""&" & sCell + oCell = oReportSheet.getCellByPosition (nGroups * 2 + nI, 0) + oCell.setFormula (sFormula) + oCursor = oCell.createTextCursor + oCursor.gotoStart (False) + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.collapseToEnd + oCursor.goRight (1, True) + oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC) + oCursor.setPropertyValue ("CharEscapement", -33) + oCursor.setPropertyValue ("CharEscapementHeight", 58) + oCursor.collapseToEnd + oCursor.gotoEnd (True) + oCursor.setPropertyValue ("CharEscapement", -44) + oCursor.setPropertyValue ("CharEscapementHeight", 34) + For nRow = 1 To mN (nI) + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (nGroups + nI, nRow)) + sFormula = "=" & sCell & "-" & mCellZMean (nI) + oCell = oReportSheet.getCellByPosition (nGroups * 2 + nI, nRow) + oCell.setFormula (sFormula) + Next nRow + Next nI + + ' Calculates the difference of the Z means to the total mean + For nI = 0 To nGroups - 1 + sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (nGroups + nI, nNRow + 1)) + sFormula = "=" & sCell & "-" & sCellZMean + oCell = oReportSheet.getCellByPosition (nGroups + nI, nNRow + 2) + oCell.setFormula (sFormula) + Next nI + + fnCollectANOVAData = oReportSheet.getCellRangeByPosition (0, 0, nGroups * 3 - 1, nNRow + 2) +End Function