我有多个数据集,其中响应变量始终位于数据帧的最后一列。我想运行GLM(逻辑回归)并将其自动化。我按位置调用glm()
,但是此方法始终包含最后一个变量。
data(iris)
head(iris)
train<- iris
logit <- glm(train[,length(train)]~ . ,
data = train, family = "binomial")
summary(logit)
我尝试写train[,length(train)]~ . -train[,length(train)]
,但不起作用。
答案 0 :(得分:1)
非常冗长,但我认为应该可以:
import UIKit
class List: UICollectionViewController {
lazy var refresher: UIRefreshControl = {
...
}()
@IBOutlet var movieCollectionView: UICollectionView!
@IBOutlet weak var flowLayout: UICollectionViewFlowLayout!
var movies: [Movie] = [Movie]()
override func viewDidLoad() {
super.viewDidLoad()
movieCollectionView.refreshControl = refresher
...
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
fetchMovies()
}
// Update Movies List
@objc func fetchMovies() {
ViewController.sharedInstance().fetchMovies { (movies) in
if let movies = movies {
self.movies = movies
DispatchQueue.main.async {
self.movieCollectionView.reloadData()
}
} else {
print("error occured while fetching movies")
}
}
let deadline = DispatchTime.now() + .milliseconds(700)
DispatchQueue.main.asyncAfter(deadline: deadline) {
self.refresher.endRefreshing()
}
}
// CollectionView Functions
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return movies.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cellReuseIdentifier = "collectionCell"
let movie = movies[indexPath.row]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellReuseIdentifier, for: indexPath) as! CustomCollectionViewCell
cell.poster!.contentMode = UIView.ContentMode.scaleAspectFit
if let posterPath = movie.posterPath {
ViewController.sharedInstance().fetchPoster(path: posterPath, size: ViewController.PosterConstants.RowPoster, completion: { (imageData) in
if let image = imageData {
DispatchQueue.main.async {
cell.poster!.image = image
}
} else {
print("error")
}
})
}
return cell
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let controller: Detail = storyboard?.instantiateViewController(withIdentifier: "Detail") as! Detail
controller.movie = movies[indexPath.row]
navigationController?.pushViewController(controller, animated: true)
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
var numberOfSections = 0
if movies.count > 0 {
numberOfSections = 1
collectionView.backgroundView = nil
} else {
...
noDataLabel.text = "Please wait... I'm thinking..."
...
}
return numberOfSections
}
}
或使用logit <- glm(formula(paste0(names(train)[length(train)], '~.')),
data = train,
family = "binomial")
:
tail