r - Drawing a quadratic function in mixed effect model -


it's bit of long question bearing me.

here's data

https://www.dropbox.com/s/jo22d68a8vxwg63/data.csv?dl=0

i constructed mixed effect model

library(lme4) mod <- lmer(sqrt(y) ~ x1 + i(x1^2) + x2 + i(x2^2) + x3 + i(x3^2) + x4 + i(x4^2) + x5 + i(x5^2) +        x6 + i(x6^2) + x7 + i(x7^2) + x8 +  i(x8^2) + (1|loc) + (1|year), data = data) 

all predictors standardised , interested in knowing how y changes changes in x5while keeping other variables @ mean values (equal 0 since variables standardised).

this how it.

# make predictors except x5 equal 0   data$x1<-0 data$x2<-0 data$x3<-0 data$x4<-0 data$x6<-0 data$x7<-0 data$x8<-0  # use predict function   library(mertools) fitted <- predictinterval(mermod = mod, newdata = data, level = 0.95, n.sims = 1000,stat = "median",include.resid.var = true) 

now want plot fitted quadratic function of x5. this:

i<-order(data$x5)    plot(data$x5[i],fitted$fit[i],type="l") 

i expected produce plot of y quadratic function of x5. can see, following plot not have quadratic curve. can tell me doing wrong here?

this get

i'm not sure predictinterval comes from, can predict. trick make sure set random effects 0. here's how can that

newdata <- data newdata[,paste0("x", setdiff(1:8,5))] <- 0 y <- predict(mod, newdata=newdata, re.form=na) plot(data$x5, y) 

the re.form=na part drops out random effect

enter image description here


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -