Using normal distribution to approximate t distribution in importance sampling The question is Exercises 6 and 7 regarding importance sampling on page 273 of Bayesian Data Analysis 3 http://www.stat.columbia.edu/~gelman/book/BDA3.pdf.
Exercise 6 approximate a normal distribution with a t distribution ($t_3$) and exercise 7 does the opposite. I do not get why the authors claim that the importance weights are well behaved when you use $t_3$ to approximate normal but they become too variable when you use normal to approximate $t_3$ because based on the output of my R code (attached below), the histogram, the effective sample size (ess) and ESS are similar in these two situations. Can someone see what the authors mean?
My second question is that exercise 7 asks to explain why the estimates of $var(\theta)$ are systematically low. I did observe this from the results. However I can not see the reason.
#BDA3  10.6
S <- 10000
sample <- rt(S,3)

w <- dnorm(sample,sd=sqrt(3))/dt(sample,3)
hist(log(w),xlim = c(-10,10))

mean <- sum(sample*w)/sum(w)

variance <- sum((sample-mean)^2*w)/sum(w)

w_tilda <- w/sum(w)
ess <- 1/(sum(w_tilda^2))
ESS <-  mean( ( w/mean(w) - 1)^2 )

mean;variance;ess;ESS

#BDA3  10.7
S <- 10000
sample <- rnorm(S,sd=sqrt(3))

w <- dt(sample,3)/dnorm(sample,sd=sqrt(3))
hist(log(w),xlim = c(-10,10))

mean <- sum(sample*w)/sum(w)

variance <- sum((sample-mean)^2*w)/sum(w)

w_tilda <- w/sum(w)
ess <- 1/(sum(w_tilda^2))
ESS <-  mean( ( w/mean(w) - 1)^2 )

mean;variance;ess;ESS
```


As a preliminary tip, you should always set the seed when conducting random simulations, to ensure that your work is reproducible.  Also, if you want to compute the log-weights then it is best to do this directly in log-space by computing the densities in this space; this reduces numerical instability and underflow in your results.  Based on correcting the above issues, here is my own (reproducible) importance sampling simulation for Exercise 6 (larger simulation only):
#Draw a sample of size S = 10000 from the approximate density
S <- 10000
set.seed(1)
SAMPLE1 <- rt(S, df = 3)

#Compute the log-weights and log-normalised-weights
LOGW1  <- dnorm(SAMPLE1, mean = 0, sd = sqrt(3), log = TRUE) - 
          dt(SAMPLE1, df = 3, log = TRUE)
LOGNW1 <- LOGW1 - matrixStats::logSumExp(LOGW1)

#Estimate the mean and variance and compute the effective sample size
NW1       <- exp(LOGNW1)
MEAN1     <- sum(NW1*SAMPLE1)
VAR1      <- sum(NW1*(SAMPLE1-MEAN1)^2)
EFF.SIZE1 <- 1/sum(NW1^2)

#Check the estimated mean and variance and the effective sample size
#True mean = 0, True variance = 3
MEAN1
[1] -0.009231501
VAR1
[1] 2.965914
EFF.SIZE1
[1] 8209.784

Now here is an importance sampling simulation for Exercise 7:
#Draw a sample of size S = 10000 from the approximate density
S <- 10000
set.seed(1)
SAMPLE2 <- rnorm(S, mean = 0, sd = sqrt(3))

#Compute the log-weights and log-normalised-weights
LOGW2  <- dt(SAMPLE2, df = 3, log = TRUE) - 
          dnorm(SAMPLE2, mean = 0, sd = sqrt(3), log = TRUE)
LOGNW2 <- LOGW2 - matrixStats::logSumExp(LOGW2)

#Estimate the mean and variance and compute the effective sample size
NW2       <- exp(LOGNW2)
MEAN2     <- sum(NW2*SAMPLE2)
VAR2      <- sum(NW2*(SAMPLE2-MEAN2)^2)
EFF.SIZE2 <- 1/sum(NW2^2)

#Check the estimated mean and variance and the effective sample size
#True mean = 0, True variance = 3
MEAN2
[1] -0.01703927
VAR2
[1] 2.129747
EFF.SIZE2
[1] 8441.093

As you can see from these results, the second case results in a poor estimate of the variance.  We can compare the (normalised) weights by looking at histograms:
#Setup for two plots
par(mfrow = c(1,2))

#Plot histograms of the log-normalised weights
hist(NW1, breaks = 100, col = 'red',
     main = '', xlab = 'Weights (norm/t)', ylab = 'Frequency')
hist(NW2, breaks = 100, col = 'blue',
     main = '', xlab = 'Weights (t/norm)', ylab = 'Frequency')
mtext("Histograms of Weights in Importance Sampling Problems",
      cex = 1.2, font = 2, side = 3, line = -2.4, outer = TRUE)


In assessing the two approximations, you should note the advice that the authors given regarding cases where the approximation is poor:

"The worst possible scenario occurs when the importance ratios
are small with high probability but with a low probability are huge, which happens, for example, if $q$ has wide tails compared to $g$, as a function of $\theta$." (Gelman et al, p. 265)

