Reputation: 11
y <- sample(1:10,5)
sam<-sample(100:130,20)
x <- matrix(sam,5,4)
# 1a
betaestimator <- function(x,y) {
b<- solve(t(x)%*%x)%*%t(x)%*%y
b
}
#1b
covestimator <- function(x,y) {
b<- solve(t(x)%*%x)%*%t(x)%*%y
t<-nrow(x)
k<-ncol(x)
s <- ((t(y-x%*%b))%*%(y-x%*%b))/(t-k)
s2 <- matrix (s:s,k,k)
e <- s2*(solve(t(x)%*%x))
e
}
#1c
ttest <- function (x,y) {
b<- solve(t(x)%*%x)%*%t(x)%*%y
t<-nrow(x)
k<-ncol(x)
s <- ((t(y-x%*%b))%*%(y-x%*%b))/(t-k)
s2 <- matrix (s:s,k,k)
e <- s2*(solve(t(x)%*%x))
estatt<-matrix(0,k,1)
for (i in 1:k ) {
estatt[i,1] = b[i,1]*e[i,i]
}
estatt
}
#ESTATISTICA t TA DANDO MT BAIXO
#2.1
b1<-0.121
b2<-0.190
t<-23
c2<-2
theta<-0.6
x0<-rnorm(1,c2/(1-theta),1/(1-theta^2))
set.seed(1210686)
normais<-c(rnorm(23,0,1))
c<-0:22
c[1]<-x0
for (i in 2:23) {
c[i] = 2 + theta*c[i-1] + normais[i]
}
#2.2
epsilon<-c(rnorm(23,0,1))
#2.3
y<-0:22
for (i in 1:23) {
y[i] = b1 + b2*c[1] + epsilon[i]
}
ytransposto <- t(y)
tudoum<-matrix(1,1,23)
novax <- matrix(rbind(tudoum,c),2,23)
novax
vamos <- (t(novax)%*%novax)
vamos
solve(vamos)
When I try to solve this matrix, it gives me the error:
Error in solve.default(vamos): system is computationally singular: reciprocal condition number = 1.71139e-19
Error in solve.default(vamos): system is computationally singular: reciprocal condition number = 1.71139e-19
I can't change the numbers, because this is part of a class project my teacher gave me. Thanks!
Upvotes: 1
Views: 11016
Reputation: 4366
In solve()
, use a smaller tolerance, like solve(..., tol = 1e-20)
.
This should be fine since you get reciprocal condition number = 1.71139e-19
.
More info in the help file and this related question.
Upvotes: 1