(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 9.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       157,          7]
NotebookDataLength[      6091,        363]
NotebookOptionsPosition[      5846,        350]
NotebookOutlinePosition[      6190,        365]
CellTagsIndexPosition[      6147,        362]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell["\<\
(* SLOPE-09 - This program is used to compare slopes or intercepts from two

   regression lines calculated using probit, logit, or complementary 

   log-log transformations. The independent variable (time or dose) may

   have been transformed using log10. Note that the same 

   transformations must have been used for both dependent and 

   independent variables for the two regression lines. That is, if you

   used the probit transformation of the dependent variable and the

   log10 transformation of the independent variable for one data set, 

   you must have used those same transformations for the other data

   set. The program reads input from the file SLinput. The user should 

   make no changes to the program below. *)



(* This program was developed by:



   Jim Throne

   USDA, ARS, SJVASC

   9611 South Riverbend Avenue

   Parlier CA 93648

   (559) 596-2702

   james.throne@ars.usda.gov



   Please notify me of problems or suggestions.  3 June 2013 *)



Off[]



(* Read the input data set. *)



data = ReadList[\"SLinput\"];



filename = data[[1]];

title1 = data[[2]];

title2 = data[[3]];

a1 = data[[4]];

a2 = data[[5]];

b1 = data[[6]];

b2 = data[[7]];

sea1 = data[[8]];

sea2 = data[[9]];

seb1 = data[[10]];

seb2 = data[[11]];

n1 = data[[12]];

n2 = data[[13]];

chisq = data[[14]];



(* The next line opens the output file for writing. *)



out=OpenWrite[filename,FormatType->OutputForm,PageWidth->76];



(* The next lines put descriptions on the output file. *)



WriteString[out,title1]

WriteString[out,\" \\n\"]

WriteString[out,title2]

WriteString[out,\" \\n\"]

WriteString[out,\" \\n\\n\"]



(* Descriptions of input data. *)



(*   a1, a2       Intercepts for the two regression lines.  *)



(*   b1, b2       Slopes for the two regression lines. *)



(*   sea1, sea2   Standard errors for the intercepts for the two

                  regression lines.  *)



(*   seb1, seb2   Standard errors for the slopes for the two

                  regression lines. *)



(*   n1, n2       Number of observations used to calculate statistics

                  for the two regression lines. *)



(*   chisq        Set to yes if the chisqare for either regression 

                  line is significant.  If neither is significant,

                  set to no.  Enclose choice in quotation marks. *)



(* The user should not make any changes to the program below. *)



WriteString[out,\"Input data: \\n\\n\"]

WriteString[out,\"Intercept1 = \"]

Write[out,a1]

WriteString[out,\"Intercept2 = \"]

Write[out,a2]

WriteString[out,\"Slope1 = \"]

Write[out,b1]

WriteString[out,\"Slope2 = \"]

Write[out,b2]

WriteString[out,\"SE Intercept1 = \"]

Write[out,sea1]

WriteString[out,\"SE Intercept2 = \"]

Write[out,sea2]

WriteString[out,\"SE Slope1 = \"]

Write[out,seb1]

WriteString[out,\"SE Slope2 = \"]

Write[out,seb2]

WriteString[out,\"Number of doses or times in data set 1 = \"]

Write[out,n1]

WriteString[out,\"Number of doses or times in data set 2 = \"]

Write[out,n2]

WriteString[out,\"Is either chi-square significant? = \"]

Write[out,chisq]

WriteString[out,\" \\n\\n\"]



(* Calculate the test statistic. *)



tstata=Abs[(a1-a2)]/Sqrt[(sea1^2)+(sea2^2)] //N;

tstatb=Abs[(b1-b2)]/Sqrt[(seb1^2)+(seb2^2)] //N;



Write[out,\"The test statistic for the intercepts is \",tstata]

Write[out,\"The test statistic for the slopes is \",tstatb]

WriteString[out,\" \\n\\n\"]



(* Determine z value or t value, depending on whether chisquare is

   significant. *)



Do[

If[chisq==\"yes\",Goto[yes]];

z05=1.96;

z01=2.575;

If[tstata>=z01,Write[out,

\"The intercepts are different at the .01 level.\"],Goto[step2]];

Goto[step3];

Label[step2];

If[tstata>=z05 && tstata<z01,Write[out,

\"The intercepts are different at the .05 level.\"],

Write[out,\"The intercepts are not different at the .05 level.\"],];

Label[step3];

If[tstatb>=z01,Write[out,\"The slopes are different at the .01 level.

  \"],Goto[step4]];

Goto[end];

Label[step4];

If[tstatb>=z05 && tstatb<z01,Write[out,

\"The slopes are different at the .05 level.\"],

  Write[out,\"The slopes are not different at the .05 level.\"]];

Goto[end];

Label[yes];

ndist=NormalDistribution[0,1];

t1=StudentTDistribution[n1-2];

t2=StudentTDistribution[n2-2];

t105=Quantile[t1,.975];

t101=Quantile[t1,.995];

t205=Quantile[t2,.975];

t201=Quantile[t2,.995];

t05a=(((sea1^2)*t105)+((sea2^2)*t205))/((sea1^2)+(sea2^2));

t05b=(((seb1^2)*t105)+((seb2^2)*t205))/((seb1^2)+(seb2^2));

t01a=(((sea1^2)*t101)+((sea2^2)*t201))/((sea1^2)+(sea2^2));

t01b=(((seb1^2)*t101)+((seb2^2)*t201))/((seb1^2)+(seb2^2));

If[tstata>=t01a,Write[out,

\"The intercepts are different at the .01 level.\"],Goto[step5]];

Goto[step6];

Label[step5];

If[tstata>=t05a && tstata<t01a,

Write[out,\"The intercepts are different at the .05 level.\"],

Write[out,\"The intercepts are not different at the .05 level.\"]];

Label[step6];

If[tstatb>=t01b,Write[out,

\"The slopes are different at the .01 level.\"],Goto[step7]];

Goto[end];

Label[step7];

If[tstatb>=t05b && tstatb<t01b,

Write[out,\"The slopes are different at the .05 level.\"],

Write[out,\"The slopes are not different at the .05 level.\"]];

Label[end],{i,1}]



Close[out]\
\>", "Input"]
},
WindowSize->{707, 787},
WindowMargins->{{48, Automatic}, {Automatic, 60}},
FrontEndVersion->"9.0 for Microsoft Windows (64-bit) (January 25, 2013)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[557, 20, 5285, 328, 5573, "Input"]
}
]
*)

(* End of internal cache information *)

