Displaying 11 results from an estimated 11 matches for "mycoef".
2006 May 19
1
UseMethod infelicity
If I do
> example(lm)
...
> mycoef <- function(object, ...) UseMethod("coef", object)
> mycoef(lm.D9)
Error in mycoef(lm.D9) : no applicable method for "coef"
which is pretty surprising, as coef has a default method.
After a bit of digging, this comes from do_usemethod having
defenv = environment...
2009 Jun 29
2
How to use "subset" in lm function
Hi, I'm using R to do a time series analysis. In the model, I use the lags
of some variables. such the lags of the variables have different length, I
just can't use them directly in the lm function. Intuitively, I feel that
"subset" might be useful, but I do not know how to use it. Anyone can give
me an example syntax? Thanks.
Harry
[[alternative HTML version deleted]]
2012 May 05
2
No error message no display output
...ry to run sapply?
pru<-function(){
randz<-matrix(rnorm(200000),100,2000)
H<-matrix(0,100,2000)
for (j in 2:2000){
for (i in 2:100){
H[1,]<-randz[1,]
H[i,j]<-H[i-1,j]+randz[i,j]
}}
hy<-nrow(H)-1
estima<-H[2:nrow(H),]
estima2<-H[1:hy,]
a<-estima
b<-estima2
mycoef <- function(x, y) coefficients( lm(y ~ x-1) )
rest <- sapply(2:2000, function(i){
y <- a[,i]
x <- b[,i]
mycoef(x,y)
}
)
print(summary(rest))
hist(rest,col="blue",breaks=seq(0.6,1.05,0.01),prob=TRUE)
li...
2007 Aug 20
1
Q: combine 2 data frames with missing values
Een ingesloten tekst met niet-gespecificeerde tekenset is
van het bericht gescrubt ...
Naam: niet beschikbaar
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070820/920567a6/attachment.pl
2009 Jul 15
0
strategy to iterate over repeated measures/longitudinal data
...2 = sample(c("a","b"),10,replace=TRUE),
predictor3 = sample(c("a","b"),10,replace=TRUE),
measurement1=rnorm(10),
measurement2=rnorm(10))
#vector of names to iterate over
predictor_names <- colnames(wide_data)[2:4]
#vector to store coefficients
mycoefs <- rep(-1,length(predictor_names))
names(mycoefs) <- predictor_names
for (predictor in predictor_names)
{
long_data <- make.univ( data.frame(wide_data$id,wide_data[,predictor]),
data.frame(
wide_data$measurement1,
wide_data$measurement2
)
)
names(long_da...
2005 Apr 08
1
subset arg lmList
...bjects they need. This trivial example produces
"Error in rownames(fakedf) : Object "fakedf" not found":
library(nlme)
fitbyID <- function() {
fakedf <- data.frame(ID = gl(5, 10, 50),
A = sample(1:100, 50),
B = rnorm(50))
mycoefs <- lmList(B ~ A | ID,
data = fakedf,
subset = !is.element(rownames(fakedf),
c("3", "10")))
coef(mycoefs)
}
fitbyID()
If fakedf is already in the workspace, then the function runs fine, so
r...
2012 May 10
1
Error t value matrix
...lt;-randz[1,]
for (i in 2:50){
if(i < 26) {
H[i, ] <- 0.6 * H[i-1, ] + randz[i, ]
} else {
H[i, ] <- H[i-1, ] + randz[i, ]
}
}
write.table(H, file = "datad.txt")
g<-read.table("datad.txt")
hy<-nrow(g)-1
estima<-H[2:nrow(g), ]
estima2<-H[ 1:hy, ]
mycoef <- function (x,y)
a<-estima
b<-estima2
f<-summary(lm(a~b))
ff<-coef(f)
ff[2,"t value"]
tvalue <- sapply (2:ncol(b) , function (i){
y<-a[,i]
x<-b[,i]
mycoef(x,y)
}
)
print (summary(tvalue))
[[alternative HTML version deleted]]
2002 Oct 09
5
polynomial
Any better (more efficient, built-in) ideas for computing
coef[1]+coef[2]*x+coef[3]*x^2+ ...
than
polynom <- function(coef,x) {
n <- length(coef)
sum(coef*apply(matrix(c(rep(x,n),seq(0,n-1)),ncol=2),1,function(z)z[1]^z[2]))
}
?
Ben
--
318 Carr Hall bolker at zoo.ufl.edu
Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker
2016 Apr 30
0
Unexpected scores from weighted PCA with svyprcomp()
...rvey)
data(api)
dclus2 <- svydesign(ids = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data =
apiclus2)
pc <- svyprcomp( ~ api99 + api00, design = dclus2, scale = TRUE, scores
= TRUE)
dclus2$variables$pc1 <- pc$x[, "PC1"]
dclus2$variables$pc2 <- predict(pc, apiclus2)[, "PC1"]
mycoef <- pc$rotation[, "PC1"] / pc$scale
dclus2$variables$pc3 <- with(apiclus2, api99 * mycoef["api99"] + api00 *
mycoef["api00"])
svycor(~ pc1 + pc2 + pc3, dclus2)[, ]
# pc1 pc2 pc3
# pc1 1.0000000 0.2078789 0.2078789
# pc2 0.2078789 1.0000000 1....
2011 Jul 07
3
coefficients lm of data.frame
Hi,
I've a data frame like this:
> as.data.frame(cbind(rnorm(1:12),rnorm(1:12)))
V1 V2
1 -1.30849402 -0.52094136
2 0.96157302 0.76217871
3 -0.44223351 -1.72630871
4 -0.10432438 -1.04732942
5 -1.38748914 0.95877311
6 -0.63965975 0.65494811
7 -0.24058318 0.19496830
8 -0.11172988 1.01680655
9 0.08065333 0.22168589
10 0.25196536 0.84619914
11
2009 Jun 25
1
lm
Hi all,
I want to make multiple least squares estimation on two matrix (without
intercept)
imagine matrix "a" and matrix "b", I want to "regress" each colum on matrix
"a" (dependent variable) on each column of matrix b, I mean, regress first
colum on a to first column on b. Second column on a to second column on b.
Imagine "a" and "b"