I am new to R. I would like to use a permutation test to see a relationship between y and x1. In this case, I want y is fixed, whereas x1 is permuted and the other regressor, x2, is constant. Because I have a longitudinal dataset and my dependent variable, y, is count data, I use a fixed-effect

I run the following code

setwd("D:/trial")
getwd()

trial <- read.csv("trial.csv")

b <- c()
r <- c()

data = trial[,c(-1,-6)]
for(i in 1:500){
    data$x1 <- sample(data$x1)
    placebo <- glm(y ~ data$x1 + x2+ as.factor(code) + as.factor(year), 
    data=data, family=poisson)
    b <- append(b, placebo$coef[4])
    r <- append(r,cor(data$x1, data$y))
    coef(summary(placebo))
}
hist(b)

and got an error message as:

Error in eval(predvars, data, env) : object 'x2' not found hist(b) Error in hist.default(b) : 'x' must be numeric

Can anyone help me to solve this problem?

1 Answers

0
Community On

I'm not sure about that but maybe you should replace x2 by data$x2 and then convert your b to a numeric value like this :

hist(as.numeric(b))