转换为pdf时出现latex问题

转换为pdf时出现latex问题
\documentclass[a4paper,11pt]{article}
\usepackage{graphicx}
\usepackage{a4wide}
\usepackage[colorlinks,linkcolor=blue,citecolor=red]{hyperref}
\usepackage{natbib}

\usepackage{float}
\floatstyle{ruled}
\restylefloat{table}
\restylefloat{figure}
\newcommand{\floatintro}[1]
{
 \vspace*{0.15in}
 {\footnotesize
   #1
 }
  \vspace*{0.15in}
}
\renewcommand{\topfraction}{0.9}    % max fraction of floats at top
    \renewcommand{\bottomfraction}{0.8} % max fraction of floats at bottom
    %   Parameters for TEXT pages (not float pages):
    \setcounter{topnumber}{2}
    \setcounter{bottomnumber}{2}
    \setcounter{totalnumber}{4}     % 2 may work better
    \setcounter{dbltopnumber}{2}    % for 2-column pages
    \renewcommand{\dbltopfraction}{0.9} % fit big float above 2-col. text
    \renewcommand{\textfraction}{0.07}  % allow minimal text w. figs
    %   Parameters for FLOAT pages (not text pages):
    \renewcommand{\floatpagefraction}{0.7}  % require fuller float pages
    % N.B.: floatpagefraction MUST be less than topfraction !!
    \renewcommand{\dblfloatpagefraction}{0.7}   % require fuller float pages
\title{Technical note on seasonal adjustment \\for\\ Gross Domestic Product-fc\\ (constant prices 2004-05)}
\author{~}
    \begin{document}
    \maketitle

\tableofcontents
\listoffigures
\listoftables

\newpage

\SweaveOpts{engine=R,eps=FALSE,results=hide,echo=FALSE}
\section{Full sample: Starting from 1999, April}

\subsection{Pre adjustment analysis}

\section{Gross domestic product}
We analyse the quarterly data for Gross domestic product from the 1st quarter of the fiscal year 1996-97. Figure \ref{key} shows the original plot of the series. It shows seasonal pattern. In such a non-seasonally adjusted series, it is difficult to discern a trend as the seasonal variations may mask the important characteristics of a time series.

<<Reading in the data and plotting>>= 

source("../../LIBRARY/BCMlib.R")
library(zoo)
library(reshape2)

setwd("../../../../../../../")
source("SRC/data.R")
bb <- getMainData("ABD")
bb.metadata <- getMetadata("ABD")
## b99 <-  as.data.frame(bb[grep("ABD00137",bb$mapcode),])
## b99$mapcode <- bb.metadata[which(bb.metadata$MapCode %in% b99$mapcode),"SeriesName"]
## colnames(b99)[ncol(b99)] <- b99[1,1]
## b99 <- b99[,-1]
## b99$timestamp <- as.Date(as.character(b99$timestamp,"%Y-%m-%d"))
gdp.old.series <- read.csv("./MASTERDATA/ACT/RESOURCES/gdp_old_fc_const.csv",skip=2)
gdp.old.series <- gdp.old.series[,c(-1,-2)]
gdp.old.series <- gdp.old.series[-nrow(gdp.old.series),]
gdp.old.series$year <- paste(substr(gdp.old.series$Industry..Year,1,4))

for(i in 1:nrow(gdp.old.series)){
  if (gdp.old.series$year[i] ==""){
    gdp.old.series$year[i]<-gdp.old.series$year[i-1]
  }
}

#gdp.old.series$year <- as.Date(as.character(
gdp.old.series$year <- as.Date(as.yearmon(as.Date(paste(as.yearmon(as.yearqtr(paste(gdp.old.series$year,gdp.old.series$X))),"01"),format="%b %Y %d"))+5/12)
gdp.old.series$Industry..Year <- gdp.old.series$X <- NULL
gdp.old.series <- zoo(gdp.old.series[,-ncol(gdp.old.series)],gdp.old.series[,ncol(gdp.old.series)])
old.base.series <- gdp.old.series$Gross.Domestic.Product.at.factor.cost * 1000

