I am trying to run the following code in R markdown only to print the code. I do not want to print the results from R code. Some of the lines in code are really large. When I run, it worked perfectly, but some of the lines go outside of the page? Here is the R markdown code
title: R code
output:
pdf_document:
toc: true
number_sections: true
documentclass: article
classoption:
- portrait
- a4paper
---
```{r,eval=F,echo=TRUE}
hrs_data_GS$rSLn==i,\]%*%beta\[k,\])^2/2*sigma2)+
sum(z_ij_str\[i\]*xdata\[hrs_data_GS$rSLn==i,\]%*%alpha\[k,\])-
0.5*sum(w_ij\[hrs_data_GS$rSLn==i\]*(xdata\[hrs_data_GS$rSLn==i,\]%*%alpha\[k,\])^2)+
( (lamda/sigma2)*sum(hrs_data_GS$y_ij\[hrs_data_GS$z_ij==1 & hrs_data_GS$rSLn==i\]-
xdata\[hrs_data_GS$z_ij==1 & hrs_data_GS$rSLn==i,\]%*%beta\[k,\])
+sum_z_ij_str\[i\]- sum(w_ij\[hrs_data_GS$rSLn==i\]*
xdata\[hrs_data_GS$rSLn==i,\]%*%alpha\[k,\]))^2*
2*((n_i\[i\]*lamda^2/sigma2)+sum_w_ij_j\[i\]+1/sig2.theta)^-1)+
(log(pi_cls\[i,k\])) #(log(pi_k\[k\]))
}
}
nume_prod<-nume_prod-apply(nume_prod,1,max) #it works
nume_prod <- exp(nume_prod)
prob_cls_rsum=apply(nume_prod, 1, sum)
prob_cls=nume_prod/ prob_cls_rsum
#cls=miscF::rMultinom(p=cbind(prob_cls)) #miscF is not available at CRC
cls=Hmisc::rMultinom(p=cbind(prob_cls),1)
#Update sum_y.ij_j and sum_wxa_ij_j before updating the theta
#these values involve 'cls'
#******
for (i in 1:m){
#1**********
sum_y.ij_j\[i\]<-(lamda/sigma2)*sum((hrs_data_GS$y_ij\[hrs_data_GS$z_ij==1 & hrs_data_GS$rSLn==i\]-
xdata\[hrs_data_GS$z_ij==1 & hrs_data_GS$rSLn==i,\]%*%beta\[cls\[i\],\])
) #conditioning on z_ij==1
#2******
sum_wxa_ij_j\[i\]<-sum((w_ij\[hrs_data_GS$rSLn==i\]*
xdata\[hrs_data_GS$rSLn==i,\]%*%
alpha\[cls\[i\],\])
)
}
#Update theta_i
theta_i=rnorm(m, #number of thetas
(sum_z_ij_str-sum_wxa_ij_j+sum_y.ij_j)*
(((1/sig2.theta)+sum_w_ij_j+((lamda^2/sigma2)*n_i_z1))^-1), #mean
sqrt((((1/sig2.theta)+sum_w_ij_j+((lamda^2/sigma2)*n_i_z1))^-1)) #std
```
I would like to keep all the codes inside the page. Is there any way I do it for all chunk?
