[R] rv package, rvnorm function
John P. Burkett
burkett at uri.edu
Tue Aug 21 00:49:10 CEST 2007
In an attempt to learn to use the rv package, I have been working
through the examples in Jouni Kerman and Andrew Gelman's "Using Random
Variables to Manipulate and Summarize Simulations in R" (July 4, 2007).
I am using a Dell Precision 380n computer running Gentoo Linux and R
2.2.1 (the latest available through Gentoo's portage/emerge system).
Everything worked well until I tried the following command (found on p.
2 of the document):
beta <- rvnorm(mean=beta.hat, var=V.beta*sigma^2)
That command produced the following error message:
Error in .rvmvnorm(n = n, mean = mean, Sigma = var) :
Invalid (non-numeric) covariance matrix Sigma
Any suggestions for interpreting the error message or correcting the
problem would be much appreciated.
Pasted below, in case it is useful, is my R file:
****R file begins here **************************
# This is a file of R commands to test Kerman and Gelman's package rv.
# It is based on their "Using Random Variables to Manipulate and
# Summarize Simulations in R,", July 4, 2007.
testscores <- read.table("rv_data.txt",header=TRUE) # Extract data.
attach(testscores) # Put testscores in R search path
testscores[1:2,] # Print first 2 observations
testscores[14:15,] # Print last 2 observations
x <- testscores[,1] # midterm scores
y <- testscores[,2] # final exam scores
testlm <- lm(y ~ x) # fit linear model by OLS
sigma.hat <- sqrt(deviance(testlm)/df.residual(testlm))
# deviance(testlm) is equivalent to sum(residuals(testlm)^2)
beta.hat <- coefficients(testlm)
V.beta <- vcov(testlm)/(sigma.hat^2) # unscaled covariance matrix
n <- 10
library(rv)
sigma <- sigma.hat*sqrt((n-2)/rvchisq(df=n-2)) # default number of
simulations
# is 1000
beta <- rvnorm(mean=beta.hat, var=V.beta*sigma^2)
****R file ends here *********************
Best regards,
John
--
John P. Burkett
Department of Environmental and Natural Resource Economics
and Department of Economics
University of Rhode Island
Kingston, RI 02881-0808
USA
phone (401) 874-9195
More information about the R-help
mailing list