## setwd("../../../../../../../")
## source("SRC/data.R")
## bb <- getMainData("ABD")
## bb.metadata <- getMetadata("ABD")
## b99 <-  as.data.frame(bb[grep("ABD00136",bb$mapcode),])
## b99$mapcode <- bb.metadata[which(bb.metadata$MapCode %in% b99$mapcode),"SeriesName"]
## colnames(b99)[ncol(b99)] <- b99[1,1]
## b99 <- b99[,-1]
## b99$timestamp <- as.Date(as.character(b99$timestamp,"%Y-%m-%d"))
## old.base.series <- zoo(b99[,-1],b99[,1])

b05 <-  as.data.frame(bb[grep("ABD00215",bb$mapcode),])
b05$mapcode <- bb.metadata[which(bb.metadata$MapCode %in% b05$mapcode),"SeriesName"]
colnames(b05)[ncol(b05)] <- b05[1,1]
b05 <- b05[,-1]
b05$timestamp <- as.Date(as.character(b05$timestamp,"%Y-%m-%d"))
new.base.series <- zoo(b05[,-1],b05[,1])
index(new.base.series) <- as.yearmon(index(new.base.series))
index(new.base.series) <- as.Date(paste("01", index(new.base.series), sep = " "),"%d %b %Y")

# add an intermediate step here to convert the series into a growth series 
tmp <- merge(old.base.series,new.base.series ,all=TRUE)

chainlink <- function(tmp) {
  link <- function(old.series,new.series) {
                                        # Making one dataset with both series
    tmp1 <- merge(old.series,new.series ,all=TRUE)
    start <- complete.cases(tmp1)
    link.date <- index(tmp1)[start][1]
    cat("The first overlapping period is:", as.character(link.date), "\n")
    cutoff <- window(old.series,end=index(old.series)[as.numeric(which(index(old.series)==link.date))-1])
    link.factor <- new.series[link.date,]/old.series[link.date,]
    cutoff <- cutoff * coredata(link.factor)
    final <- rbind(cutoff,window(new.series ,start=link.date))
    final
  }
  if (NCOL(tmp) > 2) {
    cat("There are more than two series that require base year linking. Proceeding to chain link recursively.\n")
    k <- NULL
    for (i in 1:(ncol(tmp)-1)) {
      cat("Linking:",i,"\n")
      if (i==1) {
        k <- link(old.series=tmp[,i],new.series=tmp[,i+1])
      } else {
        k <- link(old.series=k,new.series=tmp[,i+1])
      }
    }
  } else {
    k <- link(old.series=tmp[,1],new.series=tmp[,2])
  }
  return(k)
}

b <- chainlink(tmp)

## start <- complete.cases(tmp)
## link.date <- index(tmp)[start][1]
##  s1 <- as.numeric(old.base.series[which(index(old.base.series)==link.date)])
##  s2 <- as.numeric(new.base.series [which(index(new.base.series )==link.date)])
##  cutoff <- window(old.base.series,end=index(old.base.series)[as.numeric(which(index(old.base.series)==link.date))-1])
##  link.factor <- s2/s1
##  cutoff <- cutoff*(link.factor)
##  b<- round(rbind(cutoff,window(new.base.series ,start=link.date)),2)
## b<-window(b,start=as.Date("1999-06-30"))
## index(b) <- as.yearmon(index(b))
## b[which(b==0)] <- NA
## b <- na.approx(b)
## index(b) <- as.Date(paste("01", index(b), sep= " "), "%d %b %Y")

c <- ts(b,freq=4,start=c(1996,2))
setwd("MASTERDATA/ACT/RESOURCES/sa/SAfactory/ANNUAL/quarter")
@

<<gdp-activity-original-plot, width=7, height=6, fig=TRUE>>=
b <- b/100
plot(b, xlab="",ylab="Million")
@


\subsection{Additive versus multiplicative seasonality}
X-12-ARIMA has the capability to determine the mode of the seasonal adjustment decomposition to be performed i.e whether multiplicative or additive seasonal adjustment decomposition is appropriate for the series. For Gross domestic product, multiplicative seasonal adjustment is considered appropriate on the basis of the model selection criteria.\\

\section{Steps in the seasonal adjustment procedure}
Given that seasonality exists, it is important to model seasonality before the application of seasonal adjustment procedure. Seasonality in time series can be deterministic or stochastic. Stochastic seasonality can be stationary or non-stationary.\\
\\
A visually appealing way of looking at the raw data is to plot the growth rates in each of the quarters across the years i.e the growth of 2nd quarter (July-September) over 1st quarter (April-June) in each of the years from the fiscal year 1999 onwards. This gives us some idea of the presence of seasonal peaks, if any in the series.\\ The nature of seasonality can also be inferred intutively from the plot before the application of the testing procedures.


