0
$\begingroup$

I am trying to construct a regression model in R.I am getting an error while predicting the model. I am not sure if the newdata(which is my validation set) should be a data frame?

data<-read.csv("training.csv")
data<- na.omit(data)
model<-lm(Y ~ X1+X2+...+X10, data=data)
newdata<-read.csv("validation.csv")
predict(model,newdata)

I am new to statistic and was trying to perform bartlett test and leneve test to test for constant variance. I am not sure if this is the right way to do it.

bartlett.test(list(X1,X2,X3..X10),data= data)
levene.test(X1,X2..., X10, location="mean")

It would be great if anyone could help.

$\endgroup$
0

1 Answer 1

2
$\begingroup$

1) Not only should your new data be a data frame, all the x-variables (the columns of the data frame) should have exactly the same names as the original data.

2) you don't specify a sequence of X's by putting ".." between them in R

3) The Bartlett and Levene (NOT Leneve) tests are for comparing variances of conditional y's, not x's. You need grouping variables for those tests, and to my knowledge levene.test is not in vanilla R.

levene.test presumably in some package; you should state which one you're using. There's discussion of one here, which suggests it may be in some package loaded by Rcmdr (or one you can use with it). The package car has leveneTest.

Edit: the packages lawstat and s20x have levene.test functions, and it's also a deprecated function in car

$\endgroup$
2
  • $\begingroup$ I am little confused about using bartlett test. We use it in comparing the variances of Y. In my case I only have one target variable and 16 input variable. So how does it work. It would be great if you could help. $\endgroup$ Commented Sep 15, 2014 at 4:25
  • $\begingroup$ I've responded to that already in my answer ("you need grouping variables for those tests"). The Bartlett test is explicitly for comparing variances of groups. If your "16 variables" don't divide the data into a (moderate) number of mutually exclusive groups each of which has a large enough sample size to estimate a variance (and you don't have some other obvious way of dividing your residuals up into groups), you probably don't want to use the Bartlett test. $\endgroup$
    – Glen_b
    Commented Sep 15, 2014 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.