[R] Combining two models into one
luana
luana.paponi at libero.it
Sun Oct 20 08:49:16 CEST 2013
Hi guys,
I'm trying to combining 2 models into 1 but maybe I'm not doing this in the
right way.
my dataset is about the level of the vitamin A in the blood measured at
different times with two different treatments (ie. I have 6 coloums, vit A1
, time1, treat1, vit A2, time2, treat2, n=28). It wants to determinate if
the variable treatment is really appropriate.
E(y) = β0 + β1 x + β2 x^2 (treatment1)
= γ0 + γ1 x + γ2 x^2 (treatment2)
(level of vit a against time)
satisfy the hypothesis H0 : β1 = γ1 and β2 = γ2 .
The question is how can I combine the two models into one E(y) = X β with
appropriate design matrix X and coefficient vector β? In this question β is
6x1.
I did it but I think it is not good at all:
vita<-cbind(dt$Vita..y., dt$Time..x.,
dt$Treatment,dt$Vita..y..1,dt$Time..x..1,dt$Treatment.1)
x1 <- cbind(rep(1,28), matrix(0,28,2), vita[,1], matrix(0,28,2))
x11 <- cbind(rep(1,28), matrix(0,28,2), vita[,4], matrix(0,28,2))
x2 <- cbind(rep(0,28), rep(1,28), matrix(0,28,2), vita[,2], rep(0,28))
x22 <- cbind(rep(0,28), rep(1,28), matrix(0,28,2), vita[,5], rep(0,28))
x3 <- cbind(matrix(0,28,2), rep(1,28), matrix(0,28,2), vita[,3])
x33 <- cbind(matrix(0,28,2), rep(1,28), matrix(0,28,2), vita[,6])
x <- rbind(x1, x2, x3,x11, x22, x33) #create the design matrix
ma <-c(vita[,1],vita[,4]) #response values
mma <- data.frame(ma,x) #create the data frame for regression
attach(mma) #attach the data frame to make it available to lm()
ma.lm <- lm(ma ~ -1 + X1 + X2 + X3 + X4 + X5 + X6) #regr model without
#intercept (note the -1 term)
I am sure that is not good, because I should have x^2 and there isn't.
Moreover it gives me an error:
Error in model.frame.default(formula = ma ~ -1 + X1 + X2 + X3 + X4 + X5 + :
variable lengths differ (found for 'X1')
How can I do it?
Tnx
--
View this message in context: http://r.789695.n4.nabble.com/Combining-two-models-into-one-tp4678635.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list