\begin{figure}[H]
\begin{center}
<<LevelsNSA2,fig=TRUE>>=
 nsa.plot(b,ylab="Rs. Crore")
@ 
 \caption{Non seasonally adjusted}
\end{center}
\end{figure}


\begin{figure}[H]
\begin{center}
<<Plotperiod2, fig=TRUE>>=
 period(pop(c))
@ 
 \caption{Period plot}
\end{center}
\end{figure}

Figure \ref{quarterly} shows that mean growth rate in quarter 3 (October-December) is higher than the growth rate in other quarters.




\newpage
\subsection{Seasonal adjustment with X-12-ARIMA}
Seasonal adjustment is done with X-12-ARIMA method. 
<<seasonal adjustment with x12arima,echo=FALSE,results=hide>>=
source("../../../SRC/x12arima.R")
res.gdp.activity <- x12arima(c,
                    more="regression{variables=(const)}",
                    transform="transform{function=log}",
                    outlier="outlier{types=all method=addone}",
                    type="mult", delete=TRUE)
@


<<NSA-SA-plot>>=
GDP_activity_sa <- res.gdp.activity$SeasAdj
df <- data.frame(dates=seq(as.Date("1999-06-01"), by='3 month',length.out=length(c)), c, GDP_activity_sa)
print(ggplot(df, aes(dates)) + geom_line(aes(y=b[, colour="GDP-NSA")) + geom_line(aes(y=GDP_activity_sa, colour="GDP-SA"))+scale_colour_manual(name="",values=c("GDP-NSA"="blue","GDP-SA"="red"))+opts(legend.position=c(.3,.9))+labs(x=NULL,y="Gross domestic product (Rs billion)"))

@



\begin{figure}[H]
\begin{center}
<<Levels NSA,fig=TRUE>>=
 nsa.plot(b,ylab="Rs. Crore")
@ 
 \caption{Non seasonally adjusted}
\end{center}
\end{figure}



\subsection{X-12-ARIMA run on the series}
Seasonal adjustment is done with X-12-ARIMA method.
<<>>=
x12output <-x12arima(b,
                          more="regression{variables=(const)}",
                          transform="transform{function=log}",
                          outlier="outlier{types=all method=addone}",
                          type="mult", delete=FALSE)

x12output$ModelChoice
mc <- x12output$ModelChoice[length(x12output$ModelChoice)]
model.choice2<-paste("arima{model =",substr(mc,34,47),"}",sep="")
model.type.mining2<-data.frame(matrix(NA,ncol=4,nrow=1))
colnames(model.type.mining2)<-c("Series","Model","RegType","Add/Mult")
 more2="regression{variables=(const)}"
type2="mult"
model.type.mining2[1,1]<-c("gdp.fc.const.2004-05.sa.quarterly")
model.type.mining2[1,2]<-model.choice2
model.type.mining2[1,3]<-more2
model.type.mining2[1,4]<-type2
#save(model.type.mining,file="alltype.rda")
@ 

<<model-type-table, results=tex>>=
print(xtable(model.type.mining2,caption="Model type"), include.rownames=FALSE,table.placement = "H",caption.placement="top",caption="Model type")
@ 
\begin{figure}[htp]
\begin{center}
 \includegraphics[width=0.7\linewidth]{../DOC/GEN/NSA_SA_GDP_activity.pdf}
 \caption{Gross domestic product (NSA and SA)}\label{figure}
\end{center}
\end{figure}

Figure \ref{figure} shows the non-seasonally and seasonally adjusted Gross domestic product. The seasonal peaks are dampened after seasonal adjustment.



\subsection{X-12-ARIMA diagnostics}
After seasonal adjustment, a series of diagnostic checks are performed through relevant tests and quality assessment statistics.
\subsubsection{Validation of the automodel choice by X-12-ARIMA}
A test of validation of the auto model choice by X-12-ARIMA is the randomness of the residuals of the ARIMA model. 
The Ljung-Box test is conducted on the residuals of the fitted ARIMA model to check whether or not the residuals are white noise. The ACFs of the residuals are plotted to check for randomness.
<<x12arimaDiagnostics,results=tex>>=
print(xtable(x12aDiag(x12output),caption="X-12-arima diagnostics"))
@ 
<<echo=FALSE,results=hide>>=
source("../SRC/x12arima.R")
res.gdp.activity <- x12arima(q[,"GDP_constant"],
                    more="regression{variables=(const)}",
                    transform="transform{function=log}",
                    outlier="outlier{types=all method=addone}",
                    type="mult", delete=TRUE)
GDP_activity.residuals<-res.gdp.activity$Residual
acf(GDP_activity.residuals,na.action=na.pass, main="GDP")
Box.test(GDP_activity.residuals,type=c("Ljung-Box"),lag=16) #$
@
<<acf-residuals-plot>>=

plot(acf(GDP_activity.residuals,na.action=na.pass))
)
@
<<x12arimaDiagnostics,results=tex>>=
print(xtable(x12aDiag(x12output),caption="X-12-arima diagnostics"))
@ 


