0

I am using a for loop to perform repeatability analysis on subsets of my data. I am struggling to find a function that will store the results of my for loop in a data frame, because the repeatability analysis output gives R, Standard Error, Confidence Interval, and p-values. I would like to only store R and CI values.

Here is my code:

p<-10000 for(i in 1:P){ newdf<-df[df$ID %in% sample(unique(df$ID), 16), ] m1<-rpt(Behaviour~Temperature+(1|ID),grname="ID",data=newdf,datatype="Gaussian",nboot=1000,npermut=1000) } 

Can anyone help?

1 Answer 1

1

You can create a numeric vector to store R and CI values :

p<-10000 R_value <- numeric(length = p) CI_value <- numeric(length = p) for(i in 1:P) { newdf<-df[df$ID %in% sample(unique(df$ID), 16), ] m1<- rptR::rpt(Behaviour~Temperature+(1|ID),grname="ID",data=newdf, datatype="Gaussian",nboot=1000,npermut=1000) R_value[i] <- m1$R CI_value[i] <- m1$CI } 
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Ronak, but unfortunately the R_value and CI_value are just returning a string of 0's! Any suggestions?
Did you run the loop? When we initialise R_value and CI_value, they are initialised to 0 but after running the loop there should be some value.
I ran the loop, and then called R_value() and CI_value() afterwards as no values appeared after running the loop..
You should do R_value and CI_value. () is used for functions. It seems to work with example shared in ?rpt page. If it doesn't work for your data, can you share your data?
It seems that this works when I run the repeatability analysis outside of the for loop, but 0's are still generated when I use the for loop. Any suggestions on where I might me going wrong with the loop?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.