\documentclass[11pt,a4paper]{report}
\usepackage{amsthm,amssymb,amsmath}
\usepackage[top=30mm, bottom=30mm, left=20mm, right=25mm]{geometry}
\usepackage{zref-perpage}
\usepackage{graphicx}
% بسته‌ و دستوراتی برای ایجاد لینک‌های رنگی با امکان جهش 
\usepackage[pagebackref=true,colorlinks,linkcolor=black,citecolor=magenta]{hyperref}
% چنانچه قصد پرینت گرفتن نوشته خود را دارید، خط بالا را غیرفعال و  از دستور زیر استفاده کنید چون در صورت استفاده از دستور زیر‌‌، 
% لینک‌ها به رنگ سیاه ظاهر خواهند شد و برای پرینت گرفتن، مناسب‌تر است
%\usepackage[pagebackref=false]{hyperref}
% بسته‌ای برای ظاهر شدن «مراجع» و« نمایه» در فهرست مطالب
\usepackage{tocbibind}
\usepackage{makeidx}
% دستورات مربوط به ایجاد نمایه
\makeindex
%%%%%%%%%%%%%%%%%%%%%%%%%%
% فراخوانی بسته زی‌پرشین و دستورات مربوط به نوع فونت‌ها
\usepackage[usenames,dvipsnames]{color,xcolor}
\usepackage{listings}
\usepackage{hyperref}
\usepackage{xepersian}
\settextfont[Scale=1.1]{XB Niloofar}
\setcounter{chapter}{3}
\setcounter{section}{0}
\setcounter{equation}{0}
\pagenumbering{arabic}
%\setlatintextfont[Scale=2]{Linux Libertine}
\setlatintextfont[Scale=1]{Times New Roman}
% از revision 118 زی‌پرشین به بعد، وارد کردن دستور زیر لازم نیست. توجه داشته باشید که در صورت  غیرفعال کردن این دستور،
% از فونت پیش‌فرض لاتک برای کلمات انگلیسی استفاده خواهد شد.
%\setlatintextfont[ExternalLocation,BoldFont={lmroman10-bold},BoldItalicFont={lmroman10-bolditalic},ItalicFont={lmroman10-italic}]{lmroman10-regular}
% چنانچه می‌خواهید اعداد در فرمول‌ها، فارسی باشد، خط زیر را نیز فعال کنید
\setdigitfont[Scale=.85]{Yas}
%%%%%%%%%%%%%%%%%%%%%%%%%%
% تعریف قلم‌های فارسی و انگلیسی برای استفاده در بعضی از قسمت‌های متن
\defpersianfont\titr[Scale=1]{XB Titre}
%\defpersianfont\traffic[Scale=1]{B traffic}
% چنانچه فونت B Traffic را ندارید، دستور بالا را غیرفعال کرده و دستور زیر را فعال کنید
\defpersianfont\traffic[Scale=1]{XB Niloofar}
%%%%%%%%%%%%%%%%%%%%%%%%%%
%تعریف و نحوه ظاهر شدن عنوان قضیه‌ها، تعریف‌ها، مثال‌ها و ...
\theoremstyle{definition}
\newtheorem{definition}{تعریف}[section]
\newtheorem{theorem}{قضیه}[section]
\newtheorem{lemma}{لم}[section]
\newtheorem{proposition}{گزاره}[section]
\newtheorem{corollary}{نتیجه}[section]
\newtheorem{remark}{ملاحظه}[section]
\theoremstyle{definition}
\newtheorem{example}{مثال}[section]
%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter 
\renewcommand{\@makefntext}[1]{\parindent 1em
    \noindent\hbox to 2em{}% if you want to indent footnote text you can change the width of the hbox (e.g. \hbox to 2em{})
    \llap{\if@RTL\else\latinfont\fi\@thefnmark)\,\,}#1}
