[R] R Help

Yadavalli, Anita P ayadaval at purdue.edu
Sun Mar 27 18:23:57 CEST 2011


Hi, 

Creating the X'y vector has been troublesome. I get the error: requires numeric/complex matrix/vector arguments. Could you please look at my code and tell me what I am doing wrong? I have several dummy variables among my independent variables. 


#Variable MHL16, or that corresponding to whether the school social worker is required to be licensed or certified by a state agency or board, is coded as dependent variable

y1 <- subset(dat, select=c(MHL16))
y <- as.matrix(y1[1:873,])

summary(y)
y

#Create independent variable vectors

x02 <- subset(dat, select=c(sampstra))

x03 <- subset(dat, select=c(size)) 
x03.dummy <- subset(x03=="2") #where True=large size and False=small size
dim(x03.dummy)

x04 <- subset(dat, select=c(level))
x05 <- subset(dat, select=c(ENROLL))

x06 <- subset(dat, select=c(URBAN))
x06.dummy <- subset(x06=="1") #where True=urban and False=non-urban or NA

x07 <- subset(dat, select=c(REGION))

x08 <- subset(dat, select=c(POVERTY))
x08.dummy <- subset(x08=="2") #where True=high poverty and False=low proverty or NA
x08.dummy
dim(x08.dummy)

x09 <- subset(dat, select=c(MHL12)) #is there a PT/FT school social worker who provides mental health/social services to students
x09.dummy <- subset(x09=="1") #where True=yes and False=no
dim(x09.dummy)

x010 <- subset(dat, select=c(MHL13)) #how many PT/FT school social workers provides services
x011 <- subset(dat, select=c(MHL15)) #what is the minimum level of education required for newly hired school social worker

x012 <- subset(dat, select=c(MHL27c_03)) #does the school social worker provide services for pregnancy prevention
x012.dummy <- subset(x012=="1") #where True=yes, False=no

x013 <- subset(dat, select=c(MHL27d_03)) #does the school social worker provide services for HIV prevention
x013.dummy <- subset(x013=="1") #where True=yes, False=no


x2 <- as.matrix(x02[1:843,])
x3 <- as.matrix(x03.dummy[1:843,])
x4 <- as.matrix(x04[1:843,])
x5 <- as.matrix(x05[1:843,])
x6 <- as.matrix(x06.dummy[1:843,])
x7 <- as.matrix(x07[1:843,])
x8 <- as.matrix(x08.dummy[1:843,])
x9 <- as.matrix(x09.dummy[1:843,])
x10 <- as.matrix(x010[1:843,])
x11 <- as.matrix(x011[1:843,])
x12 <- as.matrix(x012.dummy[1:843,])
x13 <- as.matrix(x013.dummy[1:843,])

#Create X matrix

X <- cbind(1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13)
dim(X)

> Xty <- t(X)%*%y
Error in t(X) %*% y : requires numeric/complex matrix/vector arguments

Thanks!



More information about the R-help mailing list