Creating own boxcox code

I'm attempting to create my own function that uses the box cox transformation and returns all values of lambda in which the new data is normally distributed. Not sure where I have gone wrong. This is my code:
boxtran<-function(x){
lambda=seq(-5,5,1/10)
for(i in lambda) {
if (i!=0){
y<-(x^i-1)/i
}
if (i==0){
y<-log(x)
}
p<-ad.test(y)$p.value

}
q[p<=0.05]

for (seq(min(q),max(q))){
return(i)
}
}
}

Hi, and welcome!

Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers.

For your question, it would be particularly helpful due to a syntax error as posted. Also, what argument x is the function intended to take?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.