\def\LTRfootnote{\@ifnextchar[\@xLTRfootnote{\stepcounter\@mpfn
        \protected@xdef\@thefnmark{\if@Latin\latinfont\fi\thempfn}%
        \@footnotemark\@LTRfootnotetext}}
\makeatother
% تعریف دستورات جدید برای خلاصه نویسی و راحتی کار در هنگام تایپ فرمول‌های ریاضی
\newcommand{\bR}{\mathbb{R}}
\newcommand{\bx}{\mathbf{x}}
\newcommand{\cB}{\mathcal{B}}
\newcommand{\cO}{\mathcal{O}}
\newcommand{\cG}{\mathcal{G}}
\newcommand{\cF}{\mathcal{F}}
\newcommand{\cX}{\mathcal{X}}
\newcommand{\rM}{\mathrm{M}}
\newcommand{\rC}{\mathrm{C}}
\newcommand{\rV}{\mathrm{V}}
\newcommand{\de}{\mathrm{d}}
\newcommand{\Xt}{\mathop{X}\limits_{\widetilde{}}}
\newcommand{\Yt}{\mathop{Y}\limits_{\widetilde{}}}
\newcommand{\xt}{\mathop{x}\limits_{\widetilde{}}}
\newcommand{\yt}{\mathop{y}\limits_{\widetilde{}}}
\newcommand{\Tt}{\mathop{T}\limits_{\widetilde{}}}
\newcommand{\RNum}[1]{\uppercase\expandafter{\romannumeral #1\relax}}
%%%%%%%%%%%%%%%%%%%%%%%%%%
% تغییر نام کلمه «اثبات» به «برهان»
\renewcommand\proofname{\textbf{برهان}}
\renewcommand{\qedsymbol}{}
%\renewcommand{\qedsymbol}{\rule{0.5em}{0.5em}}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\zmakeperpage[1]{footnote}   
%\@bidi@removefromreset{footnote}{chapter}
\title{مباحث تکمیلی استنباط آماری پیشرفته}
%\author{ابوذر همتی، عبدالرسول ضیایی}
\date{}
\begin{document}
\baselineskip=1.15cm
%\maketitle
سلام
\begin{latin}
\begin{lstlisting}[language=R]
> ## implement log-likelihood
> loglik <- function(alpha,       # parameter for first-order term
+                    x)           # observed data vector
+  {
+        i <- 2:length(x)
+        - 1/2 * sum((x[i] - alpha * x[i-1])^2)
+   }
> ## and plot for the given data
> x <- c(-0.560, -0.510, 1.304, 0.722, 0.490, 1.960, 1.441)
> alpha <- seq(-1, 2, length = 100)
> plot(x=alpha,
+      y=sapply(alpha, function(alpha) loglik(alpha, x)),
+      type = "l",
+      xlab = expression(alpha),
+      ylab = expression(l(alpha)))
> ## then calculate the MLE and plot it
> i <- seq(along=x)[-1]       #again an indexing vector is necessary 
> alphaMl <- sum(x[i] * x[i-1]) / sum(x[i-1]^2)
> alphaMl
[1] 0.6835131
> abline(v = alphaMl, lty = 2)
\end{lstlisting}
\end{latin}
\begin{latin}
\begin{lstlisting}[language=R]
> ## likelihood for location parameter of
> ## cauchy in random sample
> likelihood <- function(theta,           # location parameter
+                        x)               # observed data vector
+ {
+    1/pi^3 / prod((1+(x-theta)^2))
+  }
> ## In order to plot the likelihood, the function must be able
> ## to take not only one theta value but a theta vector.
> ## we can use the vectorized likelihood function
> likelihoodvec <- Vectorize(likelihood,
+                            vectorize.args="theta")
> x <- c(0,5,9)
> theta <- seq(from=-5, to=15,
+              length = 1000)
> plot(theta,likelihoodvec(theta,x=x),
+      type="l",
+      xlab = expression(theta),
+      ylab = expression(L(theta)))
\end{lstlisting}
\end{latin}
\end{document}