In: Math
5.
a. Analyze the Bread variable in the SandwichAnts dataset using
aov() in R and
interpret your results.
The data may be found here:
install.packages("Lock5Data")
library(Lock5Data)
data(SandwichAnts,package="Lock5Data")
attach(SandwichAnts)
b. State the linear model for this problem. Define all notation and
model terms.
c. Create the design matrix for this problem.
d. Estimate model parameters for this problem using ? =
(?T?)-1?T?
e. Interpret the meaning of the estimates from part d.
f. Rerun this problem using lm()in R. Interpret the coefficients in
the output.
g. Rewrite the model in as a linear regression using dummy
variables. Confirm the
results from part f. agree with the results from part g.
h. Perform a one-way ANOVA of Bread using a randomization test on
the
SandwichAnts dataset.
(a)
You did not mention the dependent variable. I suppose it is the Ants variable in SandwichAnts data If it is not then you can ask me in comments.
[ I am giving the R codes for the first 4 Questions.]
library(Lock5Data)
data(SandwichAnts,package="Lock5Data")
attach(SandwichAnts)
summary(SandwichAnts)
# (b)
# Here Ants is discrete variable order
iscontinuous variable and the
others are catagorical
variable.
# Let us build the linear model for this
# y=b1+x1+x2+e where y:- Ants, b1:- constant term, X1:-Effect of
Bread, X2:-Effect of Filling, e:- Error(follows independently
Normal with mean zero and
unknownvarince)
#(c)
# the design matrix is X = [1,x11,x12,x13,x14,x21,x22,x23]
# where 1 is the vector of ones X1 is divided into 4 catagories and
X2 is divided into 3 catagories
# X11,x12,...,X14 are 4 dummy variables denoting four catagories of
X1 and X21,x22,x23 are the three dummy variables denoting three
catagories of x2
x11=as.numeric(Bread=="Multigrain") ;
x12=as.numeric(Bread=="Rye")
x13=as.numeric(Bread=="White") ;
x14=as.numeric(Bread=="Wholemeal")
x21=as.numeric(Filling=="Ham & Pickles") ; x22=as.numeric(Filling=="Peanut Butter") ;x23=as.numeric(Filling=="Vegemite")
X=cbind(rep(1,24),x11,x12,x13,x14,x21,x22,x23)
#(d)
library(matlib)
b=Ginv(t(X)%*%X)%*%(t(X)%*%Ants) # estimated parameters
b=((X'x)^-1)X'y
[ If you have any confusion regarding anything let me know]