Comments (5)
It's not that they require the order to be the same. It's that the data frame will not be defined with the correct number of rows, unless the first variable you define has the right length. Putting sd.growing.season, in your example, first define the correct length. Then R will fill out the single values to all rows.
You could also just make sure each variable is the right length:
dpred = data.frame(mean.growing.season = rep(11,100),
sd.growing.season = seq(0, 6, len = 100),
logArea = rep(mean(n$logArea),100))
from rethinking.
I think data.frame
uses the longest supplied vector to determine the number of rows. Here it does get it right:
> dpred = data.frame(mean.growing.season = 11,
+ sd.growing.season = seq(0, 6, len = 100),
+ logArea = mean(n$logArea))
> nrow(dpred)
[1] 100
Also, explicitly defining the length of each column doesn't fix the issue:
Wrong order, implied length:
> m = lm(loglpc ~ mean.growing.season * sd.growing.season + log10(area), data = n)
> dpred = data.frame(mean.growing.season = 11,
+ sd.growing.season = seq(0, 6, len = 100),
+ logArea = mean(n$logArea))
> l = link(m, dpred)
> summary(apply(l, 2, mean))
Min. 1st Qu. Median Mean 3rd Qu. Max.
-3.615 -3.112 -2.608 -2.608 -2.105 -1.601
Right order, implied length:
> dpred = dpred[, 3:1]
> l = link(m, dpred)
> summary(apply(l, 2, mean))
Min. 1st Qu. Median Mean 3rd Qu. Max.
-2.753 -2.628 -2.502 -2.502 -2.377 -2.251
Wrong order, explicit length:
> m = lm(loglpc ~ mean.growing.season * sd.growing.season + log10(area), data = n)
> dpred = data.frame(mean.growing.season = rep(11, 100),
+ sd.growing.season = seq(0, 6, len = 100),
+ logArea = rep(mean(n$logArea), 100))
> l = link(m, dpred)
> summary(apply(l, 2, mean))
Min. 1st Qu. Median Mean 3rd Qu. Max.
-3.640 -3.126 -2.612 -2.612 -2.098 -1.584
from rethinking.
I misunderstood the original issue. Is this behavior that happens only with lm?
The link method for lm is not something I ever finished writing. I could didn't get it to behave right, and couldn't justify spending time on it.
from rethinking.
Yes, the issue seems to be constrained to link for lm's. Maybe add at least a warning to link when called with an lm?
from rethinking.
I should either fix it or disable it. Might be an easy fix. But bug seems to arise from the way I've hacked into the predict method. So will take a little detective work.
from rethinking.
Related Issues (20)
- Nevermind HOT 2
- Eliminating variable breaks ulam model HOT 2
- Smooth functions of a variable - modeling syntax HOT 2
- Problem with R code 9.14 on Mac OS
- problems loading rethinking HOT 1
- Zero Inflated Negative Binomial Model HOT 1
- difference in n_eff of population mean depending on model specification HOT 3
- Comparison length > 1 in `cv_data_slice`.
- character limit in translating to stan with ulam()? HOT 3
- Problem with defining imputed variable as a vector in generated stan code HOT 2
- link() not handling id variable values not in original data HOT 2
- Gamma parameterisation
- sim() from model with missing value imputation breaks with error "function merge_missing not found" HOT 2
- 'reject' stan command conflicts with UCBadmit data
- Chapter 16 Lynx Hare Model Change with Stan 2.33.0? HOT 10
- How to construct a spline model using ulam() HOT 4
- cannot install rethinking HOT 1
- Error in link(), R code 4.67 HOT 1
- Poisson response imputation compilation error
- Random Effect in Zero-Inflated Model
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rethinking.