\begin{figure}[H]
  \begin{center}
<<acfplots2,fig=TRUE>>=
acf.plot(x12output)
@ 
\end{center}
\end{figure}

\begin{figure}[H]
\caption{Spectral plot}
  \begin{center}
<<spectralplots1,fig=TRUE>>=
nsa2 <- b
sa2 <- x12output$SeasAdj
spectral.plot(sa2,nsa2)
@ 
\end{center}
\end{figure}
\emph {Figure \ref{res} does not reveal significant autocorrelation amongst the residuals.}


\subsection{Performance analysis}
\begin{figure}[H]
\caption{NSA and outlier unadjusted SA plot}
  \begin{center}
<<outlierunadjusted2,fig=TRUE>>=
un.sa2 <- x12output$USeasAdj
outlier.unadjusted(nsa2,un.sa2,ylab="Rs. Crore")
@ 
\end{center}
\end{figure}

\begin{figure}[H]
\caption{NSA and outlier adjusted SA plot}
  \begin{center}
<<outlieradjusted2,fig=TRUE>>=
sa2 <- x12output$SeasAdj
outlier.adjusted(nsa2,sa2,ylab="Rs. Crore")
@ 
\end{center}
\end{figure}

\begin{figure}[H]
\caption{Error}
  \begin{center}    
<<error2,fig=TRUE>>=
error(out.adj=sa2,out.unadj=un.sa2)
@ 
\caption{Absolute percentage difference between outlier adjusted and unadjusted series}
\end{center}
\end{figure}

<<table-sds, results=tex>>=
print(xtable(sd.table(nsa2,sa2,out.unadj=un.sa2),caption="Standard deviation of growth rates"),include.rownames=FALSE,table.placement = "H",caption.placement="top")

load("../allmodels.rda")
final.models <- data.frame("Series"=c("gdp.fc.const.2004-05.sa.quarterly"),
                           "Model"=c(model.choice2),
                           "RegType"=c(more2),
                           "Add/Mult"=c(type2),
                           "SA/NSA"=c("SA"),
                           "FS/SS"=c("SS"))
colnames(final.models)[4:6] <- c("Add/Mult","SA/NSA","FS/SS")
allmodels <- rbind(allmodels,final.models)
save(allmodels,file="../allmodels.rda")

@ 
\end{document}

我有一个这样的文档。但是当我将此 LaTeX 文档转换为 PDF 时,出现以下错误:

LaTeX Warning: Reference `key' on page 2 undefined on input line 50.

<test_rajib_gdp-gdp-activity-original-plot.pdf, id=16, 505.89pt x 433.62pt>
<use test_rajib_gdp-gdp-activity-original-plot.pdf>
Underfull \hbox (badness 10000) in paragraph at lines 57--58


Underfull \hbox (badness 10000) in paragraph at lines 60--63

[2 <./test_rajib_gdp-gdp-activity-original-plot.pdf>]
<test_rajib_gdp-LevelsNSA2.pdf, id=32, 433.62pt x 433.62pt>
<use test_rajib_gdp-LevelsNSA2.pdf>
<test_rajib_gdp-Plotperiod2.pdf, id=33, 433.62pt x 433.62pt>
<use test_rajib_gdp-Plotperiod2.pdf> [3 <./test_rajib_gdp-LevelsNSA2.pdf>]

LaTeX Warning: Reference `quarterly' on page 4 undefined on input line 80.

[4 <./test_rajib_gdp-Plotperiod2.pdf>])

有什么问题?请给我一个解决方案。

相关内容