Skip to main content

Posts

Showing posts from February, 2018

Obtain coefficients for orthogonal polynomial contrasts (SAS and R)

Objective : We are comparing means using ANOVA, and our treatment levels are amounts of something.  Thus regression hypotheses may shed light on how the treatments differ, for example is there an overall linear trend for the response variable to increase or decrease with treatment level.  This is addressed by adding orthogonal polynomial contrasts to our ANOVA, which may require that we add contrast coefficients. Example :  Treatments are amounts of corn in the diet, specifically 62%, 65%, 68%, 71% and 74%. SAS :  IML product has an orthogonal polynomial calculator.  Additional code here attempts to make the coefficients whole numbers by dividing by the smallest non-zero number.  Note IML may not be available, depending on your license. proc iml; trtlevels={0.62, 0.65,0.68,0.71,0.74}; **this is only user input; ntrt=nrow(trtlevels); coeff=orpol(trtlevels); coeff = coeff[,2:ntrt]; div=abs(coeff); zerloc=loc(div<1e-14); if nrow(zerloc)>0 then div[zer

Sample size to estimate a mean with given precision (SAS and R)

Objective :  We need to know how many observations to collect so our estimate of the mean has a useful precision.  For example, how many animals should be measured in order to have an 80% chance that the 95% confidence interval for weight will be no wider than 20 kg?  In addition to those 3 numbers, we also need an estimate of the std. deviation.  Suppose the best situation expected has SD=20kg, but we also want to see what changes if SD=40kg, SAS:   Run this code proc power;    onesamplemeans ci=t       alpha = 0.05       halfwidth = 10       stddev = 20 40       probwidth = 0.80       ntotal = .; run; data adjust;  samplesize=22;  population=1200;  adjsamplesize=ceil(samplesize/(1 + ((samplesize-1)/population))); run; proc print; run; The 95% confidence interval is requested by setting alpha=0.05. The 80% chance that our experiment will satisfy our objectives is specified by probwidth=0.80. The "no wider than 20" objective is addressed with halfwidth=10,